@trayai/tray-sync-cli 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/auth.js +1 -21
- package/dist/views/auth/auth.js +22 -0
- package/dist/views/auth/auth.v2.js +30 -0
- package/package.json +3 -4
- package/node_modules/ansi-regex/index.d.ts +0 -33
- package/node_modules/ansi-regex/index.js +0 -14
- package/node_modules/ansi-regex/license +0 -9
- package/node_modules/ansi-regex/package.json +0 -61
- package/node_modules/ansi-regex/readme.md +0 -66
- package/node_modules/get-east-asian-width/index.d.ts +0 -60
- package/node_modules/get-east-asian-width/index.js +0 -30
- package/node_modules/get-east-asian-width/license +0 -9
- package/node_modules/get-east-asian-width/lookup-data.js +0 -21
- package/node_modules/get-east-asian-width/lookup.js +0 -138
- package/node_modules/get-east-asian-width/package.json +0 -71
- package/node_modules/get-east-asian-width/readme.md +0 -65
- package/node_modules/get-east-asian-width/utilities.js +0 -24
- package/node_modules/string-width/index.d.ts +0 -39
- package/node_modules/string-width/index.js +0 -207
- package/node_modules/string-width/license +0 -9
- package/node_modules/string-width/package.json +0 -65
- package/node_modules/string-width/readme.md +0 -66
- package/node_modules/strip-ansi/index.d.ts +0 -15
- package/node_modules/strip-ansi/index.js +0 -19
- package/node_modules/strip-ansi/license +0 -9
- package/node_modules/strip-ansi/package.json +0 -59
- package/node_modules/strip-ansi/readme.md +0 -37
package/dist/commands/auth.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { Command, InvalidArgumentError } from "commander";
|
|
2
2
|
import { readCredentials, writeCredentials } from "../config/credentials.js";
|
|
3
|
-
import { describeRegion } from "../lib/regionDisplay.js";
|
|
4
3
|
import { parseRegion } from "../lib/regionParsing.js";
|
|
5
4
|
import { isUuid } from "../lib/uuid.js";
|
|
6
|
-
|
|
7
|
-
const verb = result.overwrote ? "Updated" : "Set";
|
|
8
|
-
stdout(`${verb} token for workspace ${result.workspaceId} (${describeRegion(result.region)}).`);
|
|
9
|
-
}
|
|
5
|
+
import { printAuthListResult, printAuthRemoveResult, printAuthSetResult } from "../views/auth/auth.v2.js";
|
|
10
6
|
export async function runAuthSet(deps, options) {
|
|
11
7
|
const { env, stdout } = deps;
|
|
12
8
|
const credentials = await readCredentials(env);
|
|
@@ -19,13 +15,6 @@ export async function runAuthSet(deps, options) {
|
|
|
19
15
|
printAuthSetResult(stdout, { workspaceId: options.workspaceId, region: options.region, overwrote });
|
|
20
16
|
return 0;
|
|
21
17
|
}
|
|
22
|
-
export function printAuthRemoveResult(stdout, result) {
|
|
23
|
-
if (!result.removed) {
|
|
24
|
-
stdout(`No stored credentials for workspace ${result.workspaceId}. Nothing to remove.`);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
stdout(`Removed stored credentials for workspace ${result.workspaceId}.`);
|
|
28
|
-
}
|
|
29
18
|
export async function runAuthRemove(deps, options) {
|
|
30
19
|
const { env, stdout } = deps;
|
|
31
20
|
const credentials = await readCredentials(env);
|
|
@@ -37,15 +26,6 @@ export async function runAuthRemove(deps, options) {
|
|
|
37
26
|
printAuthRemoveResult(stdout, { workspaceId: options.workspaceId, removed });
|
|
38
27
|
return 0;
|
|
39
28
|
}
|
|
40
|
-
export function printAuthListResult(stdout, result) {
|
|
41
|
-
if (result.entries.length === 0) {
|
|
42
|
-
stdout("No stored credentials.");
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
for (const entry of result.entries) {
|
|
46
|
-
stdout(` ${entry.workspaceId} (${describeRegion(entry.region)})`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
29
|
export async function runAuthList(deps, _options) {
|
|
50
30
|
const { env, stdout } = deps;
|
|
51
31
|
const credentials = await readCredentials(env);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describeRegion } from "../../lib/regionDisplay.js";
|
|
2
|
+
export function printAuthSetResult(stdout, result) {
|
|
3
|
+
const verb = result.overwrote ? "Updated" : "Set";
|
|
4
|
+
stdout(`${verb} token for workspace ${result.workspaceId} (${describeRegion(result.region)}).`);
|
|
5
|
+
}
|
|
6
|
+
export function printAuthRemoveResult(stdout, result) {
|
|
7
|
+
if (!result.removed) {
|
|
8
|
+
stdout(`No stored credentials for workspace ${result.workspaceId}. Nothing to remove.`);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
stdout(`Removed stored credentials for workspace ${result.workspaceId}.`);
|
|
12
|
+
}
|
|
13
|
+
export function printAuthListResult(stdout, result) {
|
|
14
|
+
if (result.entries.length === 0) {
|
|
15
|
+
stdout("No stored credentials.");
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
for (const entry of result.entries) {
|
|
19
|
+
stdout(` ${entry.workspaceId} (${describeRegion(entry.region)})`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import ansis from "ansis";
|
|
2
|
+
import Table from "cli-table3";
|
|
3
|
+
import { describeRegion } from "../../lib/regionDisplay.js";
|
|
4
|
+
import { INFO_ICON } from "../icons.js";
|
|
5
|
+
export function printAuthSetResult(stdout, result) {
|
|
6
|
+
const verb = result.overwrote ? "Updated" : "Set";
|
|
7
|
+
stdout(`${ansis.bold(verb)} token for workspace ${ansis.bold(result.workspaceId)} (${describeRegion(result.region)}).`);
|
|
8
|
+
}
|
|
9
|
+
export function printAuthRemoveResult(stdout, result) {
|
|
10
|
+
if (!result.removed) {
|
|
11
|
+
stdout(`${INFO_ICON} No stored credentials for workspace ${ansis.bold(result.workspaceId)}. Nothing to remove.`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
stdout(`${ansis.bold("Removed")} stored credentials for workspace ${ansis.bold(result.workspaceId)}.`);
|
|
15
|
+
}
|
|
16
|
+
export function printAuthListResult(stdout, result) {
|
|
17
|
+
if (result.entries.length === 0) {
|
|
18
|
+
stdout(`${INFO_ICON} No stored credentials.`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const table = new Table({
|
|
22
|
+
head: ["ID", "Region"].map((h) => ansis.bold(h)),
|
|
23
|
+
style: { head: [] },
|
|
24
|
+
});
|
|
25
|
+
for (const entry of result.entries) {
|
|
26
|
+
table.push([ansis.bold(entry.workspaceId), describeRegion(entry.region)]);
|
|
27
|
+
}
|
|
28
|
+
stdout(table.toString());
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=auth.v2.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayai/tray-sync-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "CLI tool to clone Tray projects and related assets to a local directory, and promote them between Tray environments",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tray": "dist/cli.js"
|
|
@@ -30,21 +30,20 @@
|
|
|
30
30
|
"gallery:pull": "tsc -p tsconfig.test.json && node dist-test/test/manual/pullOutputGallery.js",
|
|
31
31
|
"gallery:project": "tsc -p tsconfig.test.json && node dist-test/test/manual/projectOutputGallery.js",
|
|
32
32
|
"gallery:init": "tsc -p tsconfig.test.json && node dist-test/test/manual/initOutputGallery.js",
|
|
33
|
-
"gallery:promote": "tsc -p tsconfig.test.json && node dist-test/test/manual/promoteOutputGallery.js"
|
|
33
|
+
"gallery:promote": "tsc -p tsconfig.test.json && node dist-test/test/manual/promoteOutputGallery.js",
|
|
34
|
+
"gallery:auth": "tsc -p tsconfig.test.json && node dist-test/test/manual/authOutputGallery.js"
|
|
34
35
|
},
|
|
35
36
|
"license": "Apache-2.0",
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"ansis": "^4.3.1",
|
|
38
39
|
"cli-table3": "^0.6.5",
|
|
39
40
|
"commander": "~15.0.0",
|
|
40
|
-
"string-width": "^8.2.2",
|
|
41
41
|
"yaml": "~2.9.0"
|
|
42
42
|
},
|
|
43
43
|
"bundleDependencies": [
|
|
44
44
|
"ansis",
|
|
45
45
|
"cli-table3",
|
|
46
46
|
"commander",
|
|
47
|
-
"string-width",
|
|
48
47
|
"yaml"
|
|
49
48
|
],
|
|
50
49
|
"devDependencies": {
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export type Options = {
|
|
2
|
-
/**
|
|
3
|
-
Match only the first ANSI escape.
|
|
4
|
-
|
|
5
|
-
@default false
|
|
6
|
-
*/
|
|
7
|
-
readonly onlyFirst: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
Regular expression for matching ANSI escape codes.
|
|
12
|
-
|
|
13
|
-
@example
|
|
14
|
-
```
|
|
15
|
-
import ansiRegex from 'ansi-regex';
|
|
16
|
-
|
|
17
|
-
ansiRegex().test('\u001B[4mcake\u001B[0m');
|
|
18
|
-
//=> true
|
|
19
|
-
|
|
20
|
-
ansiRegex().test('cake');
|
|
21
|
-
//=> false
|
|
22
|
-
|
|
23
|
-
'\u001B[4mcake\u001B[0m'.match(ansiRegex());
|
|
24
|
-
//=> ['\u001B[4m', '\u001B[0m']
|
|
25
|
-
|
|
26
|
-
'\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
|
|
27
|
-
//=> ['\u001B[4m']
|
|
28
|
-
|
|
29
|
-
'\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
|
|
30
|
-
//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
|
|
31
|
-
```
|
|
32
|
-
*/
|
|
33
|
-
export default function ansiRegex(options?: Options): RegExp;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default function ansiRegex({onlyFirst = false} = {}) {
|
|
2
|
-
// Valid string terminator sequences are BEL, ESC\, and 0x9c
|
|
3
|
-
const ST = '(?:\\u0007|\\u001B\\u005C|\\u009C)';
|
|
4
|
-
|
|
5
|
-
// OSC sequences only: ESC ] ... ST (non-greedy until the first ST)
|
|
6
|
-
const osc = `(?:\\u001B\\][\\s\\S]*?${ST})`;
|
|
7
|
-
|
|
8
|
-
// CSI and related: ESC/C1, optional intermediates, optional params (supports ; and :) then final byte
|
|
9
|
-
const csi = '[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]';
|
|
10
|
-
|
|
11
|
-
const pattern = `${osc}|${csi}`;
|
|
12
|
-
|
|
13
|
-
return new RegExp(pattern, onlyFirst ? undefined : 'g');
|
|
14
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ansi-regex",
|
|
3
|
-
"version": "6.2.2",
|
|
4
|
-
"description": "Regular expression for matching ANSI escape codes",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"repository": "chalk/ansi-regex",
|
|
7
|
-
"funding": "https://github.com/chalk/ansi-regex?sponsor=1",
|
|
8
|
-
"author": {
|
|
9
|
-
"name": "Sindre Sorhus",
|
|
10
|
-
"email": "sindresorhus@gmail.com",
|
|
11
|
-
"url": "https://sindresorhus.com"
|
|
12
|
-
},
|
|
13
|
-
"type": "module",
|
|
14
|
-
"exports": "./index.js",
|
|
15
|
-
"types": "./index.d.ts",
|
|
16
|
-
"sideEffects": false,
|
|
17
|
-
"engines": {
|
|
18
|
-
"node": ">=12"
|
|
19
|
-
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"test": "xo && ava && tsd",
|
|
22
|
-
"view-supported": "node fixtures/view-codes.js"
|
|
23
|
-
},
|
|
24
|
-
"files": [
|
|
25
|
-
"index.js",
|
|
26
|
-
"index.d.ts"
|
|
27
|
-
],
|
|
28
|
-
"keywords": [
|
|
29
|
-
"ansi",
|
|
30
|
-
"styles",
|
|
31
|
-
"color",
|
|
32
|
-
"colour",
|
|
33
|
-
"colors",
|
|
34
|
-
"terminal",
|
|
35
|
-
"console",
|
|
36
|
-
"cli",
|
|
37
|
-
"string",
|
|
38
|
-
"tty",
|
|
39
|
-
"escape",
|
|
40
|
-
"formatting",
|
|
41
|
-
"rgb",
|
|
42
|
-
"256",
|
|
43
|
-
"shell",
|
|
44
|
-
"xterm",
|
|
45
|
-
"command-line",
|
|
46
|
-
"text",
|
|
47
|
-
"regex",
|
|
48
|
-
"regexp",
|
|
49
|
-
"re",
|
|
50
|
-
"match",
|
|
51
|
-
"test",
|
|
52
|
-
"find",
|
|
53
|
-
"pattern"
|
|
54
|
-
],
|
|
55
|
-
"devDependencies": {
|
|
56
|
-
"ansi-escapes": "^5.0.0",
|
|
57
|
-
"ava": "^3.15.0",
|
|
58
|
-
"tsd": "^0.21.0",
|
|
59
|
-
"xo": "^0.54.2"
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# ansi-regex
|
|
2
|
-
|
|
3
|
-
> Regular expression for matching [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm install ansi-regex
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```js
|
|
14
|
-
import ansiRegex from 'ansi-regex';
|
|
15
|
-
|
|
16
|
-
ansiRegex().test('\u001B[4mcake\u001B[0m');
|
|
17
|
-
//=> true
|
|
18
|
-
|
|
19
|
-
ansiRegex().test('cake');
|
|
20
|
-
//=> false
|
|
21
|
-
|
|
22
|
-
'\u001B[4mcake\u001B[0m'.match(ansiRegex());
|
|
23
|
-
//=> ['\u001B[4m', '\u001B[0m']
|
|
24
|
-
|
|
25
|
-
'\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
|
|
26
|
-
//=> ['\u001B[4m']
|
|
27
|
-
|
|
28
|
-
'\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
|
|
29
|
-
//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## API
|
|
33
|
-
|
|
34
|
-
### ansiRegex(options?)
|
|
35
|
-
|
|
36
|
-
Returns a regex for matching ANSI escape codes.
|
|
37
|
-
|
|
38
|
-
#### options
|
|
39
|
-
|
|
40
|
-
Type: `object`
|
|
41
|
-
|
|
42
|
-
##### onlyFirst
|
|
43
|
-
|
|
44
|
-
Type: `boolean`\
|
|
45
|
-
Default: `false` *(Matches any ANSI escape codes in a string)*
|
|
46
|
-
|
|
47
|
-
Match only the first ANSI escape.
|
|
48
|
-
|
|
49
|
-
## Important
|
|
50
|
-
|
|
51
|
-
If you run the regex against untrusted user input in a server context, you should [give it a timeout](https://github.com/sindresorhus/super-regex).
|
|
52
|
-
|
|
53
|
-
**I do not consider [ReDoS](https://blog.yossarian.net/2022/12/28/ReDoS-vulnerabilities-and-misaligned-incentives) a valid vulnerability for this package.**
|
|
54
|
-
|
|
55
|
-
## FAQ
|
|
56
|
-
|
|
57
|
-
### Why do you test for codes not in the ECMA 48 standard?
|
|
58
|
-
|
|
59
|
-
Some of the codes we run as a test are codes that we acquired finding various lists of non-standard or manufacturer specific codes. We test for both standard and non-standard codes, as most of them follow the same or similar format and can be safely matched in strings without the risk of removing actual string content. There are a few non-standard control codes that do not follow the traditional format (i.e. they end in numbers) thus forcing us to exclude them from the test because we cannot reliably match them.
|
|
60
|
-
|
|
61
|
-
On the historical side, those ECMA standards were established in the early 90's whereas the VT100, for example, was designed in the mid/late 70's. At that point in time, control codes were still pretty ungoverned and engineers used them for a multitude of things, namely to activate hardware ports that may have been proprietary. Somewhere else you see a similar 'anarchy' of codes is in the x86 architecture for processors; there are a ton of "interrupts" that can mean different things on certain brands of processors, most of which have been phased out.
|
|
62
|
-
|
|
63
|
-
## Maintainers
|
|
64
|
-
|
|
65
|
-
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
66
|
-
- [Josh Junon](https://github.com/qix-)
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export type WidthType = 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous';
|
|
2
|
-
|
|
3
|
-
export type Options = {
|
|
4
|
-
/**
|
|
5
|
-
Whether to treat an `'ambiguous'` character as wide.
|
|
6
|
-
|
|
7
|
-
@default true
|
|
8
|
-
|
|
9
|
-
@example
|
|
10
|
-
```
|
|
11
|
-
import {eastAsianWidth} from 'get-east-asian-width';
|
|
12
|
-
|
|
13
|
-
const codePoint = '⛣'.codePointAt(0);
|
|
14
|
-
|
|
15
|
-
console.log(eastAsianWidth(codePoint));
|
|
16
|
-
//=> 1
|
|
17
|
-
|
|
18
|
-
console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
|
|
19
|
-
//=> 2
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
> Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). __If the context cannot be established reliably, they should be treated as narrow characters by default.__
|
|
23
|
-
> - http://www.unicode.org/reports/tr11/
|
|
24
|
-
*/
|
|
25
|
-
readonly ambiguousAsWide?: boolean;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
Returns the width as a number for the given code point.
|
|
30
|
-
|
|
31
|
-
@param codePoint - A Unicode code point.
|
|
32
|
-
|
|
33
|
-
@example
|
|
34
|
-
```
|
|
35
|
-
import {eastAsianWidth} from 'get-east-asian-width';
|
|
36
|
-
|
|
37
|
-
const codePoint = '字'.codePointAt(0);
|
|
38
|
-
|
|
39
|
-
console.log(eastAsianWidth(codePoint));
|
|
40
|
-
//=> 2
|
|
41
|
-
```
|
|
42
|
-
*/
|
|
43
|
-
export function eastAsianWidth(codePoint: number, options?: Options): 1 | 2;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
Returns the type of “East Asian Width” for the given code point.
|
|
47
|
-
|
|
48
|
-
@param codePoint - A Unicode code point.
|
|
49
|
-
|
|
50
|
-
@example
|
|
51
|
-
```
|
|
52
|
-
import {eastAsianWidthType} from 'get-east-asian-width';
|
|
53
|
-
|
|
54
|
-
const codePoint = '字'.codePointAt(0);
|
|
55
|
-
|
|
56
|
-
console.log(eastAsianWidthType(codePoint));
|
|
57
|
-
//=> 'wide'
|
|
58
|
-
```
|
|
59
|
-
*/
|
|
60
|
-
export function eastAsianWidthType(codePoint: number): WidthType;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {getCategory, isAmbiguous, isFullWidth, isWide} from './lookup.js';
|
|
2
|
-
|
|
3
|
-
function validate(codePoint) {
|
|
4
|
-
if (!Number.isSafeInteger(codePoint)) {
|
|
5
|
-
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function eastAsianWidthType(codePoint) {
|
|
10
|
-
validate(codePoint);
|
|
11
|
-
|
|
12
|
-
return getCategory(codePoint);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function eastAsianWidth(codePoint, {ambiguousAsWide = false} = {}) {
|
|
16
|
-
validate(codePoint);
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
isFullWidth(codePoint)
|
|
20
|
-
|| isWide(codePoint)
|
|
21
|
-
|| (ambiguousAsWide && isAmbiguous(codePoint))
|
|
22
|
-
) {
|
|
23
|
-
return 2;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return 1;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Private exports for https://github.com/sindresorhus/is-fullwidth-code-point
|
|
30
|
-
export {isFullWidth as _isFullWidth, isWide as _isWide} from './lookup.js';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Generated by scripts/build.js
|
|
2
|
-
|
|
3
|
-
export const ambiguousMinimalCodePoint = 161;
|
|
4
|
-
export const ambiguousMaximumCodePoint = 1114109;
|
|
5
|
-
export const ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
|
|
6
|
-
|
|
7
|
-
export const fullwidthMinimalCodePoint = 12288;
|
|
8
|
-
export const fullwidthMaximumCodePoint = 65510;
|
|
9
|
-
export const fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
|
|
10
|
-
|
|
11
|
-
export const halfwidthMinimalCodePoint = 8361;
|
|
12
|
-
export const halfwidthMaximumCodePoint = 65518;
|
|
13
|
-
export const halfwidthRanges = [8361, 8361, 65377, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, 65512, 65518];
|
|
14
|
-
|
|
15
|
-
export const narrowMinimalCodePoint = 32;
|
|
16
|
-
export const narrowMaximumCodePoint = 10630;
|
|
17
|
-
export const narrowRanges = [32, 126, 162, 163, 165, 166, 172, 172, 175, 175, 10214, 10221, 10629, 10630];
|
|
18
|
-
|
|
19
|
-
export const wideMinimalCodePoint = 4352;
|
|
20
|
-
export const wideMaximumCodePoint = 262141;
|
|
21
|
-
export const wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101589, 101631, 101662, 101760, 101874, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110882, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110951, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128728, 128732, 128735, 128747, 128748, 128756, 128764, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129674, 129678, 129734, 129736, 129736, 129741, 129756, 129759, 129770, 129775, 129784, 131072, 196605, 196608, 262141];
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ambiguousMinimalCodePoint,
|
|
3
|
-
ambiguousMaximumCodePoint,
|
|
4
|
-
ambiguousRanges,
|
|
5
|
-
|
|
6
|
-
fullwidthMinimalCodePoint,
|
|
7
|
-
fullwidthMaximumCodePoint,
|
|
8
|
-
fullwidthRanges,
|
|
9
|
-
|
|
10
|
-
halfwidthMinimalCodePoint,
|
|
11
|
-
halfwidthMaximumCodePoint,
|
|
12
|
-
halfwidthRanges,
|
|
13
|
-
|
|
14
|
-
narrowMinimalCodePoint,
|
|
15
|
-
narrowMaximumCodePoint,
|
|
16
|
-
narrowRanges,
|
|
17
|
-
|
|
18
|
-
wideMinimalCodePoint,
|
|
19
|
-
wideMaximumCodePoint,
|
|
20
|
-
wideRanges,
|
|
21
|
-
} from './lookup-data.js';
|
|
22
|
-
import {isInRange} from './utilities.js';
|
|
23
|
-
|
|
24
|
-
const commonCjkCodePoint = 0x4E_00;
|
|
25
|
-
const [wideFastPathStart, wideFastPathEnd] = /* #__PURE__ */ findWideFastPathRange(wideRanges);
|
|
26
|
-
|
|
27
|
-
// Use a hot-path range so common `isWide` calls can skip binary search.
|
|
28
|
-
// The range containing U+4E00 covers common CJK ideographs;
|
|
29
|
-
// fallback to the largest range for resilience to Unicode table changes.
|
|
30
|
-
function findWideFastPathRange(ranges) {
|
|
31
|
-
let fastPathStart = ranges[0];
|
|
32
|
-
let fastPathEnd = ranges[1];
|
|
33
|
-
|
|
34
|
-
for (let index = 0; index < ranges.length; index += 2) {
|
|
35
|
-
const start = ranges[index];
|
|
36
|
-
const end = ranges[index + 1];
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
commonCjkCodePoint >= start
|
|
40
|
-
&& commonCjkCodePoint <= end
|
|
41
|
-
) {
|
|
42
|
-
return [start, end];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if ((end - start) > (fastPathEnd - fastPathStart)) {
|
|
46
|
-
fastPathStart = start;
|
|
47
|
-
fastPathEnd = end;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return [fastPathStart, fastPathEnd];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const isAmbiguous = codePoint => {
|
|
55
|
-
if (
|
|
56
|
-
codePoint < ambiguousMinimalCodePoint
|
|
57
|
-
|| codePoint > ambiguousMaximumCodePoint
|
|
58
|
-
) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return isInRange(ambiguousRanges, codePoint);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const isFullWidth = codePoint => {
|
|
66
|
-
if (
|
|
67
|
-
codePoint < fullwidthMinimalCodePoint
|
|
68
|
-
|| codePoint > fullwidthMaximumCodePoint
|
|
69
|
-
) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return isInRange(fullwidthRanges, codePoint);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const isHalfWidth = codePoint => {
|
|
77
|
-
if (
|
|
78
|
-
codePoint < halfwidthMinimalCodePoint
|
|
79
|
-
|| codePoint > halfwidthMaximumCodePoint
|
|
80
|
-
) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return isInRange(halfwidthRanges, codePoint);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const isNarrow = codePoint => {
|
|
88
|
-
if (
|
|
89
|
-
codePoint < narrowMinimalCodePoint
|
|
90
|
-
|| codePoint > narrowMaximumCodePoint
|
|
91
|
-
) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return isInRange(narrowRanges, codePoint);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export const isWide = codePoint => {
|
|
99
|
-
if (
|
|
100
|
-
codePoint >= wideFastPathStart
|
|
101
|
-
&& codePoint <= wideFastPathEnd
|
|
102
|
-
) {
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
codePoint < wideMinimalCodePoint
|
|
108
|
-
|| codePoint > wideMaximumCodePoint
|
|
109
|
-
) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return isInRange(wideRanges, codePoint);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export function getCategory(codePoint) {
|
|
117
|
-
if (isAmbiguous(codePoint)) {
|
|
118
|
-
return 'ambiguous';
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (isFullWidth(codePoint)) {
|
|
122
|
-
return 'fullwidth';
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (isHalfWidth(codePoint)) {
|
|
126
|
-
return 'halfwidth';
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (isNarrow(codePoint)) {
|
|
130
|
-
return 'narrow';
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (isWide(codePoint)) {
|
|
134
|
-
return 'wide';
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return 'neutral';
|
|
138
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "get-east-asian-width",
|
|
3
|
-
"version": "1.6.0",
|
|
4
|
-
"description": "Determine the East Asian Width of a Unicode character",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"repository": "sindresorhus/get-east-asian-width",
|
|
7
|
-
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
|
-
"author": {
|
|
9
|
-
"name": "Sindre Sorhus",
|
|
10
|
-
"email": "sindresorhus@gmail.com",
|
|
11
|
-
"url": "https://sindresorhus.com"
|
|
12
|
-
},
|
|
13
|
-
"type": "module",
|
|
14
|
-
"exports": {
|
|
15
|
-
"types": "./index.d.ts",
|
|
16
|
-
"default": "./index.js"
|
|
17
|
-
},
|
|
18
|
-
"sideEffects": false,
|
|
19
|
-
"engines": {
|
|
20
|
-
"node": ">=18"
|
|
21
|
-
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"test": "xo && ava && tsc index.d.ts",
|
|
24
|
-
"build": "node scripts/build.js",
|
|
25
|
-
"prepublish": "npm run build"
|
|
26
|
-
},
|
|
27
|
-
"files": [
|
|
28
|
-
"index.js",
|
|
29
|
-
"index.d.ts",
|
|
30
|
-
"lookup.js",
|
|
31
|
-
"lookup-data.js",
|
|
32
|
-
"utilities.js"
|
|
33
|
-
],
|
|
34
|
-
"keywords": [
|
|
35
|
-
"unicode",
|
|
36
|
-
"east-asian-width",
|
|
37
|
-
"eastasianwidth",
|
|
38
|
-
"character",
|
|
39
|
-
"string",
|
|
40
|
-
"width",
|
|
41
|
-
"text",
|
|
42
|
-
"layout",
|
|
43
|
-
"alignment",
|
|
44
|
-
"fullwidth",
|
|
45
|
-
"halfwidth",
|
|
46
|
-
"ambiguous",
|
|
47
|
-
"narrow",
|
|
48
|
-
"wide",
|
|
49
|
-
"neutral",
|
|
50
|
-
"typography",
|
|
51
|
-
"japanese",
|
|
52
|
-
"chinese",
|
|
53
|
-
"korean",
|
|
54
|
-
"codepoint",
|
|
55
|
-
"text-processing",
|
|
56
|
-
"i18n",
|
|
57
|
-
"l10n"
|
|
58
|
-
],
|
|
59
|
-
"devDependencies": {
|
|
60
|
-
"ava": "^5.3.1",
|
|
61
|
-
"outdent": "^0.8.0",
|
|
62
|
-
"simplify-ranges": "^0.1.0",
|
|
63
|
-
"typescript": "^5.2.2",
|
|
64
|
-
"xo": "^0.56.0"
|
|
65
|
-
},
|
|
66
|
-
"xo": {
|
|
67
|
-
"ignores": [
|
|
68
|
-
"lookup-data.js"
|
|
69
|
-
]
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# get-east-asian-width
|
|
2
|
-
|
|
3
|
-
> Determine the [East Asian Width](https://unicode.org/reports/tr11/) of a Unicode character
|
|
4
|
-
|
|
5
|
-
> East Asian Width categorizes Unicode characters based on their occupied space in East Asian typography, which helps in text layout and alignment, particularly in languages like Japanese, Chinese, and Korean.
|
|
6
|
-
|
|
7
|
-
Unlike other similar packages, this package uses the latest Unicode data (which changes each year).
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
npm install get-east-asian-width
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
import {eastAsianWidth, eastAsianWidthType} from 'get-east-asian-width';
|
|
19
|
-
|
|
20
|
-
const codePoint = '字'.codePointAt(0);
|
|
21
|
-
|
|
22
|
-
console.log(eastAsianWidth(codePoint));
|
|
23
|
-
//=> 2
|
|
24
|
-
|
|
25
|
-
console.log(eastAsianWidthType(codePoint));
|
|
26
|
-
//=> 'wide'
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## `eastAsianWidth(codePoint: number, options?: object): 1 | 2`
|
|
30
|
-
|
|
31
|
-
Returns the width as a number for the given code point.
|
|
32
|
-
|
|
33
|
-
### options
|
|
34
|
-
|
|
35
|
-
Type: `object`
|
|
36
|
-
|
|
37
|
-
#### ambiguousAsWide
|
|
38
|
-
|
|
39
|
-
Type: `boolean`\
|
|
40
|
-
Default: `false`
|
|
41
|
-
|
|
42
|
-
Whether to treat an `'ambiguous'` character as wide.
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
import {eastAsianWidth} from 'get-east-asian-width';
|
|
46
|
-
|
|
47
|
-
const codePoint = '⛣'.codePointAt(0);
|
|
48
|
-
|
|
49
|
-
console.log(eastAsianWidth(codePoint));
|
|
50
|
-
//=> 1
|
|
51
|
-
|
|
52
|
-
console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
|
|
53
|
-
//=> 2
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
> Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). **If the context cannot be established reliably, they should be treated as narrow characters by default.**
|
|
57
|
-
> - http://www.unicode.org/reports/tr11/
|
|
58
|
-
|
|
59
|
-
## `eastAsianWidthType(codePoint: number): 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous'`
|
|
60
|
-
|
|
61
|
-
Returns the type of “East Asian Width” for the given code point.
|
|
62
|
-
|
|
63
|
-
## Related
|
|
64
|
-
|
|
65
|
-
- [string-width](https://github.com/sindresorhus/string-width) - Get the visual width of a string
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
Binary search on a sorted flat array of [start, end] pairs.
|
|
3
|
-
|
|
4
|
-
@param {number[]} ranges - Flat array of inclusive [start, end] range pairs, e.g. [0, 5, 10, 20].
|
|
5
|
-
@param {number} codePoint - The value to search for.
|
|
6
|
-
@returns {boolean} Whether the value falls within any of the ranges.
|
|
7
|
-
*/
|
|
8
|
-
export const isInRange = (ranges, codePoint) => {
|
|
9
|
-
let low = 0;
|
|
10
|
-
let high = Math.floor(ranges.length / 2) - 1;
|
|
11
|
-
while (low <= high) {
|
|
12
|
-
const mid = Math.floor((low + high) / 2);
|
|
13
|
-
const i = mid * 2;
|
|
14
|
-
if (codePoint < ranges[i]) {
|
|
15
|
-
high = mid - 1;
|
|
16
|
-
} else if (codePoint > ranges[i + 1]) {
|
|
17
|
-
low = mid + 1;
|
|
18
|
-
} else {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return false;
|
|
24
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export type Options = {
|
|
2
|
-
/**
|
|
3
|
-
Count [ambiguous width characters](https://www.unicode.org/reports/tr11/#Ambiguous) as having narrow width (count of 1) instead of wide width (count of 2).
|
|
4
|
-
|
|
5
|
-
@default true
|
|
6
|
-
|
|
7
|
-
> Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). __If the context cannot be established reliably, they should be treated as narrow characters by default.__
|
|
8
|
-
> - http://www.unicode.org/reports/tr11/
|
|
9
|
-
*/
|
|
10
|
-
readonly ambiguousIsNarrow?: boolean;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
Whether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted.
|
|
14
|
-
|
|
15
|
-
@default false
|
|
16
|
-
*/
|
|
17
|
-
readonly countAnsiEscapeCodes?: boolean;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
Get the visual width of a string - the number of columns required to display it.
|
|
22
|
-
|
|
23
|
-
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.
|
|
24
|
-
|
|
25
|
-
@example
|
|
26
|
-
```
|
|
27
|
-
import stringWidth from 'string-width';
|
|
28
|
-
|
|
29
|
-
stringWidth('a');
|
|
30
|
-
//=> 1
|
|
31
|
-
|
|
32
|
-
stringWidth('古');
|
|
33
|
-
//=> 2
|
|
34
|
-
|
|
35
|
-
stringWidth('\u001B[1m古\u001B[22m');
|
|
36
|
-
//=> 2
|
|
37
|
-
```
|
|
38
|
-
*/
|
|
39
|
-
export default function stringWidth(string: string, options?: Options): number;
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import stripAnsi from 'strip-ansi';
|
|
2
|
-
import {eastAsianWidth} from 'get-east-asian-width';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
Logic:
|
|
6
|
-
- Segment graphemes to match how terminals render clusters.
|
|
7
|
-
- Width rules:
|
|
8
|
-
1. Skip non-printing clusters (Default_Ignorable, Control, pure nonspacing/enclosing Mark, lone Surrogates). Tabs are ignored by design.
|
|
9
|
-
2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
|
|
10
|
-
3. Minimally-qualified/unqualified emoji clusters (ZWJ sequences with 2+ Extended_Pictographic, or keycap sequences) are double-width.
|
|
11
|
-
4. Hangul jamo collapse each standard modern Hangul L+V or L+V+T syllable piece to width 2.
|
|
12
|
-
Unmatched repeated leading/vowel/trailing jamo stay additive because that matches how the terminals we target render them.
|
|
13
|
-
5. Otherwise use East Asian Width of the cluster's first visible code point, and add widths for trailing spacing marks and Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const segmenter = new Intl.Segmenter();
|
|
17
|
-
|
|
18
|
-
// Whole-cluster zero-width
|
|
19
|
-
const zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Nonspacing_Mark}|\p{Enclosing_Mark}|\p{Surrogate})+$/v;
|
|
20
|
-
|
|
21
|
-
// Pick the base scalar if the cluster starts with Prepend/Format/Marks
|
|
22
|
-
const leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Nonspacing_Mark}\p{Enclosing_Mark}\p{Surrogate}]+/v;
|
|
23
|
-
const spacingMarkRegex = /\p{Spacing_Mark}/v;
|
|
24
|
-
|
|
25
|
-
// RGI emoji sequences
|
|
26
|
-
const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
|
|
27
|
-
|
|
28
|
-
// Detect minimally-qualified/unqualified emoji sequences (missing VS16 but still render as double-width)
|
|
29
|
-
const unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
|
|
30
|
-
const extendedPictographicRegex = /\p{Extended_Pictographic}/gu;
|
|
31
|
-
|
|
32
|
-
function isDoubleWidthNonRgiEmojiSequence(segment) {
|
|
33
|
-
// Real emoji clusters are < 30 chars; guard against pathological input
|
|
34
|
-
if (segment.length > 50) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (unqualifiedKeycapRegex.test(segment)) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ZWJ sequences with 2+ Extended_Pictographic
|
|
43
|
-
if (segment.includes('\u200D')) {
|
|
44
|
-
const pictographics = segment.match(extendedPictographicRegex);
|
|
45
|
-
return pictographics !== null && pictographics.length >= 2;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function baseVisible(segment) {
|
|
52
|
-
return segment.replace(leadingNonPrintingRegex, '');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function isZeroWidthCluster(segment) {
|
|
56
|
-
return zeroWidthClusterRegex.test(segment);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function isHangulLeadingJamo(codePoint) {
|
|
60
|
-
return (codePoint >= 0x11_00 && codePoint <= 0x11_5F)
|
|
61
|
-
|| (codePoint >= 0xA9_60 && codePoint <= 0xA9_7C);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function isHangulVowelJamo(codePoint) {
|
|
65
|
-
return (codePoint >= 0x11_60 && codePoint <= 0x11_A7)
|
|
66
|
-
|| (codePoint >= 0xD7_B0 && codePoint <= 0xD7_C6);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function isHangulTrailingJamo(codePoint) {
|
|
70
|
-
return (codePoint >= 0x11_A8 && codePoint <= 0x11_FF)
|
|
71
|
-
|| (codePoint >= 0xD7_CB && codePoint <= 0xD7_FB);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function isHangulJamo(codePoint) {
|
|
75
|
-
return isHangulLeadingJamo(codePoint)
|
|
76
|
-
|| isHangulVowelJamo(codePoint)
|
|
77
|
-
|| isHangulTrailingJamo(codePoint);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
|
|
81
|
-
const codePoints = [];
|
|
82
|
-
|
|
83
|
-
for (const character of visibleSegment) {
|
|
84
|
-
if (zeroWidthClusterRegex.test(character)) {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
codePoints.push(character.codePointAt(0));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (codePoints.length === 0) {
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
let width = 0;
|
|
96
|
-
|
|
97
|
-
for (let index = 0; index < codePoints.length; index++) {
|
|
98
|
-
const codePoint = codePoints[index];
|
|
99
|
-
if (!isHangulJamo(codePoint)) {
|
|
100
|
-
if (width === 0) {
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Mixed cluster (e.g., L + precomposed syllable): use EAW for non-jamo remainder
|
|
105
|
-
for (let remaining = index; remaining < codePoints.length; remaining++) {
|
|
106
|
-
width += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return width;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Modern Hangul L+V(+T) shapes as one syllable block. Unmatched jamo stay additive:
|
|
113
|
-
// U+1100 U+1100 U+1161 => U+1100 + (U+1100 U+1161) => 2 + 2.
|
|
114
|
-
if (
|
|
115
|
-
isHangulLeadingJamo(codePoint)
|
|
116
|
-
&& isHangulVowelJamo(codePoints[index + 1])
|
|
117
|
-
) {
|
|
118
|
-
width += 2;
|
|
119
|
-
index += isHangulTrailingJamo(codePoints[index + 2]) ? 2 : 1;
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return width;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function trailingWidth(visibleSegment, eastAsianWidthOptions) {
|
|
130
|
-
let extra = 0;
|
|
131
|
-
let first = true;
|
|
132
|
-
|
|
133
|
-
for (const character of visibleSegment) {
|
|
134
|
-
if (first) {
|
|
135
|
-
first = false;
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
spacingMarkRegex.test(character)
|
|
141
|
-
|| (character >= '\uFF00' && character <= '\uFFEF')
|
|
142
|
-
) {
|
|
143
|
-
extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return extra;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export default function stringWidth(input, options = {}) {
|
|
151
|
-
if (typeof input !== 'string' || input.length === 0) {
|
|
152
|
-
return 0;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const {
|
|
156
|
-
ambiguousIsNarrow = true,
|
|
157
|
-
countAnsiEscapeCodes = false,
|
|
158
|
-
} = options;
|
|
159
|
-
|
|
160
|
-
let string = input;
|
|
161
|
-
|
|
162
|
-
// Avoid calling stripAnsi when there are no ANSI escape sequences (ESC = 0x1B, CSI = 0x9B)
|
|
163
|
-
if (!countAnsiEscapeCodes && (string.includes('\u001B') || string.includes('\u009B'))) {
|
|
164
|
-
string = stripAnsi(string);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (string.length === 0) {
|
|
168
|
-
return 0;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Fast path: printable ASCII (0x20–0x7E) needs no segmenter, regex, or EAW lookup — width equals length.
|
|
172
|
-
if (/^[\u0020-\u007E]*$/.test(string)) {
|
|
173
|
-
return string.length;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
let width = 0;
|
|
177
|
-
const eastAsianWidthOptions = {ambiguousAsWide: !ambiguousIsNarrow};
|
|
178
|
-
|
|
179
|
-
for (const {segment} of segmenter.segment(string)) {
|
|
180
|
-
// Zero-width / non-printing clusters
|
|
181
|
-
if (isZeroWidthCluster(segment)) {
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Emoji width logic
|
|
186
|
-
if (rgiEmojiRegex.test(segment) || isDoubleWidthNonRgiEmojiSequence(segment)) {
|
|
187
|
-
width += 2;
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const visibleSegment = baseVisible(segment);
|
|
192
|
-
const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
|
|
193
|
-
if (hangulWidth !== undefined) {
|
|
194
|
-
width += hangulWidth;
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Everything else: EAW of the cluster’s first visible scalar
|
|
199
|
-
const codePoint = visibleSegment.codePointAt(0);
|
|
200
|
-
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
201
|
-
|
|
202
|
-
// Add width for trailing spacing marks and Halfwidth/Fullwidth Forms (e.g., ゙, ゚, ー)
|
|
203
|
-
width += trailingWidth(visibleSegment, eastAsianWidthOptions);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return width;
|
|
207
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "string-width",
|
|
3
|
-
"version": "8.2.2",
|
|
4
|
-
"description": "Get the visual width of a string - the number of columns required to display it",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"repository": "sindresorhus/string-width",
|
|
7
|
-
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
|
-
"author": {
|
|
9
|
-
"name": "Sindre Sorhus",
|
|
10
|
-
"email": "sindresorhus@gmail.com",
|
|
11
|
-
"url": "https://sindresorhus.com"
|
|
12
|
-
},
|
|
13
|
-
"type": "module",
|
|
14
|
-
"exports": {
|
|
15
|
-
"types": "./index.d.ts",
|
|
16
|
-
"default": "./index.js"
|
|
17
|
-
},
|
|
18
|
-
"sideEffects": false,
|
|
19
|
-
"engines": {
|
|
20
|
-
"node": ">=20"
|
|
21
|
-
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"test": "xo && ava && tsd"
|
|
24
|
-
},
|
|
25
|
-
"files": [
|
|
26
|
-
"index.js",
|
|
27
|
-
"index.d.ts"
|
|
28
|
-
],
|
|
29
|
-
"keywords": [
|
|
30
|
-
"string",
|
|
31
|
-
"character",
|
|
32
|
-
"unicode",
|
|
33
|
-
"width",
|
|
34
|
-
"visual",
|
|
35
|
-
"column",
|
|
36
|
-
"columns",
|
|
37
|
-
"fullwidth",
|
|
38
|
-
"full-width",
|
|
39
|
-
"wcwidth",
|
|
40
|
-
"wcswidth",
|
|
41
|
-
"full",
|
|
42
|
-
"ansi",
|
|
43
|
-
"escape",
|
|
44
|
-
"codes",
|
|
45
|
-
"cli",
|
|
46
|
-
"command-line",
|
|
47
|
-
"terminal",
|
|
48
|
-
"console",
|
|
49
|
-
"cjk",
|
|
50
|
-
"chinese",
|
|
51
|
-
"japanese",
|
|
52
|
-
"korean",
|
|
53
|
-
"fixed-width",
|
|
54
|
-
"east-asian-width"
|
|
55
|
-
],
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"get-east-asian-width": "^1.5.0",
|
|
58
|
-
"strip-ansi": "^7.1.2"
|
|
59
|
-
},
|
|
60
|
-
"devDependencies": {
|
|
61
|
-
"ava": "^6.4.1",
|
|
62
|
-
"tsd": "^0.33.0",
|
|
63
|
-
"xo": "^1.2.3"
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# string-width
|
|
2
|
-
|
|
3
|
-
> Get the visual width of a string - the number of columns required to display it
|
|
4
|
-
|
|
5
|
-
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 do not affect the width.
|
|
6
|
-
|
|
7
|
-
Useful to be able to measure the actual width of command-line output.
|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
npm install string-width
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
import stringWidth from 'string-width';
|
|
19
|
-
|
|
20
|
-
stringWidth('a');
|
|
21
|
-
//=> 1
|
|
22
|
-
|
|
23
|
-
stringWidth('古');
|
|
24
|
-
//=> 2
|
|
25
|
-
|
|
26
|
-
stringWidth('\u001B[1m古\u001B[22m');
|
|
27
|
-
//=> 2
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## API
|
|
31
|
-
|
|
32
|
-
### stringWidth(string, options?)
|
|
33
|
-
|
|
34
|
-
#### string
|
|
35
|
-
|
|
36
|
-
Type: `string`
|
|
37
|
-
|
|
38
|
-
The string to be counted.
|
|
39
|
-
|
|
40
|
-
#### options
|
|
41
|
-
|
|
42
|
-
Type: `object`
|
|
43
|
-
|
|
44
|
-
##### ambiguousIsNarrow
|
|
45
|
-
|
|
46
|
-
Type: `boolean`\
|
|
47
|
-
Default: `true`
|
|
48
|
-
|
|
49
|
-
Count [ambiguous width characters](https://www.unicode.org/reports/tr11/#Ambiguous) as having narrow width (count of 1) instead of wide width (count of 2).
|
|
50
|
-
|
|
51
|
-
> Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). **If the context cannot be established reliably, they should be treated as narrow characters by default.**
|
|
52
|
-
> - http://www.unicode.org/reports/tr11/
|
|
53
|
-
|
|
54
|
-
##### countAnsiEscapeCodes
|
|
55
|
-
|
|
56
|
-
Type: `boolean`\
|
|
57
|
-
Default: `false`
|
|
58
|
-
|
|
59
|
-
Whether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted.
|
|
60
|
-
|
|
61
|
-
## Related
|
|
62
|
-
|
|
63
|
-
- [string-width-cli](https://github.com/sindresorhus/string-width-cli) - CLI for this module
|
|
64
|
-
- [string-length](https://github.com/sindresorhus/string-length) - Get the real length of a string
|
|
65
|
-
- [widest-line](https://github.com/sindresorhus/widest-line) - Get the visual width of the widest line in a string
|
|
66
|
-
- [get-east-asian-width](https://github.com/sindresorhus/get-east-asian-width) - Determine the East Asian Width of a Unicode character
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
|
|
3
|
-
|
|
4
|
-
@example
|
|
5
|
-
```
|
|
6
|
-
import stripAnsi from 'strip-ansi';
|
|
7
|
-
|
|
8
|
-
stripAnsi('\u001B[4mUnicorn\u001B[0m');
|
|
9
|
-
//=> 'Unicorn'
|
|
10
|
-
|
|
11
|
-
stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
|
|
12
|
-
//=> 'Click'
|
|
13
|
-
```
|
|
14
|
-
*/
|
|
15
|
-
export default function stripAnsi(string: string): string;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import ansiRegex from 'ansi-regex';
|
|
2
|
-
|
|
3
|
-
const regex = ansiRegex();
|
|
4
|
-
|
|
5
|
-
export default function stripAnsi(string) {
|
|
6
|
-
if (typeof string !== 'string') {
|
|
7
|
-
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// Fast path: ANSI codes require ESC (7-bit) or CSI (8-bit) introducer
|
|
11
|
-
if (!string.includes('\u001B') && !string.includes('\u009B')) {
|
|
12
|
-
return string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Even though the regex is global, we don't need to reset the `.lastIndex`
|
|
16
|
-
// because unlike `.exec()` and `.test()`, `.replace()` does it automatically
|
|
17
|
-
// and doing it manually has a performance penalty.
|
|
18
|
-
return string.replace(regex, '');
|
|
19
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "strip-ansi",
|
|
3
|
-
"version": "7.2.0",
|
|
4
|
-
"description": "Strip ANSI escape codes from a string",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"repository": "chalk/strip-ansi",
|
|
7
|
-
"funding": "https://github.com/chalk/strip-ansi?sponsor=1",
|
|
8
|
-
"author": {
|
|
9
|
-
"name": "Sindre Sorhus",
|
|
10
|
-
"email": "sindresorhus@gmail.com",
|
|
11
|
-
"url": "https://sindresorhus.com"
|
|
12
|
-
},
|
|
13
|
-
"type": "module",
|
|
14
|
-
"exports": "./index.js",
|
|
15
|
-
"types": "./index.d.ts",
|
|
16
|
-
"sideEffects": false,
|
|
17
|
-
"engines": {
|
|
18
|
-
"node": ">=12"
|
|
19
|
-
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"test": "xo && ava && tsd"
|
|
22
|
-
},
|
|
23
|
-
"files": [
|
|
24
|
-
"index.js",
|
|
25
|
-
"index.d.ts"
|
|
26
|
-
],
|
|
27
|
-
"keywords": [
|
|
28
|
-
"strip",
|
|
29
|
-
"trim",
|
|
30
|
-
"remove",
|
|
31
|
-
"ansi",
|
|
32
|
-
"styles",
|
|
33
|
-
"color",
|
|
34
|
-
"colour",
|
|
35
|
-
"colors",
|
|
36
|
-
"terminal",
|
|
37
|
-
"console",
|
|
38
|
-
"string",
|
|
39
|
-
"tty",
|
|
40
|
-
"escape",
|
|
41
|
-
"formatting",
|
|
42
|
-
"rgb",
|
|
43
|
-
"256",
|
|
44
|
-
"shell",
|
|
45
|
-
"xterm",
|
|
46
|
-
"log",
|
|
47
|
-
"logging",
|
|
48
|
-
"command-line",
|
|
49
|
-
"text"
|
|
50
|
-
],
|
|
51
|
-
"dependencies": {
|
|
52
|
-
"ansi-regex": "^6.2.2"
|
|
53
|
-
},
|
|
54
|
-
"devDependencies": {
|
|
55
|
-
"ava": "^6.4.1",
|
|
56
|
-
"tsd": "^0.33.0",
|
|
57
|
-
"xo": "^1.2.3"
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# strip-ansi
|
|
2
|
-
|
|
3
|
-
> Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string
|
|
4
|
-
|
|
5
|
-
> [!NOTE]
|
|
6
|
-
> Node.js has this built-in now with [`stripVTControlCharacters`](https://nodejs.org/api/util.html#utilstripvtcontrolcharactersstr). The benefit of this package is consistent behavior across Node.js versions and faster improvements. The Node.js version is actually based on this package.
|
|
7
|
-
|
|
8
|
-
## Install
|
|
9
|
-
|
|
10
|
-
```sh
|
|
11
|
-
npm install strip-ansi
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Usage
|
|
15
|
-
|
|
16
|
-
```js
|
|
17
|
-
import stripAnsi from 'strip-ansi';
|
|
18
|
-
|
|
19
|
-
stripAnsi('\u001B[4mUnicorn\u001B[0m');
|
|
20
|
-
//=> 'Unicorn'
|
|
21
|
-
|
|
22
|
-
stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
|
|
23
|
-
//=> 'Click'
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Related
|
|
27
|
-
|
|
28
|
-
- [strip-ansi-cli](https://github.com/chalk/strip-ansi-cli) - CLI for this module
|
|
29
|
-
- [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Streaming version of this module
|
|
30
|
-
- [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
|
|
31
|
-
- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
|
|
32
|
-
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
|
|
33
|
-
|
|
34
|
-
## Maintainers
|
|
35
|
-
|
|
36
|
-
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
37
|
-
- [Josh Junon](https://github.com/qix-)
|