format: prettify entire project

This commit is contained in:
Rim
2025-04-02 06:50:39 -04:00
parent 86f0782a98
commit 7ccc0be712
1711 changed files with 755867 additions and 235931 deletions

View File

@ -1,5 +1,5 @@
declare const stringWidth: {
/**
/**
Get the visual width of a string - the number of columns required to display it.
Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
@ -18,12 +18,12 @@ declare const stringWidth: {
//=> 2
```
*/
(string: string): number;
(string: string): number;
// TODO: remove this in the next major version, refactor the whole definition to:
// declare function stringWidth(string: string): number;
// export = stringWidth;
default: typeof stringWidth;
}
// TODO: remove this in the next major version, refactor the whole definition to:
// declare function stringWidth(string: string): number;
// export = stringWidth;
default: typeof stringWidth;
};
export = stringWidth;

View File

@ -3,43 +3,43 @@ const stripAnsi = require('strip-ansi');
const isFullwidthCodePoint = require('is-fullwidth-code-point');
const emojiRegex = require('emoji-regex');
const stringWidth = string => {
if (typeof string !== 'string' || string.length === 0) {
return 0;
}
const stringWidth = (string) => {
if (typeof string !== 'string' || string.length === 0) {
return 0;
}
string = stripAnsi(string);
string = stripAnsi(string);
if (string.length === 0) {
return 0;
}
if (string.length === 0) {
return 0;
}
string = string.replace(emojiRegex(), ' ');
string = string.replace(emojiRegex(), ' ');
let width = 0;
let width = 0;
for (let i = 0; i < string.length; i++) {
const code = string.codePointAt(i);
for (let i = 0; i < string.length; i++) {
const code = string.codePointAt(i);
// Ignore control characters
if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
continue;
}
// Ignore control characters
if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) {
continue;
}
// Ignore combining characters
if (code >= 0x300 && code <= 0x36F) {
continue;
}
// Ignore combining characters
if (code >= 0x300 && code <= 0x36f) {
continue;
}
// Surrogates
if (code > 0xFFFF) {
i++;
}
// Surrogates
if (code > 0xffff) {
i++;
}
width += isFullwidthCodePoint(code) ? 2 : 1;
}
width += isFullwidthCodePoint(code) ? 2 : 1;
}
return width;
return width;
};
module.exports = stringWidth;

View File

@ -1,56 +1,56 @@
{
"name": "string-width",
"version": "4.2.3",
"description": "Get the visual width of a string - the number of columns required to display it",
"license": "MIT",
"repository": "sindresorhus/string-width",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"string",
"character",
"unicode",
"width",
"visual",
"column",
"columns",
"fullwidth",
"full-width",
"full",
"ansi",
"escape",
"codes",
"cli",
"command-line",
"terminal",
"console",
"cjk",
"chinese",
"japanese",
"korean",
"fixed-width"
],
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.1",
"xo": "^0.24.0"
}
"name": "string-width",
"version": "4.2.3",
"description": "Get the visual width of a string - the number of columns required to display it",
"license": "MIT",
"repository": "sindresorhus/string-width",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"string",
"character",
"unicode",
"width",
"visual",
"column",
"columns",
"fullwidth",
"full-width",
"full",
"ansi",
"escape",
"codes",
"cli",
"command-line",
"terminal",
"console",
"cjk",
"chinese",
"japanese",
"korean",
"fixed-width"
],
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.1",
"xo": "^0.24.0"
}
}