From 5ec24d80367be128c8f016100b857d0bf9409a38 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 29 Apr 2017 13:43:43 -0700 Subject: [PATCH] readline: use module.exports = {} on internal/readline PR-URL: https://github.com/nodejs/node/pull/12755 Reviewed-By: Anna Henningsen --- lib/internal/readline.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/internal/readline.js b/lib/internal/readline.js index 9f1884ad0ea9e1..4474b0234575d5 100644 --- a/lib/internal/readline.js +++ b/lib/internal/readline.js @@ -7,15 +7,12 @@ 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)); @@ -23,7 +20,7 @@ if (process.binding('config').hasIntl) { 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 +};