ccusage 16.2.5 → 17.0.0
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 +20 -25
- package/config-schema.json +0 -33
- package/dist/_types-CV6z8-9_.js +583 -0
- package/dist/{calculate-cost-BDqO4yWA.js → calculate-cost-CX9KwEZt.js} +1 -1
- package/dist/calculate-cost.d.ts +1 -4
- package/dist/calculate-cost.js +2 -3
- package/dist/data-loader-DQtk3Va0.js +3733 -0
- package/dist/data-loader-D_hlygEz.d.ts +2307 -0
- package/dist/data-loader.d.ts +1 -2
- package/dist/data-loader.js +3 -5
- package/dist/debug-Bn_uiKiR.js +148 -0
- package/dist/debug.d.ts +8 -0
- package/dist/debug.js +4 -6
- package/dist/index.d.ts +0 -0
- package/dist/index.js +2838 -2065
- package/dist/{logger-wHijzbnK.js → logger-1M8m84B7.js} +179 -74
- package/dist/logger.d.ts +11 -7
- package/dist/logger.js +1 -1
- package/dist/{prompt-DsUFNEY7.js → prompt-BeRmYuGP.js} +49 -28
- package/package.json +4 -4
- package/dist/_token-utils-WjkbrjKv.js +0 -5
- package/dist/_types-DIdtMJ6V.js +0 -3076
- package/dist/data-loader-D1FVB4Lp.d.ts +0 -785
- package/dist/data-loader-abvRdQYo.js +0 -2681
- package/dist/debug-CkCfHFil.js +0 -109
- package/dist/mcp-Dz21qUWi.js +0 -6832
- package/dist/mcp.d.ts +0 -35
- package/dist/mcp.js +0 -8
- package/dist/pricing-fetcher-BtUY4dRM.js +0 -402
- package/dist/pricing-fetcher-DK8lcI1w.d.ts +0 -219
- package/dist/pricing-fetcher.d.ts +0 -2
- package/dist/pricing-fetcher.js +0 -4
|
@@ -17,7 +17,8 @@ const LogLevels = {
|
|
|
17
17
|
debug: 4,
|
|
18
18
|
trace: 5,
|
|
19
19
|
verbose: Number.POSITIVE_INFINITY
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
|
+
const LogTypes = {
|
|
21
22
|
silent: { level: -1 },
|
|
22
23
|
fatal: { level: LogLevels.fatal },
|
|
23
24
|
error: { level: LogLevels.error },
|
|
@@ -36,7 +37,10 @@ const LogLevels = {
|
|
|
36
37
|
function isPlainObject$1(value) {
|
|
37
38
|
if (value === null || typeof value !== "object") return false;
|
|
38
39
|
const prototype = Object.getPrototypeOf(value);
|
|
39
|
-
|
|
40
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
|
|
41
|
+
if (Symbol.iterator in value) return false;
|
|
42
|
+
if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
|
|
43
|
+
return true;
|
|
40
44
|
}
|
|
41
45
|
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
42
46
|
if (!isPlainObject$1(defaults)) return _defu(baseObject, {}, namespace, merger);
|
|
@@ -44,7 +48,8 @@ function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
|
44
48
|
for (const key in baseObject) {
|
|
45
49
|
if (key === "__proto__" || key === "constructor") continue;
|
|
46
50
|
const value = baseObject[key];
|
|
47
|
-
if (value === null || value === void 0
|
|
51
|
+
if (value === null || value === void 0) continue;
|
|
52
|
+
if (merger && merger(object, key, value, namespace)) continue;
|
|
48
53
|
if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
|
|
49
54
|
else if (isPlainObject$1(value) && isPlainObject$1(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
|
|
50
55
|
else object[key] = value;
|
|
@@ -59,7 +64,10 @@ function isPlainObject(obj) {
|
|
|
59
64
|
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
60
65
|
}
|
|
61
66
|
function isLogObj(arg) {
|
|
62
|
-
|
|
67
|
+
if (!isPlainObject(arg)) return false;
|
|
68
|
+
if (!arg.message && !arg.args) return false;
|
|
69
|
+
if (arg.stack) return false;
|
|
70
|
+
return true;
|
|
63
71
|
}
|
|
64
72
|
let paused = false;
|
|
65
73
|
const queue = [];
|
|
@@ -69,7 +77,7 @@ var Consola = class Consola {
|
|
|
69
77
|
_mockFn;
|
|
70
78
|
constructor(options = {}) {
|
|
71
79
|
const types = options.types || LogTypes;
|
|
72
|
-
|
|
80
|
+
this.options = defu({
|
|
73
81
|
...options,
|
|
74
82
|
defaults: { ...options.defaults },
|
|
75
83
|
level: _normalizeLogLevel(options.level, types),
|
|
@@ -83,13 +91,15 @@ var Consola = class Consola {
|
|
|
83
91
|
colors: false,
|
|
84
92
|
compact: true
|
|
85
93
|
}
|
|
86
|
-
})
|
|
94
|
+
});
|
|
95
|
+
for (const type in types) {
|
|
87
96
|
const defaults = {
|
|
88
97
|
type,
|
|
89
98
|
...this.options.defaults,
|
|
90
99
|
...types[type]
|
|
91
100
|
};
|
|
92
|
-
this[type] = this._wrapLogFn(defaults)
|
|
101
|
+
this[type] = this._wrapLogFn(defaults);
|
|
102
|
+
this[type].raw = this._wrapLogFn(defaults, true);
|
|
93
103
|
}
|
|
94
104
|
if (this.options.mockFn) this.mockTypes();
|
|
95
105
|
this._lastLog = {};
|
|
@@ -125,7 +135,8 @@ var Consola = class Consola {
|
|
|
125
135
|
return this.withDefaults({ tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag });
|
|
126
136
|
}
|
|
127
137
|
addReporter(reporter) {
|
|
128
|
-
|
|
138
|
+
this.options.reporters.push(reporter);
|
|
139
|
+
return this;
|
|
129
140
|
}
|
|
130
141
|
removeReporter(reporter) {
|
|
131
142
|
if (reporter) {
|
|
@@ -135,13 +146,16 @@ var Consola = class Consola {
|
|
|
135
146
|
return this;
|
|
136
147
|
}
|
|
137
148
|
setReporters(reporters) {
|
|
138
|
-
|
|
149
|
+
this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
|
|
150
|
+
return this;
|
|
139
151
|
}
|
|
140
152
|
wrapAll() {
|
|
141
|
-
this.wrapConsole()
|
|
153
|
+
this.wrapConsole();
|
|
154
|
+
this.wrapStd();
|
|
142
155
|
}
|
|
143
156
|
restoreAll() {
|
|
144
|
-
this.restoreConsole()
|
|
157
|
+
this.restoreConsole();
|
|
158
|
+
this.restoreStd();
|
|
145
159
|
}
|
|
146
160
|
wrapConsole() {
|
|
147
161
|
for (const type in this.options.types) {
|
|
@@ -150,24 +164,32 @@ var Consola = class Consola {
|
|
|
150
164
|
}
|
|
151
165
|
}
|
|
152
166
|
restoreConsole() {
|
|
153
|
-
for (const type in this.options.types) if (console["__" + type])
|
|
167
|
+
for (const type in this.options.types) if (console["__" + type]) {
|
|
168
|
+
console[type] = console["__" + type];
|
|
169
|
+
delete console["__" + type];
|
|
170
|
+
}
|
|
154
171
|
}
|
|
155
172
|
wrapStd() {
|
|
156
|
-
this._wrapStream(this.options.stdout, "log")
|
|
173
|
+
this._wrapStream(this.options.stdout, "log");
|
|
174
|
+
this._wrapStream(this.options.stderr, "log");
|
|
157
175
|
}
|
|
158
176
|
_wrapStream(stream, type) {
|
|
159
|
-
if (stream)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
177
|
+
if (!stream) return;
|
|
178
|
+
if (!stream.__write) stream.__write = stream.write;
|
|
179
|
+
stream.write = (data) => {
|
|
180
|
+
this[type].raw(String(data).trim());
|
|
181
|
+
};
|
|
165
182
|
}
|
|
166
183
|
restoreStd() {
|
|
167
|
-
this._restoreStream(this.options.stdout)
|
|
184
|
+
this._restoreStream(this.options.stdout);
|
|
185
|
+
this._restoreStream(this.options.stderr);
|
|
168
186
|
}
|
|
169
187
|
_restoreStream(stream) {
|
|
170
|
-
if (stream
|
|
188
|
+
if (!stream) return;
|
|
189
|
+
if (stream.__write) {
|
|
190
|
+
stream.write = stream.__write;
|
|
191
|
+
delete stream.__write;
|
|
192
|
+
}
|
|
171
193
|
}
|
|
172
194
|
pauseLogs() {
|
|
173
195
|
paused = true;
|
|
@@ -179,7 +201,12 @@ var Consola = class Consola {
|
|
|
179
201
|
}
|
|
180
202
|
mockTypes(mockFn) {
|
|
181
203
|
const _mockFn = mockFn || this.options.mockFn;
|
|
182
|
-
|
|
204
|
+
this._mockFn = _mockFn;
|
|
205
|
+
if (typeof _mockFn !== "function") return;
|
|
206
|
+
for (const type in this.options.types) {
|
|
207
|
+
this[type] = _mockFn(type, this.options.types[type]) || this[type];
|
|
208
|
+
this[type].raw = this[type];
|
|
209
|
+
}
|
|
183
210
|
}
|
|
184
211
|
_wrapLogFn(defaults, isRaw) {
|
|
185
212
|
return (...args) => {
|
|
@@ -205,12 +232,17 @@ var Consola = class Consola {
|
|
|
205
232
|
};
|
|
206
233
|
if (!isRaw && args.length === 1 && isLogObj(args[0])) Object.assign(logObj, args[0]);
|
|
207
234
|
else logObj.args = [...args];
|
|
208
|
-
if (logObj.message)
|
|
235
|
+
if (logObj.message) {
|
|
236
|
+
logObj.args.unshift(logObj.message);
|
|
237
|
+
delete logObj.message;
|
|
238
|
+
}
|
|
209
239
|
if (logObj.additional) {
|
|
210
240
|
if (!Array.isArray(logObj.additional)) logObj.additional = logObj.additional.split("\n");
|
|
211
|
-
logObj.args.push("\n" + logObj.additional.join("\n"))
|
|
241
|
+
logObj.args.push("\n" + logObj.additional.join("\n"));
|
|
242
|
+
delete logObj.additional;
|
|
212
243
|
}
|
|
213
|
-
logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log"
|
|
244
|
+
logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
|
|
245
|
+
logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
|
|
214
246
|
const resolveLog = (newLog = false) => {
|
|
215
247
|
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
|
216
248
|
if (this._lastLog.object && repeated > 0) {
|
|
@@ -219,20 +251,28 @@ var Consola = class Consola {
|
|
|
219
251
|
this._log({
|
|
220
252
|
...this._lastLog.object,
|
|
221
253
|
args: args2
|
|
222
|
-
})
|
|
254
|
+
});
|
|
255
|
+
this._lastLog.count = 1;
|
|
256
|
+
}
|
|
257
|
+
if (newLog) {
|
|
258
|
+
this._lastLog.object = logObj;
|
|
259
|
+
this._log(logObj);
|
|
223
260
|
}
|
|
224
|
-
if (newLog) this._lastLog.object = logObj, this._log(logObj);
|
|
225
261
|
};
|
|
226
262
|
clearTimeout(this._lastLog.timeout);
|
|
227
263
|
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
|
228
|
-
|
|
264
|
+
this._lastLog.time = logObj.date;
|
|
265
|
+
if (diffTime < this.options.throttle) try {
|
|
229
266
|
const serializedLog = JSON.stringify([
|
|
230
267
|
logObj.type,
|
|
231
268
|
logObj.tag,
|
|
232
269
|
logObj.args
|
|
233
|
-
])
|
|
234
|
-
|
|
235
|
-
|
|
270
|
+
]);
|
|
271
|
+
const isSameLog = this._lastLog.serialized === serializedLog;
|
|
272
|
+
this._lastLog.serialized = serializedLog;
|
|
273
|
+
if (isSameLog) {
|
|
274
|
+
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
|
275
|
+
if (this._lastLog.count > this.options.throttleMin) {
|
|
236
276
|
this._lastLog.timeout = setTimeout(resolveLog, this.options.throttle);
|
|
237
277
|
return;
|
|
238
278
|
}
|
|
@@ -245,19 +285,27 @@ var Consola = class Consola {
|
|
|
245
285
|
}
|
|
246
286
|
};
|
|
247
287
|
function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
288
|
+
if (input === void 0) return defaultLevel;
|
|
289
|
+
if (typeof input === "number") return input;
|
|
290
|
+
if (types[input] && types[input].level !== void 0) return types[input].level;
|
|
291
|
+
return defaultLevel;
|
|
292
|
+
}
|
|
293
|
+
Consola.prototype.add = Consola.prototype.addReporter;
|
|
294
|
+
Consola.prototype.remove = Consola.prototype.removeReporter;
|
|
295
|
+
Consola.prototype.clear = Consola.prototype.removeReporter;
|
|
296
|
+
Consola.prototype.withScope = Consola.prototype.withTag;
|
|
297
|
+
Consola.prototype.mock = Consola.prototype.mockTypes;
|
|
298
|
+
Consola.prototype.pause = Consola.prototype.pauseLogs;
|
|
299
|
+
Consola.prototype.resume = Consola.prototype.resumeLogs;
|
|
251
300
|
function createConsola(options = {}) {
|
|
252
301
|
return new Consola(options);
|
|
253
302
|
}
|
|
254
303
|
function parseStack(stack, message) {
|
|
255
|
-
const cwd = process.cwd() + sep
|
|
256
|
-
return
|
|
304
|
+
const cwd = process.cwd() + sep;
|
|
305
|
+
return stack.split("\n").splice(message.split("\n").length).map((l$1) => l$1.trim().replace("file://", "").replace(cwd, ""));
|
|
257
306
|
}
|
|
258
307
|
function writeStream(data, stream) {
|
|
259
|
-
|
|
260
|
-
return write.call(stream, data);
|
|
308
|
+
return (stream.__write || stream.write).call(stream, data);
|
|
261
309
|
}
|
|
262
310
|
const bracket = (x) => x ? `[${x}]` : "";
|
|
263
311
|
var BasicReporter = class {
|
|
@@ -267,7 +315,11 @@ var BasicReporter = class {
|
|
|
267
315
|
${indent}`);
|
|
268
316
|
}
|
|
269
317
|
formatError(err, opts) {
|
|
270
|
-
const message = err.message ?? formatWithOptions(opts, err)
|
|
318
|
+
const message = err.message ?? formatWithOptions(opts, err);
|
|
319
|
+
const stack = err.stack ? this.formatStack(err.stack, message, opts) : "";
|
|
320
|
+
const level = opts?.errorLevel || 0;
|
|
321
|
+
const causedPrefix = level > 0 ? `${" ".repeat(level)}[cause]: ` : "";
|
|
322
|
+
const causedError = err.cause ? "\n\n" + this.formatError(err.cause, {
|
|
271
323
|
...opts,
|
|
272
324
|
errorLevel: level + 1
|
|
273
325
|
}) : "";
|
|
@@ -275,7 +327,8 @@ ${indent}`);
|
|
|
275
327
|
}
|
|
276
328
|
formatArgs(args, opts) {
|
|
277
329
|
const _args = args.map((arg) => {
|
|
278
|
-
|
|
330
|
+
if (arg && typeof arg.stack === "string") return this.formatError(arg, opts);
|
|
331
|
+
return arg;
|
|
279
332
|
});
|
|
280
333
|
return formatWithOptions(opts, ..._args);
|
|
281
334
|
}
|
|
@@ -287,11 +340,12 @@ ${indent}`);
|
|
|
287
340
|
}
|
|
288
341
|
formatLogObj(logObj, opts) {
|
|
289
342
|
const message = this.formatArgs(logObj.args, opts);
|
|
290
|
-
|
|
343
|
+
if (logObj.type === "box") return "\n" + [
|
|
291
344
|
bracket(logObj.tag),
|
|
292
345
|
logObj.title && logObj.title,
|
|
293
346
|
...message.split("\n")
|
|
294
|
-
].filter(Boolean).map((l$1) => " > " + l$1).join("\n") + "\n"
|
|
347
|
+
].filter(Boolean).map((l$1) => " > " + l$1).join("\n") + "\n";
|
|
348
|
+
return this.filterAndJoin([
|
|
295
349
|
bracket(logObj.type),
|
|
296
350
|
bracket(logObj.tag),
|
|
297
351
|
message
|
|
@@ -305,7 +359,14 @@ ${indent}`);
|
|
|
305
359
|
return writeStream(line + "\n", logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout);
|
|
306
360
|
}
|
|
307
361
|
};
|
|
308
|
-
const { env = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process
|
|
362
|
+
const { env = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
|
|
363
|
+
const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
|
|
364
|
+
const isForced = "FORCE_COLOR" in env || argv.includes("--color");
|
|
365
|
+
const isWindows = platform === "win32";
|
|
366
|
+
const isDumbTerminal = env.TERM === "dumb";
|
|
367
|
+
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
|
|
368
|
+
const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
|
|
369
|
+
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
309
370
|
function replaceClose(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
|
|
310
371
|
return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
311
372
|
}
|
|
@@ -437,7 +498,8 @@ const boxStylePresets = {
|
|
|
437
498
|
h: "─",
|
|
438
499
|
v: "│"
|
|
439
500
|
}
|
|
440
|
-
}
|
|
501
|
+
};
|
|
502
|
+
const defaultStyle = {
|
|
441
503
|
borderColor: "white",
|
|
442
504
|
borderStyle: "rounded",
|
|
443
505
|
valign: "center",
|
|
@@ -453,21 +515,34 @@ function box(text, _opts = {}) {
|
|
|
453
515
|
...defaultStyle,
|
|
454
516
|
..._opts.style
|
|
455
517
|
}
|
|
456
|
-
}
|
|
518
|
+
};
|
|
519
|
+
const textLines = text.split("\n");
|
|
520
|
+
const boxLines = [];
|
|
521
|
+
const _color = getColor$1(opts.style.borderColor);
|
|
522
|
+
const borderStyle = { ...typeof opts.style.borderStyle === "string" ? boxStylePresets[opts.style.borderStyle] || boxStylePresets.solid : opts.style.borderStyle };
|
|
457
523
|
if (_color) for (const key in borderStyle) borderStyle[key] = _color(borderStyle[key]);
|
|
458
|
-
const paddingOffset = opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1
|
|
524
|
+
const paddingOffset = opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1;
|
|
525
|
+
const height = textLines.length + paddingOffset;
|
|
526
|
+
const width = Math.max(...textLines.map((line) => stripAnsi(line).length), opts.title ? stripAnsi(opts.title).length : 0) + paddingOffset;
|
|
527
|
+
const widthOffset = width + paddingOffset;
|
|
528
|
+
const leftSpace = opts.style.marginLeft > 0 ? " ".repeat(opts.style.marginLeft) : "";
|
|
459
529
|
if (opts.style.marginTop > 0) boxLines.push("".repeat(opts.style.marginTop));
|
|
460
530
|
if (opts.title) {
|
|
461
|
-
const title = _color ? _color(opts.title) : opts.title
|
|
531
|
+
const title = _color ? _color(opts.title) : opts.title;
|
|
532
|
+
const left = borderStyle.h.repeat(Math.floor((width - stripAnsi(opts.title).length) / 2));
|
|
533
|
+
const right = borderStyle.h.repeat(width - stripAnsi(opts.title).length - stripAnsi(left).length + paddingOffset);
|
|
462
534
|
boxLines.push(`${leftSpace}${borderStyle.tl}${left}${title}${right}${borderStyle.tr}`);
|
|
463
535
|
} else boxLines.push(`${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`);
|
|
464
536
|
const valignOffset = opts.style.valign === "center" ? Math.floor((height - textLines.length) / 2) : opts.style.valign === "top" ? height - textLines.length - paddingOffset : height - textLines.length;
|
|
465
537
|
for (let i$1 = 0; i$1 < height; i$1++) if (i$1 < valignOffset || i$1 >= valignOffset + textLines.length) boxLines.push(`${leftSpace}${borderStyle.v}${" ".repeat(widthOffset)}${borderStyle.v}`);
|
|
466
538
|
else {
|
|
467
|
-
const line = textLines[i$1 - valignOffset]
|
|
539
|
+
const line = textLines[i$1 - valignOffset];
|
|
540
|
+
const left = " ".repeat(paddingOffset);
|
|
541
|
+
const right = " ".repeat(width - stripAnsi(line).length);
|
|
468
542
|
boxLines.push(`${leftSpace}${borderStyle.v}${left}${line}${right}${borderStyle.v}`);
|
|
469
543
|
}
|
|
470
|
-
|
|
544
|
+
boxLines.push(`${leftSpace}${borderStyle.bl}${borderStyle.h.repeat(widthOffset)}${borderStyle.br}`);
|
|
545
|
+
if (opts.style.marginBottom > 0) boxLines.push("".repeat(opts.style.marginBottom));
|
|
471
546
|
return boxLines.join("\n");
|
|
472
547
|
}
|
|
473
548
|
const r = Object.create(null), i = (e) => globalThis.process?.env || import.meta.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (e ? r : globalThis), o = new Proxy(r, {
|
|
@@ -628,10 +703,9 @@ function G() {
|
|
|
628
703
|
const e = F.find((s$1) => s$1[0]);
|
|
629
704
|
if (e) return { name: e[1] };
|
|
630
705
|
}
|
|
631
|
-
|
|
632
|
-
P?.name;
|
|
706
|
+
G()?.name;
|
|
633
707
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
634
|
-
const
|
|
708
|
+
const pattern = [`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))`, "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
|
|
635
709
|
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
636
710
|
}
|
|
637
711
|
const regex = ansiRegex();
|
|
@@ -652,11 +726,15 @@ function validate(codePoint) {
|
|
|
652
726
|
if (!Number.isSafeInteger(codePoint)) throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
653
727
|
}
|
|
654
728
|
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
655
|
-
|
|
729
|
+
validate(codePoint);
|
|
730
|
+
if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) return 2;
|
|
731
|
+
return 1;
|
|
656
732
|
}
|
|
657
733
|
const emojiRegex = () => {
|
|
658
734
|
return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE89\uDE8F-\uDEC2\uDEC6\uDECE-\uDEDC\uDEDF-\uDEE9]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
|
|
659
|
-
}
|
|
735
|
+
};
|
|
736
|
+
const segmenter = globalThis.Intl?.Segmenter ? new Intl.Segmenter() : { segment: (str) => str.split("") };
|
|
737
|
+
const defaultIgnorableCodePointRegex = /^\p{Default_Ignorable_Code_Point}$/u;
|
|
660
738
|
function stringWidth$1(string, options = {}) {
|
|
661
739
|
if (typeof string !== "string" || string.length === 0) return 0;
|
|
662
740
|
const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options;
|
|
@@ -666,7 +744,12 @@ function stringWidth$1(string, options = {}) {
|
|
|
666
744
|
const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
|
|
667
745
|
for (const { segment: character } of segmenter.segment(string)) {
|
|
668
746
|
const codePoint = character.codePointAt(0);
|
|
669
|
-
if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159
|
|
747
|
+
if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) continue;
|
|
748
|
+
if (codePoint >= 8203 && codePoint <= 8207 || codePoint === 65279) continue;
|
|
749
|
+
if (codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071) continue;
|
|
750
|
+
if (codePoint >= 55296 && codePoint <= 57343) continue;
|
|
751
|
+
if (codePoint >= 65024 && codePoint <= 65039) continue;
|
|
752
|
+
if (defaultIgnorableCodePointRegex.test(character)) continue;
|
|
670
753
|
if (emojiRegex().test(character)) {
|
|
671
754
|
width += 2;
|
|
672
755
|
continue;
|
|
@@ -676,8 +759,10 @@ function stringWidth$1(string, options = {}) {
|
|
|
676
759
|
return width;
|
|
677
760
|
}
|
|
678
761
|
function isUnicodeSupported() {
|
|
679
|
-
const { env: env$1 } = process$1
|
|
680
|
-
|
|
762
|
+
const { env: env$1 } = process$1;
|
|
763
|
+
const { TERM, TERM_PROGRAM } = env$1;
|
|
764
|
+
if (process$1.platform !== "win32") return TERM !== "linux";
|
|
765
|
+
return Boolean(env$1.WT_SESSION) || Boolean(env$1.TERMINUS_SUBLIME) || env$1.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env$1.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
681
766
|
}
|
|
682
767
|
const TYPE_COLOR_MAP = {
|
|
683
768
|
info: "cyan",
|
|
@@ -685,10 +770,14 @@ const TYPE_COLOR_MAP = {
|
|
|
685
770
|
success: "green",
|
|
686
771
|
ready: "green",
|
|
687
772
|
start: "magenta"
|
|
688
|
-
}
|
|
773
|
+
};
|
|
774
|
+
const LEVEL_COLOR_MAP = {
|
|
689
775
|
0: "red",
|
|
690
776
|
1: "yellow"
|
|
691
|
-
}
|
|
777
|
+
};
|
|
778
|
+
const unicode = isUnicodeSupported();
|
|
779
|
+
const s = (c$1, fallback) => unicode ? c$1 : fallback;
|
|
780
|
+
const TYPE_ICONS = {
|
|
692
781
|
error: s("✖", "×"),
|
|
693
782
|
fatal: s("✖", "×"),
|
|
694
783
|
ready: s("✔", "√"),
|
|
@@ -702,8 +791,8 @@ const TYPE_COLOR_MAP = {
|
|
|
702
791
|
log: ""
|
|
703
792
|
};
|
|
704
793
|
function stringWidth(str) {
|
|
705
|
-
|
|
706
|
-
return
|
|
794
|
+
if (!(typeof Intl === "object") || !Intl.Segmenter) return stripAnsi(str).length;
|
|
795
|
+
return stringWidth$1(str);
|
|
707
796
|
}
|
|
708
797
|
var FancyReporter = class extends BasicReporter {
|
|
709
798
|
formatStack(stack, message, opts) {
|
|
@@ -724,10 +813,18 @@ ${indent}`);
|
|
|
724
813
|
title: logObj.title ? characterFormat(logObj.title) : void 0,
|
|
725
814
|
style: logObj.style
|
|
726
815
|
});
|
|
727
|
-
const date = this.formatDate(logObj.date, opts)
|
|
816
|
+
const date = this.formatDate(logObj.date, opts);
|
|
817
|
+
const coloredDate = date && colors.gray(date);
|
|
818
|
+
const isBadge = logObj.badge ?? logObj.level < 2;
|
|
819
|
+
const type = this.formatType(logObj, isBadge, opts);
|
|
820
|
+
const tag = logObj.tag ? colors.gray(logObj.tag) : "";
|
|
728
821
|
let line;
|
|
729
|
-
const left = this.filterAndJoin([type, characterFormat(message)])
|
|
730
|
-
|
|
822
|
+
const left = this.filterAndJoin([type, characterFormat(message)]);
|
|
823
|
+
const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
|
|
824
|
+
const space = (opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2;
|
|
825
|
+
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
|
|
826
|
+
line += characterFormat(additional.length > 0 ? "\n" + additional.join("\n") : "");
|
|
827
|
+
if (logObj.type === "trace") {
|
|
731
828
|
const _err = /* @__PURE__ */ new Error("Trace: " + logObj.message);
|
|
732
829
|
line += this.formatStack(_err.stack || "", _err.message);
|
|
733
830
|
}
|
|
@@ -746,26 +843,34 @@ function getBgColor(color = "bgWhite") {
|
|
|
746
843
|
function createConsola$1(options = {}) {
|
|
747
844
|
let level = _getDefaultLogLevel();
|
|
748
845
|
if (process.env.CONSOLA_LEVEL) level = Number.parseInt(process.env.CONSOLA_LEVEL) ?? level;
|
|
749
|
-
|
|
846
|
+
return createConsola({
|
|
750
847
|
level,
|
|
751
848
|
defaults: { level },
|
|
752
849
|
stdout: process.stdout,
|
|
753
850
|
stderr: process.stderr,
|
|
754
|
-
prompt: (...args) => import("./prompt-
|
|
851
|
+
prompt: (...args) => import("./prompt-BeRmYuGP.js").then((m) => m.prompt(...args)),
|
|
755
852
|
reporters: options.reporters || [options.fancy ?? !(T || R) ? new FancyReporter() : new BasicReporter()],
|
|
756
853
|
...options
|
|
757
854
|
});
|
|
758
|
-
return consola2;
|
|
759
855
|
}
|
|
760
856
|
function _getDefaultLogLevel() {
|
|
761
|
-
|
|
857
|
+
if (g) return LogLevels.debug;
|
|
858
|
+
if (R) return LogLevels.warn;
|
|
859
|
+
return LogLevels.info;
|
|
762
860
|
}
|
|
763
861
|
const consola = createConsola$1();
|
|
764
|
-
|
|
765
|
-
const logger = consola.withTag(name);
|
|
766
|
-
if (process$1.env.LOG_LEVEL != null) {
|
|
767
|
-
|
|
768
|
-
|
|
862
|
+
function createLogger(name$1) {
|
|
863
|
+
const logger$1 = consola.withTag(name$1);
|
|
864
|
+
if (process$1.env.LOG_LEVEL != null) {
|
|
865
|
+
const level = Number.parseInt(process$1.env.LOG_LEVEL, 10);
|
|
866
|
+
if (!Number.isNaN(level)) logger$1.level = level;
|
|
867
|
+
}
|
|
868
|
+
return logger$1;
|
|
769
869
|
}
|
|
770
870
|
const log = console.log;
|
|
771
|
-
|
|
871
|
+
var name = "ccusage";
|
|
872
|
+
var version = "17.0.0";
|
|
873
|
+
var description = "Usage analysis tool for Claude Code";
|
|
874
|
+
const logger = createLogger(name);
|
|
875
|
+
const log$1 = log;
|
|
876
|
+
export { description, log$1 as log, logger, name, version };
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as consola0 from "consola";
|
|
2
2
|
|
|
3
3
|
//#region src/logger.d.ts
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview Logging utilities for the ccusage application
|
|
7
|
+
*
|
|
8
|
+
* This module provides configured logger instances using consola for consistent
|
|
9
|
+
* logging throughout the application with package name tagging.
|
|
10
|
+
*
|
|
11
|
+
* @module logger
|
|
12
|
+
*/
|
|
5
13
|
/**
|
|
6
14
|
* Application logger instance with package name tag
|
|
7
15
|
*/
|
|
8
|
-
declare const logger: ConsolaInstance;
|
|
16
|
+
declare const logger: consola0.ConsolaInstance;
|
|
9
17
|
/**
|
|
10
18
|
* Direct console.log function for cases where logger formatting is not desired
|
|
11
19
|
*/
|
|
12
|
-
|
|
13
|
-
declare const log: {
|
|
14
|
-
(...data: any[]): void;
|
|
15
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
16
|
-
};
|
|
20
|
+
declare const log: (message?: any, ...optionalParams: any[]) => void;
|
|
17
21
|
//#endregion
|
|
18
22
|
export { log, logger };
|
package/dist/logger.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { log, logger } from "./logger-
|
|
1
|
+
import { log, logger } from "./logger-1M8m84B7.js";
|
|
2
2
|
export { log, logger };
|