Install yarn
This commit is contained in:
parent
0453e84836
commit
1fde8a81be
1927 changed files with 82144 additions and 83317 deletions
48
node_modules/string-width/index.js
generated
vendored
48
node_modules/string-width/index.js
generated
vendored
|
@ -1,47 +1,37 @@
|
|||
'use strict';
|
||||
const stripAnsi = require('strip-ansi');
|
||||
const isFullwidthCodePoint = require('is-fullwidth-code-point');
|
||||
const emojiRegex = require('emoji-regex');
|
||||
var stripAnsi = require('strip-ansi');
|
||||
var codePointAt = require('code-point-at');
|
||||
var isFullwidthCodePoint = require('is-fullwidth-code-point');
|
||||
|
||||
const stringWidth = string => {
|
||||
if (typeof string !== 'string' || string.length === 0) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
string = stripAnsi(string);
|
||||
var width = 0;
|
||||
|
||||
if (string.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
str = stripAnsi(str);
|
||||
|
||||
string = string.replace(emojiRegex(), ' ');
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
var code = codePointAt(str, i);
|
||||
|
||||
let width = 0;
|
||||
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
const code = string.codePointAt(i);
|
||||
|
||||
// Ignore control characters
|
||||
if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
|
||||
// ignore control characters
|
||||
if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore combining characters
|
||||
if (code >= 0x300 && code <= 0x36F) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Surrogates
|
||||
if (code > 0xFFFF) {
|
||||
// surrogates
|
||||
if (code >= 0x10000) {
|
||||
i++;
|
||||
}
|
||||
|
||||
width += isFullwidthCodePoint(code) ? 2 : 1;
|
||||
if (isFullwidthCodePoint(code)) {
|
||||
width += 2;
|
||||
} else {
|
||||
width++;
|
||||
}
|
||||
}
|
||||
|
||||
return width;
|
||||
};
|
||||
|
||||
module.exports = stringWidth;
|
||||
// TODO: remove this in the next major version
|
||||
module.exports.default = stringWidth;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue