aboutsummaryrefslogtreecommitdiff
path: root/node_modules/string-width/index.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-12-27 19:33:54 +0100
committerFlorian Dold <florian.dold@gmail.com>2017-12-27 19:34:16 +0100
commit0e6de2c31dbf8c21277481f112e99c52b913940f (patch)
tree91789032de3b8eec9d789acd1323f25fc5d08422 /node_modules/string-width/index.js
parentceda0da31ad542c598c68146ae0712ca03df3d71 (diff)
node_modules
Diffstat (limited to 'node_modules/string-width/index.js')
-rw-r--r--node_modules/string-width/index.js35
1 files changed, 17 insertions, 18 deletions
diff --git a/node_modules/string-width/index.js b/node_modules/string-width/index.js
index b9bec6244..bbc49d29b 100644
--- a/node_modules/string-width/index.js
+++ b/node_modules/string-width/index.js
@@ -1,36 +1,35 @@
'use strict';
-var stripAnsi = require('strip-ansi');
-var codePointAt = require('code-point-at');
-var isFullwidthCodePoint = require('is-fullwidth-code-point');
+const stripAnsi = require('strip-ansi');
+const isFullwidthCodePoint = require('is-fullwidth-code-point');
-// https://github.com/nodejs/io.js/blob/cff7300a578be1b10001f2d967aaedc88aee6402/lib/readline.js#L1345
-module.exports = function (str) {
+module.exports = str => {
if (typeof str !== 'string' || str.length === 0) {
return 0;
}
- var width = 0;
-
str = stripAnsi(str);
- for (var i = 0; i < str.length; i++) {
- var code = codePointAt(str, i);
+ let width = 0;
+
+ for (let i = 0; i < str.length; i++) {
+ const code = str.codePointAt(i);
- // ignore control characters
- if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) {
+ // Ignore control characters
+ if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
continue;
}
- // surrogates
- if (code >= 0x10000) {
- i++;
+ // Ignore combining characters
+ if (code >= 0x300 && code <= 0x36F) {
+ continue;
}
- if (isFullwidthCodePoint(code)) {
- width += 2;
- } else {
- width++;
+ // Surrogates
+ if (code > 0xFFFF) {
+ i++;
}
+
+ width += isFullwidthCodePoint(code) ? 2 : 1;
}
return width;