@alcalzone/ansi-tokenize 0.2.0 → 0.2.2
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/LICENSE +21 -0
- package/README.md +8 -0
- package/build/ansiCodes.d.ts +2 -0
- package/build/ansiCodes.js +11 -2
- package/build/ansiCodes.js.map +1 -1
- package/build/reduce.js +14 -3
- package/build/reduce.js.map +1 -1
- package/build/tokenize.js +96 -25
- package/build/tokenize.js.map +1 -1
- package/package.json +10 -18
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2025 AlCalzone
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -231,6 +231,14 @@ This automatically figures out the least amount of escape codes necessary to ach
|
|
|
231
231
|
Placeholder for next release:
|
|
232
232
|
### __WORK IN PROGRESS__
|
|
233
233
|
-->
|
|
234
|
+
### 0.2.2 (2025-10-22)
|
|
235
|
+
|
|
236
|
+
- Fix: Support compound SGR sequences with multiple attributes (#39, #40)
|
|
237
|
+
|
|
238
|
+
### 0.2.1 (2025-10-20)
|
|
239
|
+
|
|
240
|
+
- Fix: Prevent `dim` and `bold` modifiers from canceling each other (#37)
|
|
241
|
+
|
|
234
242
|
### 0.2.0 (2025-04-24)
|
|
235
243
|
|
|
236
244
|
- Breaking: Require Node.js 18+
|
package/build/ansiCodes.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { AnsiCode } from "./tokenize.js";
|
|
2
2
|
export declare const ESCAPES: Set<number>;
|
|
3
|
+
export declare const CSI: number;
|
|
4
|
+
export declare const OSC: number;
|
|
3
5
|
export declare const endCodesSet: Set<string>;
|
|
4
6
|
export declare const linkStartCodePrefix = "\u001B]8;;";
|
|
5
7
|
export declare const linkStartCodePrefixCharCodes: number[];
|
package/build/ansiCodes.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import ansiStyles from "ansi-styles";
|
|
2
2
|
export const ESCAPES = new Set([27, 155]); // \x1b and \x9b
|
|
3
|
+
export const CSI = "[".codePointAt(0);
|
|
4
|
+
export const OSC = "]".codePointAt(0);
|
|
3
5
|
export const endCodesSet = new Set();
|
|
4
6
|
const endCodesMap = new Map();
|
|
5
7
|
for (const [start, end] of ansiStyles.codes) {
|
|
@@ -21,12 +23,19 @@ export function getEndCode(code) {
|
|
|
21
23
|
return code;
|
|
22
24
|
if (endCodesMap.has(code))
|
|
23
25
|
return endCodesMap.get(code);
|
|
26
|
+
// We have a few special cases to handle here:
|
|
27
|
+
// Links:
|
|
24
28
|
if (code.startsWith(linkStartCodePrefix))
|
|
25
29
|
return linkEndCode;
|
|
26
30
|
code = code.slice(2);
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
// 8-bit/24-bit colors:
|
|
32
|
+
if (code.startsWith("38")) {
|
|
33
|
+
return ansiStyles.color.close;
|
|
29
34
|
}
|
|
35
|
+
else if (code.startsWith("48")) {
|
|
36
|
+
return ansiStyles.bgColor.close;
|
|
37
|
+
}
|
|
38
|
+
// Otherwise find the reset code in the ansi-styles map
|
|
30
39
|
const ret = ansiStyles.codes.get(parseInt(code, 10));
|
|
31
40
|
if (ret) {
|
|
32
41
|
return ansiStyles.color.ansi(ret);
|
package/build/ansiCodes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ansiCodes.js","sourceRoot":"","sources":["../src/ansiCodes.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AAGrC,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB;
|
|
1
|
+
{"version":3,"file":"ansiCodes.js","sourceRoot":"","sources":["../src/ansiCodes.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AAGrC,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB;AAC3D,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC;AACvC,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC;AAEvC,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;AAC7C,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;AAC9C,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,UAAU,CAAC,KAAK,EAAE;IAC5C,WAAW,CAAC,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KAAK,CAAC;KAC9B;SAAM,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACjC,OAAO,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC;KAChC;IAED,uDAAuD;IACvD,MAAM,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IACrD,IAAI,GAAG,EAAE;QACR,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAClC;SAAM;QACN,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC;KAC7B;AACF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAiB;IAClD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChD,CAAC"}
|
package/build/reduce.js
CHANGED
|
@@ -17,9 +17,20 @@ export function reduceAnsiCodesIncremental(codes, newCodes) {
|
|
|
17
17
|
ret = ret.filter((retCode) => retCode.endCode !== code.code);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
// This is a start code.
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
// This is a start code. Remove codes it "overrides", then add it.
|
|
21
|
+
// If a new code has the same endCode, it "overrides" existing ones.
|
|
22
|
+
// Special case: Intensity codes (1m, 2m) can coexist (both end with 22m).
|
|
23
|
+
const isIntensityCode = code.code === ansiStyles.bold.open || code.code === ansiStyles.dim.open;
|
|
24
|
+
// Add intensity codes only if not already present
|
|
25
|
+
if (isIntensityCode) {
|
|
26
|
+
if (!ret.find((retCode) => retCode.code === code.code && retCode.endCode === code.endCode)) {
|
|
27
|
+
ret.push(code);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
ret = ret.filter((retCode) => retCode.endCode !== code.endCode);
|
|
32
|
+
ret.push(code);
|
|
33
|
+
}
|
|
23
34
|
}
|
|
24
35
|
}
|
|
25
36
|
return ret;
|
package/build/reduce.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reduce.js","sourceRoot":"","sources":["../src/reduce.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,mGAAmG;AACnG,MAAM,UAAU,eAAe,CAAC,KAAiB;IAChD,OAAO,0BAA0B,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED,+IAA+I;AAC/I,MAAM,UAAU,0BAA0B,CAAC,KAAiB,EAAE,QAAoB;IACjF,IAAI,GAAG,GAAe,CAAC,GAAG,KAAK,CAAC,CAAC;IACjC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE;QAC5B,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE;YACxC,gCAAgC;YAChC,GAAG,GAAG,EAAE,CAAC;SACT;aAAM,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACtC,wDAAwD;YACxD,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC;SAC7D;aAAM;YACN,
|
|
1
|
+
{"version":3,"file":"reduce.js","sourceRoot":"","sources":["../src/reduce.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,mGAAmG;AACnG,MAAM,UAAU,eAAe,CAAC,KAAiB;IAChD,OAAO,0BAA0B,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED,+IAA+I;AAC/I,MAAM,UAAU,0BAA0B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ePoint from "is-fullwidth-code-point";
|
|
2
|
-
import { ESCAPES, getEndCode, linkStartCodePrefix, linkStartCodePrefixCharCodes, } from "./ansiCodes.js";
|
|
3
|
-
|
|
4
|
-
for (let index = 0; index < str.length; index++) {
|
|
5
|
-
const charCode = str.charCodeAt(index);
|
|
6
|
-
if (charCode >= 48 && charCode <= 57) {
|
|
7
|
-
return index;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
return -1;
|
|
11
|
-
}
|
|
2
|
+
import { CSI, ESCAPES, getEndCode, linkStartCodePrefix, linkStartCodePrefixCharCodes, OSC, } from "./ansiCodes.js";
|
|
3
|
+
// HOT PATH: Use only basic string/char code operations for maximum performance
|
|
12
4
|
function parseLinkCode(string, offset) {
|
|
13
5
|
string = string.slice(offset);
|
|
14
6
|
for (let index = 1; index < linkStartCodePrefixCharCodes.length; index++) {
|
|
@@ -22,16 +14,73 @@ function parseLinkCode(string, offset) {
|
|
|
22
14
|
return undefined;
|
|
23
15
|
return string.slice(0, endIndex + 1);
|
|
24
16
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
const CC_0 = "0".charCodeAt(0);
|
|
18
|
+
const CC_9 = "9".charCodeAt(0);
|
|
19
|
+
const CC_SEMI = ";".charCodeAt(0);
|
|
20
|
+
const CC_M = "m".charCodeAt(0);
|
|
21
|
+
/**
|
|
22
|
+
* Scans through the given string and finds the index of the last character of an SGR sequence
|
|
23
|
+
* like `\x1B[38;2;123;123;123m`. This assumes that the string has been checked to start with `\x1B[`.
|
|
24
|
+
* Returns -1 if no valid SGR sequence is found.
|
|
25
|
+
*/
|
|
26
|
+
function findSGRSequenceEndIndex(str) {
|
|
27
|
+
for (let index = 2; index < str.length; index++) {
|
|
28
|
+
const charCode = str.charCodeAt(index);
|
|
29
|
+
// m marks the end of the SGR sequence
|
|
30
|
+
if (charCode === CC_M)
|
|
31
|
+
return index;
|
|
32
|
+
// Digits and semicolons are valid
|
|
33
|
+
if (charCode === CC_SEMI)
|
|
34
|
+
continue;
|
|
35
|
+
if (charCode >= CC_0 && charCode <= CC_9)
|
|
36
|
+
continue;
|
|
37
|
+
// Everything else is invalid
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
return -1;
|
|
41
|
+
}
|
|
42
|
+
// HOT PATH: Use only basic string/char code operations for maximum performance
|
|
43
|
+
function parseSGRSequence(string, offset) {
|
|
44
|
+
string = string.slice(offset);
|
|
45
|
+
const endIndex = findSGRSequenceEndIndex(string);
|
|
46
|
+
if (endIndex === -1)
|
|
47
|
+
return;
|
|
48
|
+
return string.slice(0, endIndex + 1);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Splits compound SGR sequences like `\x1B[1;3;31m` into individual components
|
|
52
|
+
*/
|
|
53
|
+
function splitCompoundSGRSequences(code) {
|
|
54
|
+
if (!code.includes(";")) {
|
|
55
|
+
// Not a compound code
|
|
56
|
+
return [code];
|
|
57
|
+
}
|
|
58
|
+
const codeParts = code
|
|
59
|
+
// Strip off the escape sequences \x1B[ and m
|
|
60
|
+
.slice(2, -1)
|
|
61
|
+
.split(";");
|
|
62
|
+
const ret = [];
|
|
63
|
+
for (let i = 0; i < codeParts.length; i++) {
|
|
64
|
+
const rawCode = codeParts[i];
|
|
65
|
+
// Keep 8-bit and 24-bit color codes (containing multiple ";") together
|
|
66
|
+
if (rawCode === "38" || rawCode === "48") {
|
|
67
|
+
if (i + 2 < codeParts.length && codeParts[i + 1] === "5") {
|
|
68
|
+
// 8-bit color, followed by another number
|
|
69
|
+
ret.push(codeParts.slice(i, i + 3).join(";"));
|
|
70
|
+
i += 2;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
else if (i + 4 < codeParts.length && codeParts[i + 1] === "2") {
|
|
74
|
+
// 24-bit color, followed by three numbers
|
|
75
|
+
ret.push(codeParts.slice(i, i + 5).join(";"));
|
|
76
|
+
i += 4;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
32
79
|
}
|
|
33
|
-
|
|
80
|
+
// Not a (valid) 8/24-bit color code, push as is
|
|
81
|
+
ret.push(rawCode);
|
|
34
82
|
}
|
|
83
|
+
return ret.map((part) => `\x1b[${part}m`);
|
|
35
84
|
}
|
|
36
85
|
export function tokenize(str, endChar = Number.POSITIVE_INFINITY) {
|
|
37
86
|
const ret = [];
|
|
@@ -40,14 +89,36 @@ export function tokenize(str, endChar = Number.POSITIVE_INFINITY) {
|
|
|
40
89
|
while (index < str.length) {
|
|
41
90
|
const codePoint = str.codePointAt(index);
|
|
42
91
|
if (ESCAPES.has(codePoint)) {
|
|
43
|
-
|
|
44
|
-
|
|
92
|
+
let code;
|
|
93
|
+
// Peek the next code point to determine the type of ANSI sequence
|
|
94
|
+
const nextCodePoint = str.codePointAt(index + 1);
|
|
95
|
+
if (nextCodePoint === OSC) {
|
|
96
|
+
// ] = operating system commands, like links
|
|
97
|
+
code = parseLinkCode(str, index);
|
|
98
|
+
if (code) {
|
|
99
|
+
ret.push({
|
|
100
|
+
type: "ansi",
|
|
101
|
+
code: code,
|
|
102
|
+
endCode: getEndCode(code),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (nextCodePoint === CSI) {
|
|
107
|
+
// [ = control sequence introducer, like SGR sequences [...m
|
|
108
|
+
code = parseSGRSequence(str, index);
|
|
109
|
+
if (code) {
|
|
110
|
+
// Split compound codes into individual tokens
|
|
111
|
+
const codes = splitCompoundSGRSequences(code);
|
|
112
|
+
for (const individualCode of codes) {
|
|
113
|
+
ret.push({
|
|
114
|
+
type: "ansi",
|
|
115
|
+
code: individualCode,
|
|
116
|
+
endCode: getEndCode(individualCode),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
45
121
|
if (code) {
|
|
46
|
-
ret.push({
|
|
47
|
-
type: "ansi",
|
|
48
|
-
code,
|
|
49
|
-
endCode: getEndCode(code),
|
|
50
|
-
});
|
|
51
122
|
index += code.length;
|
|
52
123
|
continue;
|
|
53
124
|
}
|
package/build/tokenize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenize.js","sourceRoot":"","sources":["../src/tokenize.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACN,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,4BAA4B,
|
|
1
|
+
{"version":3,"file":"tokenize.js","sourceRoot":"","sources":["../src/tokenize.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACN,GAAG,EACH,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,4BAA4B,EAC5B,GAAG,GACH,MAAM,gBAAgB,CAAC;AAgBxB,+EAA+E;AAC/E,SAAS,aAAa,CAAC,MAAc,EAAE,MAAc;IACpD,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,4BAA4B,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACzE,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,4BAA4B,CAAC,KAAK,CAAC,EAAE;YACrE,OAAO,SAAS,CAAC;SACjB;KACD;IACD,0EAA0E;IAC1E,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;IACpE,IAAI,QAAQ,KAAK,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IAEtC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAC/B,MAAM,IAAI,GAAG,GAAG,CAA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Aa,CAAC,SAAS,CAAC,CAAC;QAElD,GAAG,CAAC,IAAI,CAAC;YACR,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,SAAS;YAChB,SAAS;SACT,CAAC,CAAC;QAEH,KAAK,IAAI,SAAS,CAAC,MAAM,CAAC;QAC1B,OAAO,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC;QAE5C,IAAI,OAAO,IAAI,OAAO,EAAE;YACvB,MAAM;SACN;KACD;IAED,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alcalzone/ansi-tokenize",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Efficiently modify strings containing ANSI escape codes",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -27,21 +27,18 @@
|
|
|
27
27
|
"node": ">=18"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@alcalzone/release-script": "~
|
|
31
|
-
"@alcalzone/release-script-plugin-license": "~
|
|
32
|
-
"@tsconfig/
|
|
33
|
-
"@types/node": "^
|
|
30
|
+
"@alcalzone/release-script": "~4.0.0",
|
|
31
|
+
"@alcalzone/release-script-plugin-license": "~4.0.0",
|
|
32
|
+
"@tsconfig/node18": "^18.2.4",
|
|
33
|
+
"@types/node": "^18.19.130",
|
|
34
34
|
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
35
35
|
"@typescript-eslint/parser": "^5.55.0",
|
|
36
|
-
"ava": "^4.3.3",
|
|
37
36
|
"eslint": "^8.36.0",
|
|
38
37
|
"eslint-config-prettier": "^8.7.0",
|
|
39
38
|
"eslint-plugin-prettier": "^4.2.1",
|
|
40
39
|
"prettier": "^2.8.4",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"tsx": "^3.12.8",
|
|
44
|
-
"typescript": "^5.0.2"
|
|
40
|
+
"typescript": "^5.0.2",
|
|
41
|
+
"vitest": "^3.2.4"
|
|
45
42
|
},
|
|
46
43
|
"dependencies": {
|
|
47
44
|
"ansi-styles": "^6.2.1",
|
|
@@ -50,14 +47,9 @@
|
|
|
50
47
|
"scripts": {
|
|
51
48
|
"prepare": "tsc -p tsconfig.build.json",
|
|
52
49
|
"build": "tsc -p tsconfig.build.json",
|
|
53
|
-
"test": "
|
|
50
|
+
"test": "vitest run",
|
|
54
51
|
"lint": "eslint .",
|
|
55
52
|
"release": "release-script"
|
|
56
53
|
},
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
"ts": "module"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
"packageManager": "yarn@3.5.0"
|
|
63
|
-
}
|
|
54
|
+
"packageManager": "yarn@4.10.3"
|
|
55
|
+
}
|