Skip to content

Commit

Permalink
readline: use module.exports = {} on internal/readline
Browse files Browse the repository at this point in the history
PR-URL: #12755
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
jasnell authored and addaleax committed May 7, 2017
1 parent 9318f82 commit 392a898
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/internal/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@
const ansi =
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;


module.exports = {
emitKeys,
stripVTControlCharacters
};
var getStringWidth;
var isFullWidthCodePoint;

if (process.binding('config').hasIntl) {
const icu = process.binding('icu');
module.exports.getStringWidth = function getStringWidth(str, options) {
getStringWidth = function getStringWidth(str, options) {
options = options || {};
if (!Number.isInteger(str))
str = stripVTControlCharacters(String(str));
return icu.getStringWidth(str,
Boolean(options.ambiguousAsFullWidth),
Boolean(options.expandEmojiSequence));
};
module.exports.isFullWidthCodePoint =
isFullWidthCodePoint =
function isFullWidthCodePoint(code, options) {
if (typeof code !== 'number')
return false;
Expand All @@ -33,9 +30,9 @@ if (process.binding('config').hasIntl) {
/**
* Returns the number of columns required to display the given string.
*/
module.exports.getStringWidth = function getStringWidth(str) {
getStringWidth = function getStringWidth(str) {
if (Number.isInteger(str))
return module.exports.isFullWidthCodePoint(str) ? 2 : 1;
return isFullWidthCodePoint(str) ? 2 : 1;

let width = 0;

Expand All @@ -48,7 +45,7 @@ if (process.binding('config').hasIntl) {
i++;
}

if (module.exports.isFullWidthCodePoint(code)) {
if (isFullWidthCodePoint(code)) {
width += 2;
} else {
width++;
Expand All @@ -62,7 +59,7 @@ if (process.binding('config').hasIntl) {
* Returns true if the character represented by a given
* Unicode code point is full-width. Otherwise returns false.
*/
module.exports.isFullWidthCodePoint = function isFullWidthCodePoint(code) {
isFullWidthCodePoint = function isFullWidthCodePoint(code) {
if (!Number.isInteger(code)) {
return false;
}
Expand Down Expand Up @@ -407,3 +404,10 @@ function* emitKeys(stream) {
/* Unrecognized or broken escape sequence, don't emit anything */
}
}

module.exports = {
emitKeys,
getStringWidth,
isFullWidthCodePoint,
stripVTControlCharacters
};

0 comments on commit 392a898

Please sign in to comment.