@poe-platform/safe-bash 0.1.745 → 0.1.747
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 +5 -1
- package/dist/image-ast/browser/sharp.d.ts +1 -1
- package/dist/image-ast/index.js +133 -35
- package/dist/image-ast/sharp.d.ts +1 -1
- package/dist/safe-bash/chunks/{chunk-2F7Q532M.js → chunk-4GK4FAT6.js} +3 -3
- package/dist/safe-bash/chunks/{chunk-EAUCLWEZ.js → chunk-55AGFLG5.js} +540 -284
- package/dist/safe-bash/chunks/{chunk-WCNFCN2G.js → chunk-BS6QFRNX.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-IZZ7KX4E.js → chunk-JCXAGOEK.js} +40 -3
- package/dist/safe-bash/chunks/{chunk-I3DOFJSJ.js → chunk-MUWJPSGN.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-7RP6WOWK.js → chunk-OF2PDE3W.js} +2 -2
- package/dist/safe-bash/chunks/{src-FTMTU65U.js → src-T672TQJC.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-DRCPJVZF.js → chunk-44N2IRVP.js} +17 -5
- package/dist/safe-bash/command-chunks/{chunk-LYKC7WJB.js → chunk-6742OVAC.js} +37 -3
- package/dist/safe-bash/command-chunks/{chunk-BMBXSLVX.js → chunk-6QU5OLPJ.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-YHANNN7I.js → chunk-S3BO2NJT.js} +7 -0
- package/dist/safe-bash/commands/basic.d.ts +2 -0
- package/dist/safe-bash/commands/basic.js +236 -9
- package/dist/safe-bash/commands/pr/index.browser.js +1 -1
- package/dist/safe-bash/commands/streams.js +9 -56
- package/dist/safe-bash/commands/table-text/index.js +5 -1
- package/dist/safe-bash/commands/text.js +13 -2
- package/dist/safe-bash/commands/time-env/shared.js +2 -2
- package/dist/safe-bash/commands/time-env/sleep.js +6 -4
- package/dist/safe-bash/commands/timeout/index.d.ts +7 -0
- package/dist/safe-bash/commands/timeout/index.js +52 -32
- package/dist/safe-bash/commands/timeout/scheduler.js +7 -6
- package/dist/safe-bash/core.browser.js +2698 -543
- package/dist/safe-bash/opt-in/commands/shuf/random.js +2 -3
- package/dist/safe-bash/opt-in/shell/extensions/read/index.js +1 -1
- package/dist/safe-bash/opt-in/shell/extensions/trap/index.d.ts +1 -2
- package/dist/safe-bash/opt-in/shell/extensions/trap/index.js +1 -8
- package/dist/safe-bash/playwright/adapter.d.ts +2 -0
- package/dist/safe-bash/playwright/private-target-transport.d.ts +1 -0
- package/dist/safe-bash/playwright/private-target-transport.js +21 -21
- package/dist/safe-bash/shell/runtime.d.ts +20 -1
- package/dist/safe-bash/shell/runtime.js +3021 -532
- package/dist/safe-bash/shell/sync-jq-expression.d.ts +6 -0
- package/dist/safe-bash/shell/sync-jq-expression.js +46 -0
- package/dist/safe-bash-command-cal/index.js +32 -12
- package/dist/safe-bash-command-hostname/index.js +22 -7
- package/dist/safe-bash-command-id/index.js +28 -9
- package/dist/safe-bash-command-pandoc/command.js +1 -1
- package/dist/safe-bash-command-pandoc/index.js +1 -1
- package/dist/safe-bash-command-ssconvert/command.d.ts +2 -2
- package/dist/safe-bash-command-ssconvert/contracts.d.ts +4 -0
- package/dist/safe-bash-command-ssconvert/engine.d.ts +2 -2
- package/dist/safe-bash-command-ssconvert/index.js +524 -276
- package/dist/safe-bash-command-whoami/index.js +26 -12
- package/dist/safe-bash-query-engine/index.js +3 -3
- package/dist/safe-bash-query-engine/interpreter.js +1 -1
- package/dist/safe-bash-query-engine/parser.js +1 -1
- package/dist/safe-bash-query-engine/query-core.js +3 -3
- package/dist/safe-playwright-cloudflare/browser-private-transport.js +8 -13
- package/dist/safe-playwright-cloudflare/browser-storage-control.js +13 -4
- package/dist/safe-playwright-cloudflare/browser-trace-archive.js +1 -1
- package/package.json +18 -14
- package/dist/image-ast/streams/node.d.ts +0 -10
- package/dist/image-ast/streams/node.js +0 -5
- package/dist/image-ast/streams/web.js +0 -94
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
Interpreter,
|
|
14
14
|
parse
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-JCXAGOEK.js";
|
|
16
16
|
import {
|
|
17
17
|
Budget,
|
|
18
18
|
Decimal,
|
|
@@ -2879,4 +2879,4 @@ export {
|
|
|
2879
2879
|
createYqCommands,
|
|
2880
2880
|
yqCommands
|
|
2881
2881
|
};
|
|
2882
|
-
//# sourceMappingURL=chunk-
|
|
2882
|
+
//# sourceMappingURL=chunk-BS6QFRNX.js.map
|
|
@@ -3849,8 +3849,38 @@ var Interpreter = class _Interpreter {
|
|
|
3849
3849
|
}
|
|
3850
3850
|
return;
|
|
3851
3851
|
}
|
|
3852
|
-
if (name === "indices") {
|
|
3853
|
-
for await (const value of this.run(args[0], input))
|
|
3852
|
+
if (name === "indices" || name === "index" || name === "rindex") {
|
|
3853
|
+
for await (const value of this.run(args[0], input)) {
|
|
3854
|
+
const found = await indices(input, value, budget);
|
|
3855
|
+
if (name === "indices") yield found;
|
|
3856
|
+
else yield indexValue(found, name === "index" ? 0 : -1);
|
|
3857
|
+
}
|
|
3858
|
+
return;
|
|
3859
|
+
}
|
|
3860
|
+
if (name === "floor" || name === "ceil" || name === "round" || name === "abs") {
|
|
3861
|
+
if (!isNumber(input)) throw new JqError(`${describe(input, budget)} cannot be ${name}ed`);
|
|
3862
|
+
budget.step();
|
|
3863
|
+
const n = numberValue(input);
|
|
3864
|
+
yield name === "floor" ? Math.floor(n) : name === "ceil" ? Math.ceil(n) : name === "round" ? Math.round(n) : Math.abs(n);
|
|
3865
|
+
return;
|
|
3866
|
+
}
|
|
3867
|
+
if (name === "implode") {
|
|
3868
|
+
if (!Array.isArray(input)) throw new JqError("implode input must be an array");
|
|
3869
|
+
let out = "";
|
|
3870
|
+
for (let i = 0; i < input.length; i++) {
|
|
3871
|
+
{
|
|
3872
|
+
const _p = budget.tickSync();
|
|
3873
|
+
if (_p) await _p;
|
|
3874
|
+
}
|
|
3875
|
+
const el = input[i];
|
|
3876
|
+
const cp = isNumber(el) ? numberValue(el) : NaN;
|
|
3877
|
+
if (!Number.isInteger(cp) || cp < 0 || cp > 1114111) {
|
|
3878
|
+
throw new JqError("implode elements must be Unicode codepoints");
|
|
3879
|
+
}
|
|
3880
|
+
out += String.fromCodePoint(cp);
|
|
3881
|
+
}
|
|
3882
|
+
budget.value(out);
|
|
3883
|
+
yield out;
|
|
3854
3884
|
return;
|
|
3855
3885
|
}
|
|
3856
3886
|
if (["startswith", "endswith", "ltrimstr", "rtrimstr"].includes(name)) {
|
|
@@ -4459,7 +4489,14 @@ var precedence = Object.freeze({
|
|
|
4459
4489
|
var functions = Object.freeze({
|
|
4460
4490
|
walk: [1],
|
|
4461
4491
|
explode: [0],
|
|
4492
|
+
implode: [0],
|
|
4462
4493
|
utf8bytelength: [0],
|
|
4494
|
+
floor: [0],
|
|
4495
|
+
ceil: [0],
|
|
4496
|
+
round: [0],
|
|
4497
|
+
abs: [0],
|
|
4498
|
+
index: [1],
|
|
4499
|
+
rindex: [1],
|
|
4463
4500
|
while: [2],
|
|
4464
4501
|
until: [2],
|
|
4465
4502
|
fromdateiso8601: [0],
|
|
@@ -5107,4 +5144,4 @@ export {
|
|
|
5107
5144
|
moduleProgram,
|
|
5108
5145
|
parse
|
|
5109
5146
|
};
|
|
5110
|
-
//# sourceMappingURL=chunk-
|
|
5147
|
+
//# sourceMappingURL=chunk-JCXAGOEK.js.map
|
|
@@ -1438,8 +1438,8 @@ function settings2(options) {
|
|
|
1438
1438
|
if (value !== Infinity && (!Number.isSafeInteger(value) || value < 1)) throw new RangeError(`Invalid time-env limit: ${name}`);
|
|
1439
1439
|
}
|
|
1440
1440
|
const maxTimerMilliseconds = options.maxTimerMilliseconds ?? 2147483647;
|
|
1441
|
-
if (!Number.isInteger(maxTimerMilliseconds) || maxTimerMilliseconds < 1 || maxTimerMilliseconds > 2147483647) {
|
|
1442
|
-
throw new RangeError("maxTimerMilliseconds must be
|
|
1441
|
+
if (maxTimerMilliseconds !== Infinity && (!Number.isInteger(maxTimerMilliseconds) || maxTimerMilliseconds < 1 || maxTimerMilliseconds > 2147483647)) {
|
|
1442
|
+
throw new RangeError("maxTimerMilliseconds must be between 1 and 2147483647 or Infinity");
|
|
1443
1443
|
}
|
|
1444
1444
|
const scheduler = options.scheduler ?? {
|
|
1445
1445
|
now: () => performance.now(),
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
tryProcessFlatJsonChunkSync,
|
|
12
12
|
tryProcessFlatSelectProjectChunkSync,
|
|
13
13
|
tryWriteCompactSync
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-JCXAGOEK.js";
|
|
15
15
|
import {
|
|
16
16
|
Budget,
|
|
17
17
|
JqError,
|
|
@@ -2530,4 +2530,4 @@ export {
|
|
|
2530
2530
|
createXmlCommands,
|
|
2531
2531
|
xmlCommands
|
|
2532
2532
|
};
|
|
2533
|
-
//# sourceMappingURL=chunk-
|
|
2533
|
+
//# sourceMappingURL=chunk-OF2PDE3W.js.map
|
|
@@ -81,7 +81,7 @@ import {
|
|
|
81
81
|
updateWorkbook,
|
|
82
82
|
validSheetSize,
|
|
83
83
|
visitFormula
|
|
84
|
-
} from "./chunk-
|
|
84
|
+
} from "./chunk-55AGFLG5.js";
|
|
85
85
|
import "./chunk-CVAVQZSF.js";
|
|
86
86
|
import "./chunk-RCM5PZBN.js";
|
|
87
87
|
import "./chunk-LSRHLNCR.js";
|
|
@@ -171,4 +171,4 @@ export {
|
|
|
171
171
|
validSheetSize,
|
|
172
172
|
visitFormula
|
|
173
173
|
};
|
|
174
|
-
//# sourceMappingURL=src-
|
|
174
|
+
//# sourceMappingURL=src-T672TQJC.js.map
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
init_buffer
|
|
32
32
|
} from "./chunk-OWQEVNXV.js";
|
|
33
33
|
|
|
34
|
-
// packages/safe-bash-command-pandoc/dist/chunks/chunk-
|
|
34
|
+
// packages/safe-bash-command-pandoc/dist/chunks/chunk-IGDCQRP5.js
|
|
35
35
|
init_buffer();
|
|
36
36
|
import * as gfm_syntax_star from "../../safe-bash-markdown-engine/gfm-syntax.js";
|
|
37
37
|
import * as commonmark_blocks_star from "../../safe-bash-markdown-engine/commonmark-blocks.js";
|
|
@@ -919,7 +919,7 @@ async function renderPdf(document, context = {}) {
|
|
|
919
919
|
return bytes;
|
|
920
920
|
}
|
|
921
921
|
|
|
922
|
-
// packages/safe-bash-command-pandoc/dist/chunks/chunk-
|
|
922
|
+
// packages/safe-bash-command-pandoc/dist/chunks/chunk-IGDCQRP5.js
|
|
923
923
|
import { hasYieldCheckpoint, runYieldCheckpoint, yieldTurn } from "../../safe-bash-contracts/yield.js";
|
|
924
924
|
import { dirname } from "@poe-platform/safe-fs/core";
|
|
925
925
|
import { createOutputOperation, getCommandArguments, readBytes, FsError } from "../../safe-bash-contracts/index.js";
|
|
@@ -22874,10 +22874,22 @@ function createPandocCommand(options = {}, hasCommand) {
|
|
|
22874
22874
|
if (matchedExt) return matchedExt;
|
|
22875
22875
|
if (!["python3", "python", "node", "sh", "bash"].some((candidate) => hasCommand(candidate))) return void 0;
|
|
22876
22876
|
try {
|
|
22877
|
-
const
|
|
22878
|
-
const
|
|
22877
|
+
const bound = Math.min(limits.resourceBytes ?? defaultLimits.resourceBytes, maxBytes);
|
|
22878
|
+
const head2 = await (stdout ?? invocation).acquire(() => context.fs.readFile(
|
|
22879
|
+
pathOf(context, filterPath),
|
|
22880
|
+
Number.isFinite(bound) ? { signal: readSignal, maxBytes: bound } : { signal: readSignal }
|
|
22881
|
+
), () => {
|
|
22882
|
+
});
|
|
22883
|
+
total += head2.byteLength;
|
|
22884
|
+
context.inputBudget?.check(total);
|
|
22885
|
+
const shebangCmd = parseShebangCommand(head2.subarray(0, 256));
|
|
22879
22886
|
if (shebangCmd && hasCommand(shebangCmd)) return shebangCmd;
|
|
22880
|
-
} catch {
|
|
22887
|
+
} catch (error) {
|
|
22888
|
+
readSignal.throwIfAborted();
|
|
22889
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
22890
|
+
await (stdout ?? invocation).abort(error);
|
|
22891
|
+
throw error;
|
|
22892
|
+
}
|
|
22881
22893
|
return void 0;
|
|
22882
22894
|
}
|
|
22883
22895
|
return void 0;
|
|
@@ -1511,9 +1511,43 @@ var Interpreter = class _Interpreter {
|
|
|
1511
1511
|
}
|
|
1512
1512
|
return;
|
|
1513
1513
|
}
|
|
1514
|
-
if (name === "indices") {
|
|
1515
|
-
for await (const value of this.run(args[0], input))
|
|
1516
|
-
|
|
1514
|
+
if (name === "indices" || name === "index" || name === "rindex") {
|
|
1515
|
+
for await (const value of this.run(args[0], input)) {
|
|
1516
|
+
const found = await indices(input, value, budget);
|
|
1517
|
+
if (name === "indices")
|
|
1518
|
+
yield found;
|
|
1519
|
+
else
|
|
1520
|
+
yield indexValue(found, name === "index" ? 0 : -1);
|
|
1521
|
+
}
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
if (name === "floor" || name === "ceil" || name === "round" || name === "abs") {
|
|
1525
|
+
if (!isNumber(input))
|
|
1526
|
+
throw new JqError(`${describe(input, budget)} cannot be ${name}ed`);
|
|
1527
|
+
budget.step();
|
|
1528
|
+
const n = numberValue(input);
|
|
1529
|
+
yield name === "floor" ? Math.floor(n) : name === "ceil" ? Math.ceil(n) : name === "round" ? Math.round(n) : Math.abs(n);
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
if (name === "implode") {
|
|
1533
|
+
if (!Array.isArray(input))
|
|
1534
|
+
throw new JqError("implode input must be an array");
|
|
1535
|
+
let out = "";
|
|
1536
|
+
for (let i = 0; i < input.length; i++) {
|
|
1537
|
+
{
|
|
1538
|
+
const _p = budget.tickSync();
|
|
1539
|
+
if (_p)
|
|
1540
|
+
await _p;
|
|
1541
|
+
}
|
|
1542
|
+
const el = input[i];
|
|
1543
|
+
const cp = isNumber(el) ? numberValue(el) : NaN;
|
|
1544
|
+
if (!Number.isInteger(cp) || cp < 0 || cp > 1114111) {
|
|
1545
|
+
throw new JqError("implode elements must be Unicode codepoints");
|
|
1546
|
+
}
|
|
1547
|
+
out += String.fromCodePoint(cp);
|
|
1548
|
+
}
|
|
1549
|
+
budget.value(out);
|
|
1550
|
+
yield out;
|
|
1517
1551
|
return;
|
|
1518
1552
|
}
|
|
1519
1553
|
if (["startswith", "endswith", "ltrimstr", "rtrimstr"].includes(name)) {
|
|
@@ -44,7 +44,14 @@ var precedence = Object.freeze({
|
|
|
44
44
|
var functions = Object.freeze({
|
|
45
45
|
walk: [1],
|
|
46
46
|
explode: [0],
|
|
47
|
+
implode: [0],
|
|
47
48
|
utf8bytelength: [0],
|
|
49
|
+
floor: [0],
|
|
50
|
+
ceil: [0],
|
|
51
|
+
round: [0],
|
|
52
|
+
abs: [0],
|
|
53
|
+
index: [1],
|
|
54
|
+
rindex: [1],
|
|
48
55
|
while: [2],
|
|
49
56
|
until: [2],
|
|
50
57
|
fromdateiso8601: [0],
|
|
@@ -3,5 +3,7 @@ export declare const defaultEchoExecutors: WeakSet<CommandHandler>;
|
|
|
3
3
|
export declare function basicCommands(): CommandDefinition[];
|
|
4
4
|
export declare function formatPrintf(context: CommandContext): Promise<CommandResult>;
|
|
5
5
|
export declare function tryFastPrintf(args: readonly string[]): string | undefined;
|
|
6
|
+
export type FastPrintfSpecKind = "s" | "s_prec" | "c" | "d" | "u";
|
|
7
|
+
export declare function extractFastPrintfSpecifiers(format: string): readonly FastPrintfSpecKind[] | undefined;
|
|
6
8
|
export declare const printfCommand: CommandDefinition;
|
|
7
9
|
//# sourceMappingURL=basic.d.ts.map
|
|
@@ -8,6 +8,7 @@ import { printfHex } from "./printf-hex.js";
|
|
|
8
8
|
import { parsePrintfFloat } from "./printf-float.js";
|
|
9
9
|
import { printfDecimal } from "./printf-decimal.js";
|
|
10
10
|
import { parsePrintfDirective } from "./printf-format.js";
|
|
11
|
+
const utf8Encoder = new TextEncoder();
|
|
11
12
|
export const defaultEchoExecutors = new WeakSet();
|
|
12
13
|
export function basicCommands() {
|
|
13
14
|
return [
|
|
@@ -94,7 +95,7 @@ export function basicCommands() {
|
|
|
94
95
|
await output(context, result + (parsed.flags.has("z") ? "\0" : "\n"));
|
|
95
96
|
}
|
|
96
97
|
return { exitCode: 0 };
|
|
97
|
-
}),
|
|
98
|
+
}, 1, 1),
|
|
98
99
|
define("dirname", async (context) => {
|
|
99
100
|
const parsed = options(context.args, "z", { zero: "z" });
|
|
100
101
|
requireOperands(parsed.operands);
|
|
@@ -106,7 +107,7 @@ export function basicCommands() {
|
|
|
106
107
|
await output(context, parent.slice(0, end) + (parsed.flags.has("z") ? "\0" : "\n"));
|
|
107
108
|
}
|
|
108
109
|
return { exitCode: 0 };
|
|
109
|
-
}),
|
|
110
|
+
}, 1, 1),
|
|
110
111
|
printfCommand,
|
|
111
112
|
].map(command => {
|
|
112
113
|
if (command.name === "echo")
|
|
@@ -355,6 +356,75 @@ export function tryFastPrintf(args) {
|
|
|
355
356
|
offset += 2;
|
|
356
357
|
continue;
|
|
357
358
|
}
|
|
359
|
+
if (next === 97) {
|
|
360
|
+
result += "\x07";
|
|
361
|
+
offset += 2;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (next === 98) {
|
|
365
|
+
result += "\b";
|
|
366
|
+
offset += 2;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (next === 102) {
|
|
370
|
+
result += "\f";
|
|
371
|
+
offset += 2;
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
if (next === 118) {
|
|
375
|
+
result += "\v";
|
|
376
|
+
offset += 2;
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (next === 101 || next === 69) {
|
|
380
|
+
result += "\x1b";
|
|
381
|
+
offset += 2;
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (next === 34) {
|
|
385
|
+
result += "\"";
|
|
386
|
+
offset += 2;
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (next === 39) {
|
|
390
|
+
result += "'";
|
|
391
|
+
offset += 2;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (next >= 48 && next <= 55) {
|
|
395
|
+
let cur = offset + 1;
|
|
396
|
+
const end = Math.min(format.length, cur + 3);
|
|
397
|
+
let val = 0;
|
|
398
|
+
while (cur < end && format.charCodeAt(cur) >= 48 && format.charCodeAt(cur) <= 55) {
|
|
399
|
+
val = val * 8 + (format.charCodeAt(cur++) - 48);
|
|
400
|
+
}
|
|
401
|
+
const byte = val & 255;
|
|
402
|
+
if (byte === 0 || byte >= 128)
|
|
403
|
+
return undefined;
|
|
404
|
+
result += String.fromCharCode(byte);
|
|
405
|
+
offset = cur;
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (next === 120) {
|
|
409
|
+
let cur = offset + 2;
|
|
410
|
+
const end = Math.min(format.length, cur + 2);
|
|
411
|
+
let val = 0;
|
|
412
|
+
let digits = 0;
|
|
413
|
+
while (cur < end) {
|
|
414
|
+
const d = format.charCodeAt(cur);
|
|
415
|
+
const n = d >= 48 && d <= 57 ? d - 48 : d >= 65 && d <= 70 ? d - 55 : d >= 97 && d <= 102 ? d - 87 : -1;
|
|
416
|
+
if (n < 0)
|
|
417
|
+
break;
|
|
418
|
+
val = val * 16 + n;
|
|
419
|
+
digits++;
|
|
420
|
+
cur++;
|
|
421
|
+
}
|
|
422
|
+
if (digits === 0 || val === 0 || val >= 128)
|
|
423
|
+
return undefined;
|
|
424
|
+
result += String.fromCharCode(val);
|
|
425
|
+
offset = cur;
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
358
428
|
return undefined;
|
|
359
429
|
}
|
|
360
430
|
if (ch !== 37) {
|
|
@@ -422,15 +492,31 @@ export function tryFastPrintf(args) {
|
|
|
422
492
|
const rawVal = args[argument++] ?? "";
|
|
423
493
|
if (rawVal.includes("\0"))
|
|
424
494
|
return undefined;
|
|
425
|
-
|
|
495
|
+
let val = rawVal;
|
|
496
|
+
let valByteLen = rawVal.length;
|
|
426
497
|
if (precision >= 0 || width > 0) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
498
|
+
let isAscii = true;
|
|
499
|
+
for (let i = 0; i < rawVal.length; i++) {
|
|
500
|
+
if (rawVal.charCodeAt(i) >= 128) {
|
|
501
|
+
isAscii = false;
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (isAscii) {
|
|
506
|
+
if (precision >= 0 && precision < rawVal.length) {
|
|
507
|
+
val = rawVal.slice(0, precision);
|
|
508
|
+
valByteLen = val.length;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
else if (precision < 0) {
|
|
512
|
+
valByteLen = utf8Encoder.encode(rawVal).byteLength;
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
return undefined;
|
|
516
|
+
}
|
|
430
517
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
const pad = " ".repeat(width - val.length);
|
|
518
|
+
if (width > valByteLen) {
|
|
519
|
+
const pad = " ".repeat(width - valByteLen);
|
|
434
520
|
result += leftAlign ? val + pad : pad + val;
|
|
435
521
|
}
|
|
436
522
|
else {
|
|
@@ -439,6 +525,24 @@ export function tryFastPrintf(args) {
|
|
|
439
525
|
offset = cur + 1;
|
|
440
526
|
continue;
|
|
441
527
|
}
|
|
528
|
+
if (conv === 99 && !zeroPad) {
|
|
529
|
+
const rawVal = args[argument++] ?? "";
|
|
530
|
+
if (rawVal.length === 0)
|
|
531
|
+
return undefined;
|
|
532
|
+
const c0 = rawVal.charCodeAt(0);
|
|
533
|
+
if (c0 === 0 || c0 >= 128)
|
|
534
|
+
return undefined;
|
|
535
|
+
const ch0 = rawVal[0];
|
|
536
|
+
if (width > 1) {
|
|
537
|
+
const pad = " ".repeat(width - 1);
|
|
538
|
+
result += leftAlign ? ch0 + pad : pad + ch0;
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
result += ch0;
|
|
542
|
+
}
|
|
543
|
+
offset = cur + 1;
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
442
546
|
if (conv === 100 || conv === 105) {
|
|
443
547
|
const rawVal = args[argument++] ?? "0";
|
|
444
548
|
const val = rawVal.length === 0 ? "0" : rawVal;
|
|
@@ -536,5 +640,128 @@ export function tryFastPrintf(args) {
|
|
|
536
640
|
} while (argument < args.length);
|
|
537
641
|
return result;
|
|
538
642
|
}
|
|
643
|
+
export function extractFastPrintfSpecifiers(format) {
|
|
644
|
+
if (format.length > 256)
|
|
645
|
+
return undefined;
|
|
646
|
+
const specs = [];
|
|
647
|
+
for (let offset = 0; offset < format.length;) {
|
|
648
|
+
const ch = format.charCodeAt(offset);
|
|
649
|
+
if (ch === 92) {
|
|
650
|
+
const next = format.charCodeAt(offset + 1);
|
|
651
|
+
if (next === 110 || next === 116 || next === 114 || next === 92 ||
|
|
652
|
+
next === 97 || next === 98 || next === 102 || next === 118 ||
|
|
653
|
+
next === 101 || next === 69 || next === 34 || next === 39) {
|
|
654
|
+
offset += 2;
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
if (next >= 48 && next <= 55) {
|
|
658
|
+
let cur = offset + 1;
|
|
659
|
+
const end = Math.min(format.length, cur + 3);
|
|
660
|
+
let val = 0;
|
|
661
|
+
while (cur < end && format.charCodeAt(cur) >= 48 && format.charCodeAt(cur) <= 55) {
|
|
662
|
+
val = val * 8 + (format.charCodeAt(cur++) - 48);
|
|
663
|
+
}
|
|
664
|
+
if ((val & 255) === 0 || (val & 255) >= 128)
|
|
665
|
+
return undefined;
|
|
666
|
+
offset = cur;
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
if (next === 120) {
|
|
670
|
+
let cur = offset + 2;
|
|
671
|
+
const end = Math.min(format.length, cur + 2);
|
|
672
|
+
let val = 0;
|
|
673
|
+
let digits = 0;
|
|
674
|
+
while (cur < end) {
|
|
675
|
+
const d = format.charCodeAt(cur);
|
|
676
|
+
const n = d >= 48 && d <= 57 ? d - 48 : d >= 65 && d <= 70 ? d - 55 : d >= 97 && d <= 102 ? d - 87 : -1;
|
|
677
|
+
if (n < 0)
|
|
678
|
+
break;
|
|
679
|
+
val = val * 16 + n;
|
|
680
|
+
digits++;
|
|
681
|
+
cur++;
|
|
682
|
+
}
|
|
683
|
+
if (digits === 0 || val === 0 || val >= 128)
|
|
684
|
+
return undefined;
|
|
685
|
+
offset = cur;
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
return undefined;
|
|
689
|
+
}
|
|
690
|
+
if (ch !== 37) {
|
|
691
|
+
offset++;
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
const spec = format.charCodeAt(offset + 1);
|
|
695
|
+
if (spec === 37) {
|
|
696
|
+
offset += 2;
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
let cur = offset + 1;
|
|
700
|
+
let leftAlign = false;
|
|
701
|
+
let zeroPad = false;
|
|
702
|
+
while (cur < format.length) {
|
|
703
|
+
const fc = format.charCodeAt(cur);
|
|
704
|
+
if (fc === 45) {
|
|
705
|
+
leftAlign = true;
|
|
706
|
+
cur++;
|
|
707
|
+
}
|
|
708
|
+
else if (fc === 48) {
|
|
709
|
+
zeroPad = true;
|
|
710
|
+
cur++;
|
|
711
|
+
}
|
|
712
|
+
else
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
if (leftAlign)
|
|
716
|
+
zeroPad = false;
|
|
717
|
+
let width = 0;
|
|
718
|
+
while (cur < format.length) {
|
|
719
|
+
const dc = format.charCodeAt(cur);
|
|
720
|
+
if (dc < 48 || dc > 57)
|
|
721
|
+
break;
|
|
722
|
+
width = width * 10 + (dc - 48);
|
|
723
|
+
if (width > 128)
|
|
724
|
+
return undefined;
|
|
725
|
+
cur++;
|
|
726
|
+
}
|
|
727
|
+
let precision = -1;
|
|
728
|
+
if (format.charCodeAt(cur) === 46) {
|
|
729
|
+
cur++;
|
|
730
|
+
precision = 0;
|
|
731
|
+
while (cur < format.length) {
|
|
732
|
+
const dc = format.charCodeAt(cur);
|
|
733
|
+
if (dc < 48 || dc > 57)
|
|
734
|
+
break;
|
|
735
|
+
precision = precision * 10 + (dc - 48);
|
|
736
|
+
if (precision > 128)
|
|
737
|
+
return undefined;
|
|
738
|
+
cur++;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
const conv = format.charCodeAt(cur);
|
|
742
|
+
if (conv === 115 && !zeroPad) {
|
|
743
|
+
specs.push(precision < 0 ? "s" : "s_prec");
|
|
744
|
+
offset = cur + 1;
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
if (conv === 99 && !zeroPad) {
|
|
748
|
+
specs.push("c");
|
|
749
|
+
offset = cur + 1;
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
if (conv === 100 || conv === 105) {
|
|
753
|
+
specs.push("d");
|
|
754
|
+
offset = cur + 1;
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
if (conv === 120 || conv === 88 || conv === 111 || conv === 117) {
|
|
758
|
+
specs.push("u");
|
|
759
|
+
offset = cur + 1;
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
762
|
+
return undefined;
|
|
763
|
+
}
|
|
764
|
+
return specs;
|
|
765
|
+
}
|
|
539
766
|
export const printfCommand = define("printf", formatPrintf, 1, 1);
|
|
540
767
|
//# sourceMappingURL=basic.js.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
createPrCommand,
|
|
3
3
|
createPrCommands,
|
|
4
4
|
prCommands
|
|
5
|
-
} from "../../chunks/chunk-
|
|
5
|
+
} from "../../chunks/chunk-MUWJPSGN.js";
|
|
6
6
|
import "../../chunks/chunk-BI6JV62X.js";
|
|
7
7
|
import "../../chunks/chunk-2G2T5MEM.js";
|
|
8
8
|
import "../../chunks/chunk-JYGWVGEJ.js";
|
|
@@ -713,7 +713,7 @@ async function executeHeadTailSlow(name, maxTailFollowHandles, context) {
|
|
|
713
713
|
}
|
|
714
714
|
function headTail(name, maxTailFollowHandles = Infinity) {
|
|
715
715
|
return define(name, context => {
|
|
716
|
-
if (name === "head"
|
|
716
|
+
if (name === "head") {
|
|
717
717
|
const a = context.args;
|
|
718
718
|
let fastCount = -1;
|
|
719
719
|
if (a.length === 0) {
|
|
@@ -746,62 +746,15 @@ function headTail(name, maxTailFollowHandles = Infinity) {
|
|
|
746
746
|
fastCount = n;
|
|
747
747
|
}
|
|
748
748
|
if (fastCount >= 0) {
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
return finishHeadTailPromise(context, p);
|
|
756
|
-
}
|
|
757
|
-
catch (error) {
|
|
758
|
-
return diagnostic(context, error).then(RETURN_EXIT_ONE);
|
|
759
|
-
}
|
|
749
|
+
assertCommandRequirements(context, inspectedInputRequirements, STDIN_REQUIREMENT_MODES);
|
|
750
|
+
try {
|
|
751
|
+
const p = prefixSyncOrAsync(context, input(context, "-"), fastCount, false, false, 10);
|
|
752
|
+
if (p === undefined)
|
|
753
|
+
return RESOLVED_EXIT_ZERO;
|
|
754
|
+
return finishHeadTailPromise(context, p);
|
|
760
755
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
if (!req) {
|
|
764
|
-
assertCommandRequirements(context, inspectedInputRequirements, STDIN_REQUIREMENT_MODES);
|
|
765
|
-
const iter = input(context, "-")[Symbol.asyncIterator]();
|
|
766
|
-
if (typeof iter.tryNextSync === "function") {
|
|
767
|
-
try {
|
|
768
|
-
const res1 = iter.tryNextSync();
|
|
769
|
-
if (res1 !== undefined) {
|
|
770
|
-
if (res1.done)
|
|
771
|
-
return RESOLVED_EXIT_ZERO;
|
|
772
|
-
const chunk = res1.value;
|
|
773
|
-
const res2 = iter.tryNextSync();
|
|
774
|
-
if (res2 !== undefined && res2.done && chunk.length <= bufferLimit) {
|
|
775
|
-
if (fastCount === 0 || chunk.length === 0)
|
|
776
|
-
return RESOLVED_EXIT_ZERO;
|
|
777
|
-
let pos = chunk[chunk.length - 1] === 10 ? chunk.length - 2 : chunk.length - 1;
|
|
778
|
-
let startIdx = 0;
|
|
779
|
-
for (let rem = fastCount; rem > 0; rem--) {
|
|
780
|
-
if (pos < 0) {
|
|
781
|
-
startIdx = 0;
|
|
782
|
-
break;
|
|
783
|
-
}
|
|
784
|
-
const nl = chunk.lastIndexOf(10, pos);
|
|
785
|
-
if (nl === -1) {
|
|
786
|
-
startIdx = 0;
|
|
787
|
-
break;
|
|
788
|
-
}
|
|
789
|
-
startIdx = nl + 1;
|
|
790
|
-
pos = nl - 1;
|
|
791
|
-
}
|
|
792
|
-
const slice = startIdx === 0 ? chunk : chunk.subarray(startIdx);
|
|
793
|
-
const p = output(context, slice);
|
|
794
|
-
if (isSyncResolved(p))
|
|
795
|
-
return RESOLVED_EXIT_ZERO;
|
|
796
|
-
return finishHeadTailPromise(context, p);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
catch (error) {
|
|
801
|
-
return diagnostic(context, error).then(RETURN_EXIT_ONE);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
}
|
|
756
|
+
catch (error) {
|
|
757
|
+
return diagnostic(context, error).then(RETURN_EXIT_ONE);
|
|
805
758
|
}
|
|
806
759
|
}
|
|
807
760
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { builtInDirectContextExecutors } from "../internal.js";
|
|
1
2
|
import { createPasteCommand } from "./paste.js";
|
|
2
3
|
import { createCommCommand } from "./comm.js";
|
|
3
4
|
import { createJoinCommand } from "./join.js";
|
|
4
5
|
import { settings } from "./internal.js";
|
|
5
6
|
export function createTableTextCommands(options = {}) {
|
|
6
7
|
settings(options);
|
|
7
|
-
|
|
8
|
+
const defs = [createPasteCommand(options), createCommCommand(options), createJoinCommand(options)];
|
|
9
|
+
for (let i = 0; i < defs.length; i++)
|
|
10
|
+
builtInDirectContextExecutors.add(defs[i].execute);
|
|
11
|
+
return defs;
|
|
8
12
|
}
|
|
9
13
|
export function tableTextCommands(options = {}) {
|
|
10
14
|
const commands = createTableTextCommands(options);
|