diff options
author | isaacs <i@izs.me> | 2020-07-24 22:55:18 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-07-29 21:55:03 +0300 |
commit | 53ed7e5205a3f4d5d33828ff9dc11c093f482f7b (patch) | |
tree | d76317be79432c9527e8fb37d4c13e0719cdbaf9 /node_modules/string-width/index.js | |
parent | bbe4279120c94791b70d97f235c73d972fd67354 (diff) |
reset deps using npm v7
First self-install!
Diffstat (limited to 'node_modules/string-width/index.js')
-rw-r--r-- | node_modules/string-width/index.js | 35 |
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; |