Skip to content
Permalink
Browse files

readline: use module.exports = {} on internal/readline

PR-URL: #12755
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information...
jasnell authored and addaleax committed Apr 29, 2017
1 parent 9318f82 commit 392a8987c62f0c54de9036659853467b48f113cd
Showing with 15 additions and 11 deletions.
  1. +15 −11 lib/internal/readline.js
@@ -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;
@@ -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;

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

if (module.exports.isFullWidthCodePoint(code)) {
if (isFullWidthCodePoint(code)) {
width += 2;
} else {
width++;
@@ -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;
}
@@ -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.
You can’t perform that action at this time.