js-dev-tool 1.2.10 → 1.2.12
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/README.md +286 -120
- package/extras/cc-map.d.ts +141 -0
- package/extras/cc-map.js +140 -0
- package/extras/json-minify.d.ts +16 -0
- package/extras/json-minify.js +266 -0
- package/extras/jsonl.d.ts +8 -1
- package/extras/jsonl.js +5 -3
- package/extras/progress-light.d.ts +29 -0
- package/extras/progress-light.js +207 -0
- package/lib/unzip.min.js +3 -1
- package/lib/zip.min.js +1 -0
- package/package.json +3 -1
- package/progress/spinners.d.ts +1 -1
- package/tool-lib/rws.js +2 -3
- package/tools.js +7 -7
- package/tsconfig.json +5 -0
package/extras/cc-map.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
3
|
+
// Copyright (C) 2026 jeffy-g <hirotom1107@gmail.com>
|
|
4
|
+
// Released under the MIT license
|
|
5
|
+
// https://opensource.org/licenses/mit-license.php
|
|
6
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @file extras/cc-map.js
|
|
10
|
+
* @import { TCC_MAP } from "./cc-map";
|
|
11
|
+
*/
|
|
12
|
+
module.exports = /** @type {TCC_MAP} */({
|
|
13
|
+
/** `\u0000` */ NULL: 0,
|
|
14
|
+
/** `\u0001` */ SOH: 1,
|
|
15
|
+
/** `\u0002` */ STX: 2,
|
|
16
|
+
/** `\u0003` */ ETX: 3,
|
|
17
|
+
/** `\u0004` */ EOT: 4,
|
|
18
|
+
/** `\u0005` */ ENQ: 5,
|
|
19
|
+
/** `\u0006` */ ACK: 6,
|
|
20
|
+
/** `\u0007` */ BEL: 7,
|
|
21
|
+
/** `\u0008` */ BS: 8,
|
|
22
|
+
/** `\t` */ TAB: 9,
|
|
23
|
+
/** `\n` */ LF: 10,
|
|
24
|
+
/** `\u000b` */ VT: 11,
|
|
25
|
+
/** `\f` */ FF: 12,
|
|
26
|
+
/** `\r` */ CR: 13,
|
|
27
|
+
/** `\u000e` */ SO: 14,
|
|
28
|
+
/** `\u000f` */ SI: 15,
|
|
29
|
+
/** `\u0010` */ DLE: 16,
|
|
30
|
+
/** `\u0011` */ DC1: 17,
|
|
31
|
+
/** `\u0012` */ DC2: 18,
|
|
32
|
+
/** `\u0013` */ DC3: 19,
|
|
33
|
+
/** `\u0014` */ DC4: 20,
|
|
34
|
+
/** `\u0015` */ NAK: 21,
|
|
35
|
+
/** `\u0016` */ SYN: 22,
|
|
36
|
+
/** `\u0017` */ ETB: 23,
|
|
37
|
+
/** `\u0018` */ CAN: 24,
|
|
38
|
+
/** `\u0019` */ EM: 25,
|
|
39
|
+
/** `\u001a` */ SUB: 26,
|
|
40
|
+
/** `\u001b` */ ESC: 27,
|
|
41
|
+
/** `\u001c` */ FS: 28,
|
|
42
|
+
/** `\u001d` */ GS: 29,
|
|
43
|
+
/** `\u001e` */ RS: 30,
|
|
44
|
+
/** `\u001f` */ US: 31,
|
|
45
|
+
/** " " */ SPACE: 32,
|
|
46
|
+
/** `!` */ EXCLAMATION: 33,
|
|
47
|
+
/** `"` */ DOUBLE_QUOTE: 34,
|
|
48
|
+
/** `#` */ HASH: 35,
|
|
49
|
+
/** `$` */ DOLLAR: 36,
|
|
50
|
+
/** `%` */ PERCENT: 37,
|
|
51
|
+
/** `&` */ AMPERSAND: 38,
|
|
52
|
+
/** `'` */ SINGLE_QUOTE: 39,
|
|
53
|
+
/** `(` */ LEFT_PAREN: 40,
|
|
54
|
+
/** `)` */ RIGHT_PAREN: 41,
|
|
55
|
+
/** `*` */ ASTERISK: 42,
|
|
56
|
+
/** `+` */ PLUS: 43,
|
|
57
|
+
/** `,` */ COMMA: 44,
|
|
58
|
+
/** `-` */ MINUS: 45,
|
|
59
|
+
/** `.` */ PERIOD: 46,
|
|
60
|
+
/** `/` */ SLASH: 47,
|
|
61
|
+
/** `0` */ ZERO: 48,
|
|
62
|
+
/** `1` */ ONE: 49,
|
|
63
|
+
/** `2` */ TWO: 50,
|
|
64
|
+
/** `3` */ THREE: 51,
|
|
65
|
+
/** `4` */ FOUR: 52,
|
|
66
|
+
/** `5` */ FIVE: 53,
|
|
67
|
+
/** `6` */ SIX: 54,
|
|
68
|
+
/** `7` */ SEVEN: 55,
|
|
69
|
+
/** `8` */ EIGHT: 56,
|
|
70
|
+
/** `9` */ NINE: 57,
|
|
71
|
+
/** `:` */ COLON: 58,
|
|
72
|
+
/** `;` */ SEMICOLON: 59,
|
|
73
|
+
/** `<` */ LESS_THAN: 60,
|
|
74
|
+
/** `=` */ EQUAL: 61,
|
|
75
|
+
/** `>` */ GREATER_THAN: 62,
|
|
76
|
+
/** `?` */ QUESTION: 63,
|
|
77
|
+
/** `@` */ AT: 64,
|
|
78
|
+
/** `A` */ A: 65,
|
|
79
|
+
/** `B` */ B: 66,
|
|
80
|
+
/** `C` */ C: 67,
|
|
81
|
+
/** `D` */ D: 68,
|
|
82
|
+
/** `E` */ E: 69,
|
|
83
|
+
/** `F` */ F: 70,
|
|
84
|
+
/** `G` */ G: 71,
|
|
85
|
+
/** `H` */ H: 72,
|
|
86
|
+
/** `I` */ I: 73,
|
|
87
|
+
/** `J` */ J: 74,
|
|
88
|
+
/** `K` */ K: 75,
|
|
89
|
+
/** `L` */ L: 76,
|
|
90
|
+
/** `M` */ M: 77,
|
|
91
|
+
/** `N` */ N: 78,
|
|
92
|
+
/** `O` */ O: 79,
|
|
93
|
+
/** `P` */ P: 80,
|
|
94
|
+
/** `Q` */ Q: 81,
|
|
95
|
+
/** `R` */ R: 82,
|
|
96
|
+
/** `S` */ S: 83,
|
|
97
|
+
/** `T` */ T: 84,
|
|
98
|
+
/** `U` */ U: 85,
|
|
99
|
+
/** `V` */ V: 86,
|
|
100
|
+
/** `W` */ W: 87,
|
|
101
|
+
/** `X` */ X: 88,
|
|
102
|
+
/** `Y` */ Y: 89,
|
|
103
|
+
/** `Z` */ Z: 90,
|
|
104
|
+
/** `[` */ LEFT_BRACKET: 91,
|
|
105
|
+
/** `\` */ BACKSLASH: 92,
|
|
106
|
+
/** `]` */ RIGHT_BRACKET: 93,
|
|
107
|
+
/** `^` */ CARET: 94,
|
|
108
|
+
/** `_` */ UNDERSCORE: 95,
|
|
109
|
+
/** __`__ */ GRAVE: 96,
|
|
110
|
+
/** `a` */ a: 97,
|
|
111
|
+
/** `b` */ b: 98,
|
|
112
|
+
/** `c` */ c: 99,
|
|
113
|
+
/** `d` */ d: 100,
|
|
114
|
+
/** `e` */ e: 101,
|
|
115
|
+
/** `f` */ f: 102,
|
|
116
|
+
/** `g` */ g: 103,
|
|
117
|
+
/** `h` */ h: 104,
|
|
118
|
+
/** `i` */ i: 105,
|
|
119
|
+
/** `j` */ j: 106,
|
|
120
|
+
/** `k` */ k: 107,
|
|
121
|
+
/** `l` */ l: 108,
|
|
122
|
+
/** `m` */ m: 109,
|
|
123
|
+
/** `n` */ n: 110,
|
|
124
|
+
/** `o` */ o: 111,
|
|
125
|
+
/** `p` */ p: 112,
|
|
126
|
+
/** `q` */ q: 113,
|
|
127
|
+
/** `r` */ r: 114,
|
|
128
|
+
/** `s` */ s: 115,
|
|
129
|
+
/** `t` */ t: 116,
|
|
130
|
+
/** `u` */ u: 117,
|
|
131
|
+
/** `v` */ v: 118,
|
|
132
|
+
/** `w` */ w: 119,
|
|
133
|
+
/** `x` */ x: 120,
|
|
134
|
+
/** `y` */ y: 121,
|
|
135
|
+
/** `z` */ z: 122,
|
|
136
|
+
/** `{` */ LEFT_BRACE: 123,
|
|
137
|
+
/** `|` */ PIPE: 124,
|
|
138
|
+
/** `}` */ RIGHT_BRACE: 125,
|
|
139
|
+
/** `~` */ TILDE: 126,
|
|
140
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type TJsonSourceEnvelop = {
|
|
2
|
+
src: string;
|
|
3
|
+
};
|
|
4
|
+
export type TBlacketPairCode = [open: number, close: number];
|
|
5
|
+
export type TScannerFunction = (source: string, offset: number, out: TJsonSourceEnvelop) => number;
|
|
6
|
+
/**
|
|
7
|
+
* Minify JSON or JSONL text by removing JSON whitespace outside double-quoted strings.
|
|
8
|
+
*
|
|
9
|
+
* - A single top-level value is returned as minified JSON.
|
|
10
|
+
* - Multiple top-level values are returned as minified JSONL separated by `"\n"`.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} source
|
|
13
|
+
* @returns {string}
|
|
14
|
+
* @version 2.0
|
|
15
|
+
*/
|
|
16
|
+
export function jsonMinify(source: string): string;
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
3
|
+
// Copyright (C) 2026 jeffy-g <hirotom1107@gmail.com>
|
|
4
|
+
// Released under the MIT license
|
|
5
|
+
// https://opensource.org/licenses/mit-license.php
|
|
6
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
|
+
*/
|
|
8
|
+
"use strict";
|
|
9
|
+
/**
|
|
10
|
+
* @file extras/json-minify.js
|
|
11
|
+
* @version 2.3 2026/04/06 16:11:36
|
|
12
|
+
*/
|
|
13
|
+
const ccMap = require("./cc-map");
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {{ src: string }} TJsonSourceEnvelop
|
|
16
|
+
* @typedef {[ open: number, close: number ]} TBlacketPairCode
|
|
17
|
+
*/
|
|
18
|
+
/** @type {TBlacketPairCode} */
|
|
19
|
+
const array = [ ccMap.LEFT_BRACKET, ccMap.RIGHT_BRACKET];
|
|
20
|
+
/** @type {TBlacketPairCode} */
|
|
21
|
+
const object = [ ccMap.LEFT_BRACE, ccMap.RIGHT_BRACE];
|
|
22
|
+
/**
|
|
23
|
+
* ### (O)thers (M)ap
|
|
24
|
+
*
|
|
25
|
+
* @type {(0 | 1)[]}
|
|
26
|
+
*/
|
|
27
|
+
const om = Array(127).fill(0);
|
|
28
|
+
om[ccMap.DOUBLE_QUOTE] = 1;
|
|
29
|
+
om[ccMap.COMMA] = 1;
|
|
30
|
+
om[ccMap.COLON] = 1;
|
|
31
|
+
om[ccMap.LEFT_BRACKET] = 1;
|
|
32
|
+
om[ccMap.RIGHT_BRACKET] = 1;
|
|
33
|
+
om[ccMap.LEFT_BRACE] = 1;
|
|
34
|
+
om[ccMap.RIGHT_BRACE] = 1;
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {(source: string, offset: number, out: TJsonSourceEnvelop) => number} TScannerFunction
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* ### (O)thers (M)ap
|
|
40
|
+
*
|
|
41
|
+
* @type {TScannerFunction[]}
|
|
42
|
+
*/
|
|
43
|
+
const scanners = Array(127).fill(0);
|
|
44
|
+
scanners[ccMap.DOUBLE_QUOTE] = (source, offset, out) => {
|
|
45
|
+
const next = sqs(source, offset);
|
|
46
|
+
out.src += source.slice(offset, next);
|
|
47
|
+
return next;
|
|
48
|
+
};
|
|
49
|
+
scanners[ccMap.LEFT_BRACKET] = sjoCode;
|
|
50
|
+
scanners[ccMap.LEFT_BRACE] = sjoCode;
|
|
51
|
+
/**
|
|
52
|
+
* @param {string} message
|
|
53
|
+
* @param {number} offset
|
|
54
|
+
* @returns {never}
|
|
55
|
+
* @throws {SyntaxError}
|
|
56
|
+
*/
|
|
57
|
+
const throwJsonSyntaxError = (message, offset) => {
|
|
58
|
+
throw new SyntaxError(`${message}, offset=${offset}`);
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Minify JSON or JSONL text by removing JSON whitespace outside double-quoted strings.
|
|
62
|
+
*
|
|
63
|
+
* - A single top-level value is returned as minified JSON.
|
|
64
|
+
* - Multiple top-level values are returned as minified JSONL separated by `"\n"`.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} source
|
|
67
|
+
* @returns {string}
|
|
68
|
+
* @version 2.0
|
|
69
|
+
*/
|
|
70
|
+
function v25x(source) {
|
|
71
|
+
if (typeof source !== "string") {
|
|
72
|
+
throw new TypeError("jsonMinify(source): source must be a string");
|
|
73
|
+
}
|
|
74
|
+
/** @type {TJsonSourceEnvelop} */
|
|
75
|
+
const out = { src: "" };
|
|
76
|
+
const sourceLen = source.length;
|
|
77
|
+
let offset = 0;
|
|
78
|
+
let count = 0;
|
|
79
|
+
while (true) {
|
|
80
|
+
const next = skipWhitespaces(source, offset);
|
|
81
|
+
if (next >= sourceLen) {
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
if (count > 0) {
|
|
85
|
+
if (next === offset) {
|
|
86
|
+
throwJsonSyntaxError("Missing whitespace between top-level JSON values", next);
|
|
87
|
+
}
|
|
88
|
+
out.src += "\n";
|
|
89
|
+
}
|
|
90
|
+
offset = sjv(source, next, out);
|
|
91
|
+
count++;
|
|
92
|
+
}
|
|
93
|
+
return out.src;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Minify JSON or JSONL text by removing JSON whitespace outside double-quoted strings.
|
|
97
|
+
*
|
|
98
|
+
* - A single top-level value is returned as minified JSON.
|
|
99
|
+
* - Multiple top-level values are returned as minified JSONL separated by `"\n"`.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} source
|
|
102
|
+
* @returns {string}
|
|
103
|
+
* @version 2.0
|
|
104
|
+
*/
|
|
105
|
+
function v24x(source) {
|
|
106
|
+
if (typeof source !== "string") {
|
|
107
|
+
throw new TypeError("jsonMinify(source): source must be a string");
|
|
108
|
+
}
|
|
109
|
+
/** @type {TJsonSourceEnvelop} */
|
|
110
|
+
const out = { src: "" };
|
|
111
|
+
const sourceLen = source.length;
|
|
112
|
+
const scans = scanners;
|
|
113
|
+
let offset = 0;
|
|
114
|
+
let count = 0;
|
|
115
|
+
while (true) {
|
|
116
|
+
const next = skipWhitespaces(source, offset);
|
|
117
|
+
if (next >= sourceLen) {
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
if (count > 0) {
|
|
121
|
+
if (next === offset) {
|
|
122
|
+
throwJsonSyntaxError("Missing whitespace between top-level JSON values", next);
|
|
123
|
+
}
|
|
124
|
+
out.src += "\n";
|
|
125
|
+
}
|
|
126
|
+
const scanner = scans[
|
|
127
|
+
source.charCodeAt(next)
|
|
128
|
+
];
|
|
129
|
+
if (!scanner) {
|
|
130
|
+
const skiped = skipOthers(source, next);
|
|
131
|
+
out.src += source.slice(next, skiped);
|
|
132
|
+
offset = skiped;
|
|
133
|
+
} else {
|
|
134
|
+
offset = scanner(source, next, out);
|
|
135
|
+
}
|
|
136
|
+
count++;
|
|
137
|
+
}
|
|
138
|
+
return out.src;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* @param {string} source
|
|
142
|
+
* @param {number} offset
|
|
143
|
+
* @param {TJsonSourceEnvelop} out
|
|
144
|
+
* @returns {number}
|
|
145
|
+
* @remarks for node v25.x
|
|
146
|
+
*/
|
|
147
|
+
function sjv(source, offset, out) {
|
|
148
|
+
switch (source.charCodeAt(offset)) {
|
|
149
|
+
case ccMap.LEFT_BRACE:
|
|
150
|
+
case ccMap.LEFT_BRACKET: return sjoCode(source, offset, out);
|
|
151
|
+
case ccMap.DOUBLE_QUOTE: {
|
|
152
|
+
const next = sqs(source, offset);
|
|
153
|
+
out.src += source.slice(offset, next);
|
|
154
|
+
return next;
|
|
155
|
+
}
|
|
156
|
+
default: {
|
|
157
|
+
const next = skipOthers(source, offset);
|
|
158
|
+
out.src += source.slice(offset, next);
|
|
159
|
+
return next;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* (S)can (J)son (O)bject
|
|
165
|
+
*
|
|
166
|
+
* @param {string} source
|
|
167
|
+
* @param {number} offset
|
|
168
|
+
* @param {TJsonSourceEnvelop} out
|
|
169
|
+
* @returns {number}
|
|
170
|
+
* @throws {SyntaxError}
|
|
171
|
+
* @version 2.2 `charCodeAt` version
|
|
172
|
+
*/
|
|
173
|
+
function sjoCode(source, offset, out) {
|
|
174
|
+
let sourceRef = out.src, nest = 0;
|
|
175
|
+
const bracket = source[offset] === "[" ? array : object;
|
|
176
|
+
const open = bracket[0];
|
|
177
|
+
const close = bracket[1];
|
|
178
|
+
const sourceLen = source.length;
|
|
179
|
+
while (offset < sourceLen) {
|
|
180
|
+
const code = source.charCodeAt(offset++);
|
|
181
|
+
if (code <= 32 /* ccMap.SPACE */) continue;
|
|
182
|
+
if (code === 34 /* ccMap.DOUBLE_QUOTE */) {
|
|
183
|
+
const next = sqs(source, offset - 1);
|
|
184
|
+
sourceRef += source.slice(offset - 1, next);
|
|
185
|
+
offset = next;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
sourceRef += source[offset - 1];
|
|
189
|
+
if (code === open) {
|
|
190
|
+
nest++;
|
|
191
|
+
} else if (code === close) {
|
|
192
|
+
if (--nest === 0) break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
out.src = sourceRef;
|
|
196
|
+
return offset;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* @param {string} source
|
|
200
|
+
* @param {number} offset
|
|
201
|
+
* @returns {number}
|
|
202
|
+
*/
|
|
203
|
+
function skipOthers(source, offset) {
|
|
204
|
+
const sourceLen = source.length;
|
|
205
|
+
let next = offset;
|
|
206
|
+
while (next < sourceLen) {
|
|
207
|
+
const code = source.charCodeAt(next++);
|
|
208
|
+
if (
|
|
209
|
+
code <= 32 || om[code]
|
|
210
|
+
) {
|
|
211
|
+
next -= 1;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (next === offset) throwJsonSyntaxError("Invalid JSON primitive", offset);
|
|
216
|
+
return next;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* ### (S)can (Q)uoted (S)tring
|
|
220
|
+
*
|
|
221
|
+
* Scan a JSON double-quoted string and return the next offset.
|
|
222
|
+
*
|
|
223
|
+
* @param {string} source
|
|
224
|
+
* @param {number} offset
|
|
225
|
+
* @returns {number} `"` next offset
|
|
226
|
+
*/
|
|
227
|
+
function sqs(source, offset) {
|
|
228
|
+
const srcLen = source.length;
|
|
229
|
+
let next = offset + 1;
|
|
230
|
+
let inEscape = false;
|
|
231
|
+
while (next < srcLen) {
|
|
232
|
+
const code = source.charCodeAt(next++);
|
|
233
|
+
if (code === 92 /* ccMap.BACKSLASH */) {
|
|
234
|
+
inEscape = !inEscape;
|
|
235
|
+
} else if (inEscape) {
|
|
236
|
+
inEscape = false;
|
|
237
|
+
} else if (code === 34 /* ccMap.DOUBLE_QUOTE */) {
|
|
238
|
+
return next;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
throwJsonSyntaxError("Incomplete JSON string", offset);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* @param {number} code
|
|
245
|
+
* @returns {boolean}
|
|
246
|
+
*/
|
|
247
|
+
const isWhitespaceCode = (code) => code <= 32;
|
|
248
|
+
/**
|
|
249
|
+
* @param {string} source
|
|
250
|
+
* @param {number} offset
|
|
251
|
+
* @returns {number}
|
|
252
|
+
*/
|
|
253
|
+
const skipWhitespaces = (source, offset) => {
|
|
254
|
+
const srcLen = source.length;
|
|
255
|
+
while (offset < srcLen) {
|
|
256
|
+
if (!isWhitespaceCode(source.charCodeAt(offset++))) {
|
|
257
|
+
offset -= 1;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return offset;
|
|
262
|
+
};
|
|
263
|
+
const jsonMinify = process.versions.node.slice(0, 2) <= "24" ? v24x : v25x;
|
|
264
|
+
module.exports = {
|
|
265
|
+
jsonMinify,
|
|
266
|
+
};
|
package/extras/jsonl.d.ts
CHANGED
|
@@ -113,4 +113,11 @@ export function readJsonlMapByKey<TRow = any, TOut = TRow>(fileName: string, opt
|
|
|
113
113
|
*
|
|
114
114
|
* Intended for performance-sensitive hot paths where full `JSON.parse` is unnecessary.
|
|
115
115
|
*/
|
|
116
|
-
export function fastGetIntFieldCheap(line: string, key: string): number | undefined;
|
|
116
|
+
export function fastGetIntFieldCheap(line: string, key: string): number | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Minify JSON or JSONL text by removing JSON whitespace outside strings.
|
|
119
|
+
*
|
|
120
|
+
* - A single top-level value is returned as minified JSON.
|
|
121
|
+
* - Multiple top-level values are returned as minified JSONL separated by `"\n"`.
|
|
122
|
+
*/
|
|
123
|
+
export function jsonMinify(source: string): string;
|
package/extras/jsonl.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
const fs = require("fs");
|
|
13
13
|
const path = require("path");
|
|
14
|
+
const { jsonMinify } = require("./json-minify.js");
|
|
14
15
|
/**
|
|
15
16
|
* @import { TJsonlReadOption, TJsonlReadBaseOption } from "./jsonl.js";
|
|
16
17
|
*/
|
|
@@ -140,12 +141,12 @@ async function readJsonl(fileName, onRow, options = {}) {
|
|
|
140
141
|
try {
|
|
141
142
|
const row = jsonParse(line);
|
|
142
143
|
onRow(row, lineNo);
|
|
143
|
-
} catch (
|
|
144
|
+
} catch (e) {
|
|
144
145
|
if (onParseError) {
|
|
145
|
-
onParseError(
|
|
146
|
+
onParseError(e, line, lineNo);
|
|
146
147
|
return;
|
|
147
148
|
}
|
|
148
|
-
console.error("jsonl parse error:", fileName, `line=${lineNo}`,
|
|
149
|
+
console.error("jsonl parse error:", fileName, `line=${lineNo}`, e);
|
|
149
150
|
}
|
|
150
151
|
},
|
|
151
152
|
options
|
|
@@ -201,4 +202,5 @@ module.exports = {
|
|
|
201
202
|
readJsonlArray,
|
|
202
203
|
readJsonlMapByKey,
|
|
203
204
|
fastGetIntFieldCheap,
|
|
205
|
+
jsonMinify,
|
|
204
206
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
3
|
+
// Copyright (C) 2026 jeffy-g <hirotom1107@gmail.com>
|
|
4
|
+
// Released under the MIT license
|
|
5
|
+
// https://opensource.org/licenses/mit-license.php
|
|
6
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @file progress-light.d.ts
|
|
10
|
+
*/
|
|
11
|
+
export type ProgressFormatOptions = {
|
|
12
|
+
fmt: string;
|
|
13
|
+
payload?: Record<string, string>;
|
|
14
|
+
};
|
|
15
|
+
export type TProgressLight = {
|
|
16
|
+
updateOptions(newFrames?: string[], newOpt?: ProgressFormatOptions): void;
|
|
17
|
+
deadline(): void;
|
|
18
|
+
newLine(): void;
|
|
19
|
+
setFPS(fps: number): void;
|
|
20
|
+
renderSync(): void;
|
|
21
|
+
run(): void;
|
|
22
|
+
stop(): void;
|
|
23
|
+
isRunning(): boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* @param {number} [fps]
|
|
27
|
+
* @param {() => string} [messageEmitter]
|
|
28
|
+
*/
|
|
29
|
+
export function create(fps?: number, messageEmitter?: () => string): TProgressLight;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
3
|
+
Copyright (C) 2026 jeffy-g <hirotom1107@gmail.com>
|
|
4
|
+
Released under the MIT license
|
|
5
|
+
https://opensource.org/licenses/mit-license.php
|
|
6
|
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
|
+
*/
|
|
8
|
+
"use strict";
|
|
9
|
+
/**
|
|
10
|
+
* [usage]
|
|
11
|
+
* > node -i
|
|
12
|
+
* let t = require("./extras/progress-light");
|
|
13
|
+
* let p = t.create();
|
|
14
|
+
* p.run();
|
|
15
|
+
* p.stop();
|
|
16
|
+
*/
|
|
17
|
+
const rl = require("readline");
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {{ fmt: string, payload?: Record<string, string> }} ProgressFormatOptions
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {{
|
|
23
|
+
* updateOptions(newFrames?: string[], newOpt?: ProgressFormatOptions): void;
|
|
24
|
+
* deadline(): void;
|
|
25
|
+
* newLine(): void;
|
|
26
|
+
* setFPS(fps: number): void;
|
|
27
|
+
* renderSync(): void;
|
|
28
|
+
* run(): void;
|
|
29
|
+
* stop(): void;
|
|
30
|
+
* isRunning(): boolean;
|
|
31
|
+
* }} TProgressLight
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* @param {boolean} enabled
|
|
35
|
+
* @param {NodeJS.WriteStream} [output]
|
|
36
|
+
*/
|
|
37
|
+
const cursor = (enabled, output = process.stderr) => {
|
|
38
|
+
if (enabled) {
|
|
39
|
+
output.write("\x1B[?25h");
|
|
40
|
+
} else {
|
|
41
|
+
output.write("\x1B[?25l");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* @param {string=} msg
|
|
46
|
+
* @param {number=} row
|
|
47
|
+
*/
|
|
48
|
+
const renderLine = (msg, row) => {
|
|
49
|
+
const output = process.stderr || process.stdout;
|
|
50
|
+
rl.cursorTo(output, 0, row);
|
|
51
|
+
msg && (output.write(msg), rl.clearLine(output, 1));
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* @param {string[]} frames
|
|
55
|
+
* @param {ProgressFormatOptions} [formatOpt]
|
|
56
|
+
*/
|
|
57
|
+
const createProgressSync = (frames, formatOpt) => {
|
|
58
|
+
const fsize = frames.length;
|
|
59
|
+
let index = 0;
|
|
60
|
+
/** @type {string | undefined} */
|
|
61
|
+
let fmt;
|
|
62
|
+
/** @type {Record<string, string>} */
|
|
63
|
+
let payload = {};
|
|
64
|
+
/** @type {string[]} */
|
|
65
|
+
let keys = [];
|
|
66
|
+
if (formatOpt) {
|
|
67
|
+
fmt = formatOpt.fmt;
|
|
68
|
+
payload = formatOpt.payload || {};
|
|
69
|
+
keys = Object.keys(payload);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @param {string} tick
|
|
73
|
+
* @param {string} msg
|
|
74
|
+
*/
|
|
75
|
+
const formatter = (tick, msg) => {
|
|
76
|
+
if (fmt) {
|
|
77
|
+
let content = fmt;
|
|
78
|
+
for (let i = 0, end = keys.length; i < end; ) {
|
|
79
|
+
const key = keys[i++];
|
|
80
|
+
content = content.replace("{" + key + "}", payload[key]);
|
|
81
|
+
}
|
|
82
|
+
return content.replace("{tick}", tick).replace("{msg}", msg);
|
|
83
|
+
}
|
|
84
|
+
return `[${tick}]: ${msg}`;
|
|
85
|
+
};
|
|
86
|
+
return /** @type {(msg: string, done?: boolean) => void} */ ((msg, done = false) => {
|
|
87
|
+
const tick = done ? "-done-" : frames[index++ % fsize];
|
|
88
|
+
const line = msg ? formatter(tick, msg) : "";
|
|
89
|
+
renderLine(line);
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* @param {string[]} frames
|
|
94
|
+
* @param {ProgressFormatOptions} formatOpt
|
|
95
|
+
* @param {() => string} messageEmitter
|
|
96
|
+
* @returns {TProgressLight}
|
|
97
|
+
*/
|
|
98
|
+
const createProgressObject = (frames, formatOpt, messageEmitter) => {
|
|
99
|
+
let done = false;
|
|
100
|
+
const render = () => {
|
|
101
|
+
progress(messageEmitter(), done);
|
|
102
|
+
};
|
|
103
|
+
let progress = createProgressSync(frames, formatOpt);
|
|
104
|
+
/** @type {ReturnType<typeof setInterval> | undefined} */
|
|
105
|
+
let timer;
|
|
106
|
+
let ms = 33;
|
|
107
|
+
return {
|
|
108
|
+
updateOptions(newFrames, newOpt) {
|
|
109
|
+
if (Array.isArray(newFrames) && typeof newFrames[0] === "string") {
|
|
110
|
+
frames = newFrames;
|
|
111
|
+
}
|
|
112
|
+
if (typeof newOpt === "object" && newOpt && newOpt.fmt) {
|
|
113
|
+
formatOpt = newOpt;
|
|
114
|
+
}
|
|
115
|
+
done = false;
|
|
116
|
+
progress = createProgressSync(frames, formatOpt);
|
|
117
|
+
},
|
|
118
|
+
deadline() {
|
|
119
|
+
(done = true), render();
|
|
120
|
+
},
|
|
121
|
+
newLine() {
|
|
122
|
+
console.log();
|
|
123
|
+
},
|
|
124
|
+
setFPS(fps) {
|
|
125
|
+
ms = (1000 / fps) | 0;
|
|
126
|
+
if (timer) {
|
|
127
|
+
clearInterval(timer);
|
|
128
|
+
timer = setInterval(render, ms);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
renderSync() {
|
|
132
|
+
progress(messageEmitter(), done);
|
|
133
|
+
},
|
|
134
|
+
run() {
|
|
135
|
+
cursor(false);
|
|
136
|
+
done = false;
|
|
137
|
+
if (timer) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
timer = setInterval(render, ms);
|
|
141
|
+
},
|
|
142
|
+
stop() {
|
|
143
|
+
done = true;
|
|
144
|
+
clearInterval(timer);
|
|
145
|
+
timer = void 0;
|
|
146
|
+
cursor(true);
|
|
147
|
+
},
|
|
148
|
+
isRunning() {
|
|
149
|
+
return !!timer;
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
let fired = 0;
|
|
154
|
+
let pending = 0;
|
|
155
|
+
/** @type {() => { fired: number; pending: number; errors?: number; }} */
|
|
156
|
+
const cb = () => {
|
|
157
|
+
return {
|
|
158
|
+
fired: ++fired,
|
|
159
|
+
pending: ++pending,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
let tag = "progress test";
|
|
163
|
+
/**
|
|
164
|
+
* progress callback
|
|
165
|
+
* @type {() => string}
|
|
166
|
+
*/
|
|
167
|
+
const pcb = () => {
|
|
168
|
+
if (cb) {
|
|
169
|
+
const { fired, pending, errors } = cb();
|
|
170
|
+
return `${tag} | error: ${(errors + "").padEnd(3)} | send: ${(fired + "").padStart(3)}, pending: ${(pending + "").padEnd(5)}`;
|
|
171
|
+
} else {
|
|
172
|
+
return "- - error - -";
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* @param {number} [fps]
|
|
177
|
+
* @param {() => string} [messageEmitter]
|
|
178
|
+
* @returns {TProgressLight}
|
|
179
|
+
*/
|
|
180
|
+
const create = (fps = 30, messageEmitter) => {
|
|
181
|
+
const frames = [
|
|
182
|
+
"⠋",
|
|
183
|
+
"⠙",
|
|
184
|
+
"⠹",
|
|
185
|
+
"⠸",
|
|
186
|
+
"⠼",
|
|
187
|
+
"⠴",
|
|
188
|
+
"⠦",
|
|
189
|
+
"⠧",
|
|
190
|
+
"⠇",
|
|
191
|
+
"⠏",
|
|
192
|
+
];
|
|
193
|
+
!messageEmitter && (messageEmitter = pcb);
|
|
194
|
+
/** @type {TProgressLight} */
|
|
195
|
+
const progress = createProgressObject(
|
|
196
|
+
frames, {
|
|
197
|
+
fmt: "{tick} - {msg}",
|
|
198
|
+
payload: {},
|
|
199
|
+
},
|
|
200
|
+
messageEmitter,
|
|
201
|
+
);
|
|
202
|
+
progress.setFPS(fps);
|
|
203
|
+
return progress;
|
|
204
|
+
};
|
|
205
|
+
module.exports = {
|
|
206
|
+
create,
|
|
207
|
+
};
|
package/lib/unzip.min.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
/*! @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */ /*! (C) 2022 jeffy-g https://github.com/jeffy-g Released under the MIT license https://opensource.org/licenses/mit-license.php */
|
|
1
|
+
/*! @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */ /*! (C) 2022 jeffy-g https://github.com/jeffy-g Released under the MIT license https://opensource.org/licenses/mit-license.php */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
(function () {
|
|
2
4
|
var m,
|
|
3
5
|
aa = this;
|
|
4
6
|
Math.floor(2147483648 * Math.random()).toString(36);
|