Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/string-width/index.js')
-rw-r--r--node_modules/string-width/index.js35
1 files changed, 18 insertions, 17 deletions
diff --git a/node_modules/string-width/index.js b/node_modules/string-width/index.js
index bbc49d29b..b9bec6244 100644
--- a/node_modules/string-width/index.js
+++ b/node_modules/string-width/index.js
@@ -1,35 +1,36 @@
'use strict';
-const stripAnsi = require('strip-ansi');
-const isFullwidthCodePoint = require('is-fullwidth-code-point');
+var stripAnsi = require('strip-ansi');
+var codePointAt = require('code-point-at');
+var isFullwidthCodePoint = require('is-fullwidth-code-point');
-module.exports = str => {
+// https://github.com/nodejs/io.js/blob/cff7300a578be1b10001f2d967aaedc88aee6402/lib/readline.js#L1345
+module.exports = function (str) {
if (typeof str !== 'string' || str.length === 0) {
return 0;
}
- str = stripAnsi(str);
-
- let width = 0;
+ var width = 0;
- for (let i = 0; i < str.length; i++) {
- const code = str.codePointAt(i);
+ str = stripAnsi(str);
- // Ignore control characters
- if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
- continue;
- }
+ for (var i = 0; i < str.length; i++) {
+ var code = codePointAt(str, i);
- // Ignore combining characters
- if (code >= 0x300 && code <= 0x36F) {
+ // ignore control characters
+ if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) {
continue;
}
- // Surrogates
- if (code > 0xFFFF) {
+ // surrogates
+ if (code >= 0x10000) {
i++;
}
- width += isFullwidthCodePoint(code) ? 2 : 1;
+ if (isFullwidthCodePoint(code)) {
+ width += 2;
+ } else {
+ width++;
+ }
}
return width;