@fuzdev/fuz_util 0.55.0 → 0.56.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/dist/args.d.ts +12 -12
- package/dist/args.js +11 -11
- package/dist/async.d.ts +12 -12
- package/dist/async.js +12 -12
- package/dist/benchmark.d.ts +24 -24
- package/dist/benchmark.js +26 -26
- package/dist/benchmark_baseline.d.ts +11 -11
- package/dist/benchmark_baseline.js +11 -11
- package/dist/benchmark_format.d.ts +15 -15
- package/dist/benchmark_format.js +15 -15
- package/dist/benchmark_stats.d.ts +5 -5
- package/dist/benchmark_stats.js +5 -5
- package/dist/benchmark_types.d.ts +7 -7
- package/dist/bytes.d.ts +4 -4
- package/dist/bytes.js +4 -4
- package/dist/dag.d.ts +2 -2
- package/dist/dag.js +2 -2
- package/dist/deep_equal.d.ts +2 -2
- package/dist/deep_equal.js +2 -2
- package/dist/diff.d.ts +17 -17
- package/dist/diff.js +17 -17
- package/dist/dom.d.ts +4 -4
- package/dist/dom.js +4 -4
- package/dist/fetch.d.ts +1 -1
- package/dist/fetch.js +1 -1
- package/dist/git.d.ts +1 -1
- package/dist/git.js +1 -1
- package/dist/hash.d.ts +6 -6
- package/dist/hash.js +8 -8
- package/dist/hash_blake3.d.ts +1 -1
- package/dist/hash_blake3.js +1 -1
- package/dist/hex.d.ts +4 -4
- package/dist/hex.js +4 -4
- package/dist/json.d.ts +2 -2
- package/dist/json.js +2 -2
- package/dist/log.d.ts +12 -12
- package/dist/log.js +11 -11
- package/dist/map.d.ts +1 -1
- package/dist/map.js +1 -1
- package/dist/object.d.ts +1 -1
- package/dist/object.js +1 -1
- package/dist/package_json.d.ts +1 -1
- package/dist/package_json.js +1 -1
- package/dist/path.d.ts +5 -5
- package/dist/path.js +5 -5
- package/dist/process.d.ts +22 -22
- package/dist/process.js +22 -22
- package/dist/random.d.ts +2 -2
- package/dist/random.js +2 -2
- package/dist/result.d.ts +6 -6
- package/dist/result.js +6 -6
- package/dist/sort.d.ts +3 -3
- package/dist/sort.js +3 -3
- package/dist/source_json.d.ts +3 -3
- package/dist/source_json.js +3 -3
- package/dist/stats.d.ts +17 -17
- package/dist/stats.js +17 -17
- package/dist/string.d.ts +6 -6
- package/dist/string.js +6 -6
- package/dist/svelte_preprocess_helpers.d.ts +42 -42
- package/dist/svelte_preprocess_helpers.js +42 -42
- package/dist/testing.d.ts +44 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +59 -0
- package/dist/time.d.ts +19 -19
- package/dist/time.js +19 -19
- package/dist/zod.d.ts +16 -16
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +24 -24
- package/package.json +6 -6
- package/src/lib/args.ts +12 -12
- package/src/lib/async.ts +12 -12
- package/src/lib/benchmark.ts +28 -28
- package/src/lib/benchmark_baseline.ts +11 -11
- package/src/lib/benchmark_format.ts +15 -15
- package/src/lib/benchmark_stats.ts +5 -5
- package/src/lib/benchmark_types.ts +7 -7
- package/src/lib/bytes.ts +4 -4
- package/src/lib/dag.ts +2 -2
- package/src/lib/deep_equal.ts +2 -2
- package/src/lib/diff.ts +17 -17
- package/src/lib/dom.ts +4 -4
- package/src/lib/fetch.ts +1 -1
- package/src/lib/git.ts +1 -1
- package/src/lib/hash.ts +8 -8
- package/src/lib/hash_blake3.ts +1 -1
- package/src/lib/hex.ts +4 -4
- package/src/lib/json.ts +2 -2
- package/src/lib/log.ts +12 -12
- package/src/lib/map.ts +1 -1
- package/src/lib/object.ts +1 -1
- package/src/lib/package_json.ts +1 -1
- package/src/lib/path.ts +5 -5
- package/src/lib/process.ts +22 -22
- package/src/lib/random.ts +2 -2
- package/src/lib/result.ts +6 -6
- package/src/lib/sort.ts +3 -3
- package/src/lib/source_json.ts +3 -3
- package/src/lib/stats.ts +17 -17
- package/src/lib/string.ts +6 -6
- package/src/lib/svelte_preprocess_helpers.ts +42 -42
- package/src/lib/testing.ts +80 -0
- package/src/lib/time.ts +19 -19
- package/src/lib/zod.ts +24 -24
package/src/lib/benchmark.ts
CHANGED
|
@@ -44,8 +44,8 @@ import type {
|
|
|
44
44
|
const DEFAULT_DURATION_MS = 1000;
|
|
45
45
|
const DEFAULT_WARMUP_ITERATIONS = 10;
|
|
46
46
|
const DEFAULT_COOLDOWN_MS = 100;
|
|
47
|
-
const
|
|
48
|
-
const
|
|
47
|
+
const DEFAULT_ITERATIONS_MIN = 10;
|
|
48
|
+
const DEFAULT_ITERATIONS_MAX = 100_000;
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Validate and normalize benchmark configuration.
|
|
@@ -90,10 +90,10 @@ interface BenchmarkTaskInternal extends BenchmarkTask {
|
|
|
90
90
|
* Warmup function by running it multiple times.
|
|
91
91
|
* Detects whether the function is async based on return value.
|
|
92
92
|
*
|
|
93
|
-
* @param fn -
|
|
94
|
-
* @param iterations -
|
|
95
|
-
* @param async_hint -
|
|
96
|
-
* @returns
|
|
93
|
+
* @param fn - function to warmup (sync or async)
|
|
94
|
+
* @param iterations - number of warmup iterations
|
|
95
|
+
* @param async_hint - if provided, use this instead of detecting
|
|
96
|
+
* @returns whether the function is async
|
|
97
97
|
*
|
|
98
98
|
* @example
|
|
99
99
|
* ```ts
|
|
@@ -146,8 +146,8 @@ export class Benchmark {
|
|
|
146
146
|
duration_ms: config.duration_ms ?? DEFAULT_DURATION_MS,
|
|
147
147
|
warmup_iterations: config.warmup_iterations ?? DEFAULT_WARMUP_ITERATIONS,
|
|
148
148
|
cooldown_ms: config.cooldown_ms ?? DEFAULT_COOLDOWN_MS,
|
|
149
|
-
min_iterations: config.min_iterations ??
|
|
150
|
-
max_iterations: config.max_iterations ??
|
|
149
|
+
min_iterations: config.min_iterations ?? DEFAULT_ITERATIONS_MIN,
|
|
150
|
+
max_iterations: config.max_iterations ?? DEFAULT_ITERATIONS_MAX,
|
|
151
151
|
timer: config.timer ?? timer_default,
|
|
152
152
|
on_iteration: config.on_iteration,
|
|
153
153
|
on_task_complete: config.on_task_complete,
|
|
@@ -156,9 +156,9 @@ export class Benchmark {
|
|
|
156
156
|
|
|
157
157
|
/**
|
|
158
158
|
* Add a benchmark task.
|
|
159
|
-
* @param name -
|
|
159
|
+
* @param name - task name or full task object
|
|
160
160
|
* @param fn - Function to benchmark (if name is string). Return values are ignored.
|
|
161
|
-
* @returns
|
|
161
|
+
* @returns this `Benchmark` instance for chaining
|
|
162
162
|
*
|
|
163
163
|
* @example
|
|
164
164
|
* ```ts
|
|
@@ -194,8 +194,8 @@ export class Benchmark {
|
|
|
194
194
|
|
|
195
195
|
/**
|
|
196
196
|
* Remove a benchmark task by name.
|
|
197
|
-
* @param name -
|
|
198
|
-
* @returns
|
|
197
|
+
* @param name - name of the task to remove
|
|
198
|
+
* @returns this `Benchmark` instance for chaining
|
|
199
199
|
* @throws Error if task with given name doesn't exist
|
|
200
200
|
*
|
|
201
201
|
* @example
|
|
@@ -217,8 +217,8 @@ export class Benchmark {
|
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
219
|
* Mark a task to be skipped during benchmark runs.
|
|
220
|
-
* @param name -
|
|
221
|
-
* @returns
|
|
220
|
+
* @param name - name of the task to skip
|
|
221
|
+
* @returns this `Benchmark` instance for chaining
|
|
222
222
|
* @throws Error if task with given name doesn't exist
|
|
223
223
|
*
|
|
224
224
|
* @example
|
|
@@ -240,8 +240,8 @@ export class Benchmark {
|
|
|
240
240
|
|
|
241
241
|
/**
|
|
242
242
|
* Mark a task to run exclusively (along with other `only` tasks).
|
|
243
|
-
* @param name -
|
|
244
|
-
* @returns
|
|
243
|
+
* @param name - name of the task to run exclusively
|
|
244
|
+
* @returns this `Benchmark` instance for chaining
|
|
245
245
|
* @throws Error if task with given name doesn't exist
|
|
246
246
|
*
|
|
247
247
|
* @example
|
|
@@ -264,7 +264,7 @@ export class Benchmark {
|
|
|
264
264
|
|
|
265
265
|
/**
|
|
266
266
|
* Run all benchmark tasks.
|
|
267
|
-
* @returns
|
|
267
|
+
* @returns array of benchmark results
|
|
268
268
|
*/
|
|
269
269
|
async run(): Promise<Array<BenchmarkResult>> {
|
|
270
270
|
this.#results = [];
|
|
@@ -385,8 +385,8 @@ export class Benchmark {
|
|
|
385
385
|
|
|
386
386
|
/**
|
|
387
387
|
* Format results as an ASCII table with percentiles, min/max, and relative performance.
|
|
388
|
-
* @param options -
|
|
389
|
-
* @returns
|
|
388
|
+
* @param options - formatting options
|
|
389
|
+
* @returns formatted table string
|
|
390
390
|
*
|
|
391
391
|
* @example
|
|
392
392
|
* ```ts
|
|
@@ -410,8 +410,8 @@ export class Benchmark {
|
|
|
410
410
|
|
|
411
411
|
/**
|
|
412
412
|
* Format results as a Markdown table.
|
|
413
|
-
* @param options -
|
|
414
|
-
* @returns
|
|
413
|
+
* @param options - formatting options (groups for organized output with optional baselines)
|
|
414
|
+
* @returns formatted markdown string
|
|
415
415
|
*
|
|
416
416
|
* @example
|
|
417
417
|
* ```ts
|
|
@@ -435,7 +435,7 @@ export class Benchmark {
|
|
|
435
435
|
|
|
436
436
|
/**
|
|
437
437
|
* Format results as JSON.
|
|
438
|
-
* @param options -
|
|
438
|
+
* @param options - formatting options (pretty, include_timings)
|
|
439
439
|
* @returns JSON string
|
|
440
440
|
*/
|
|
441
441
|
json(options?: BenchmarkFormatJsonOptions): string {
|
|
@@ -445,7 +445,7 @@ export class Benchmark {
|
|
|
445
445
|
/**
|
|
446
446
|
* Get the benchmark results.
|
|
447
447
|
* Returns a shallow copy to prevent external mutation.
|
|
448
|
-
* @returns
|
|
448
|
+
* @returns array of benchmark results
|
|
449
449
|
*/
|
|
450
450
|
results(): Array<BenchmarkResult> {
|
|
451
451
|
return [...this.#results];
|
|
@@ -453,7 +453,7 @@ export class Benchmark {
|
|
|
453
453
|
|
|
454
454
|
/**
|
|
455
455
|
* Check if the benchmark has been run and has results.
|
|
456
|
-
* @returns
|
|
456
|
+
* @returns true if results are available
|
|
457
457
|
*
|
|
458
458
|
* @example
|
|
459
459
|
* ```ts
|
|
@@ -469,7 +469,7 @@ export class Benchmark {
|
|
|
469
469
|
/**
|
|
470
470
|
* Get results as a map for convenient lookup by task name.
|
|
471
471
|
* Returns a new Map each call to prevent external mutation.
|
|
472
|
-
* @returns
|
|
472
|
+
* @returns map of task name to benchmark result
|
|
473
473
|
*
|
|
474
474
|
* @example
|
|
475
475
|
* ```ts
|
|
@@ -487,7 +487,7 @@ export class Benchmark {
|
|
|
487
487
|
/**
|
|
488
488
|
* Reset the benchmark results.
|
|
489
489
|
* Keeps tasks intact so benchmarks can be rerun.
|
|
490
|
-
* @returns
|
|
490
|
+
* @returns this `Benchmark` instance for chaining
|
|
491
491
|
*/
|
|
492
492
|
reset(): this {
|
|
493
493
|
this.#results = [];
|
|
@@ -497,7 +497,7 @@ export class Benchmark {
|
|
|
497
497
|
/**
|
|
498
498
|
* Clear everything (results and tasks).
|
|
499
499
|
* Use this to start fresh with a new set of benchmarks.
|
|
500
|
-
* @returns
|
|
500
|
+
* @returns this `Benchmark` instance for chaining
|
|
501
501
|
*/
|
|
502
502
|
clear(): this {
|
|
503
503
|
this.#results = [];
|
|
@@ -507,7 +507,7 @@ export class Benchmark {
|
|
|
507
507
|
|
|
508
508
|
/**
|
|
509
509
|
* Get a quick text summary of the fastest task.
|
|
510
|
-
* @returns
|
|
510
|
+
* @returns human-readable summary string
|
|
511
511
|
*
|
|
512
512
|
* @example
|
|
513
513
|
* ```ts
|
|
@@ -161,8 +161,8 @@ const results_to_entries = (results: Array<BenchmarkResult>): Array<BenchmarkBas
|
|
|
161
161
|
/**
|
|
162
162
|
* Save benchmark results as the current baseline.
|
|
163
163
|
*
|
|
164
|
-
* @param results -
|
|
165
|
-
* @param options -
|
|
164
|
+
* @param results - benchmark results to save
|
|
165
|
+
* @param options - save options
|
|
166
166
|
*
|
|
167
167
|
* @example
|
|
168
168
|
* ```ts
|
|
@@ -204,8 +204,8 @@ export const benchmark_baseline_save = async (
|
|
|
204
204
|
/**
|
|
205
205
|
* Load the current baseline from disk.
|
|
206
206
|
*
|
|
207
|
-
* @param options -
|
|
208
|
-
* @returns
|
|
207
|
+
* @param options - load options
|
|
208
|
+
* @returns the baseline, or null if not found or invalid
|
|
209
209
|
*
|
|
210
210
|
* @example
|
|
211
211
|
* ```ts
|
|
@@ -255,9 +255,9 @@ export const benchmark_baseline_load = async (
|
|
|
255
255
|
/**
|
|
256
256
|
* Compare benchmark results against the stored baseline.
|
|
257
257
|
*
|
|
258
|
-
* @param results -
|
|
259
|
-
* @param options -
|
|
260
|
-
* @returns
|
|
258
|
+
* @param results - current benchmark results
|
|
259
|
+
* @param options - comparison options including regression threshold and staleness warning
|
|
260
|
+
* @returns comparison result with regressions, improvements, and unchanged tasks
|
|
261
261
|
*
|
|
262
262
|
* @example
|
|
263
263
|
* ```ts
|
|
@@ -420,8 +420,8 @@ export const benchmark_baseline_compare = async (
|
|
|
420
420
|
/**
|
|
421
421
|
* Format a baseline comparison result as a human-readable string.
|
|
422
422
|
*
|
|
423
|
-
* @param result -
|
|
424
|
-
* @returns
|
|
423
|
+
* @param result - comparison result from `benchmark_baseline_compare`
|
|
424
|
+
* @returns formatted string summary
|
|
425
425
|
*/
|
|
426
426
|
export const benchmark_baseline_format = (result: BenchmarkBaselineComparisonResult): string => {
|
|
427
427
|
if (!result.baseline_found) {
|
|
@@ -506,8 +506,8 @@ export const benchmark_baseline_format = (result: BenchmarkBaselineComparisonRes
|
|
|
506
506
|
/**
|
|
507
507
|
* Format a baseline comparison result as JSON for programmatic consumption.
|
|
508
508
|
*
|
|
509
|
-
* @param result -
|
|
510
|
-
* @param options -
|
|
509
|
+
* @param result - comparison result from `benchmark_baseline_compare`
|
|
510
|
+
* @param options - formatting options
|
|
511
511
|
* @returns JSON string
|
|
512
512
|
*/
|
|
513
513
|
export const benchmark_baseline_format_json = (
|
|
@@ -6,9 +6,9 @@ import {format_number} from './maths.js';
|
|
|
6
6
|
/**
|
|
7
7
|
* Format results as an ASCII table with percentiles, min/max, and relative performance.
|
|
8
8
|
* All times use the same unit for easy comparison.
|
|
9
|
-
* @param results -
|
|
10
|
-
* @param baseline -
|
|
11
|
-
* @returns
|
|
9
|
+
* @param results - array of benchmark results
|
|
10
|
+
* @param baseline - optional task name to use as baseline for comparison (defaults to fastest)
|
|
11
|
+
* @returns formatted table string with enhanced metrics
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
@@ -126,9 +126,9 @@ export const benchmark_format_table = (
|
|
|
126
126
|
/**
|
|
127
127
|
* Format results as a Markdown table with key metrics.
|
|
128
128
|
* All times use the same unit for easy comparison.
|
|
129
|
-
* @param results -
|
|
130
|
-
* @param baseline -
|
|
131
|
-
* @returns
|
|
129
|
+
* @param results - array of benchmark results
|
|
130
|
+
* @param baseline - optional task name to use as baseline for comparison (defaults to fastest)
|
|
131
|
+
* @returns formatted markdown table string
|
|
132
132
|
*
|
|
133
133
|
* @example
|
|
134
134
|
* ```ts
|
|
@@ -238,9 +238,9 @@ export const benchmark_format_markdown = (
|
|
|
238
238
|
|
|
239
239
|
/**
|
|
240
240
|
* Format results as grouped Markdown tables with headers between groups.
|
|
241
|
-
* @param results -
|
|
242
|
-
* @param groups -
|
|
243
|
-
* @returns
|
|
241
|
+
* @param results - array of benchmark results
|
|
242
|
+
* @param groups - array of group definitions
|
|
243
|
+
* @returns formatted markdown string with group headers and tables
|
|
244
244
|
*
|
|
245
245
|
* @example
|
|
246
246
|
* ```ts
|
|
@@ -301,8 +301,8 @@ export interface BenchmarkFormatJsonOptions {
|
|
|
301
301
|
|
|
302
302
|
/**
|
|
303
303
|
* Format results as JSON.
|
|
304
|
-
* @param results -
|
|
305
|
-
* @param options -
|
|
304
|
+
* @param results - array of benchmark results
|
|
305
|
+
* @param options - formatting options
|
|
306
306
|
* @returns JSON string
|
|
307
307
|
*
|
|
308
308
|
* @example
|
|
@@ -348,9 +348,9 @@ export const benchmark_format_json = (
|
|
|
348
348
|
|
|
349
349
|
/**
|
|
350
350
|
* Format results as a grouped table with visual separators between groups.
|
|
351
|
-
* @param results -
|
|
352
|
-
* @param groups -
|
|
353
|
-
* @returns
|
|
351
|
+
* @param results - array of benchmark results
|
|
352
|
+
* @param groups - array of group definitions
|
|
353
|
+
* @returns formatted table string with group separators
|
|
354
354
|
*
|
|
355
355
|
* @example
|
|
356
356
|
* ```ts
|
|
@@ -405,6 +405,6 @@ export const benchmark_format_table_grouped = (
|
|
|
405
405
|
|
|
406
406
|
/**
|
|
407
407
|
* Format a number with fixed decimal places and thousands separators.
|
|
408
|
-
* @see
|
|
408
|
+
* @see `format_number` in `maths.ts` for the underlying implementation.
|
|
409
409
|
*/
|
|
410
410
|
export const benchmark_format_number = format_number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Benchmark-specific statistical analysis.
|
|
3
|
-
* Uses the general stats utilities from stats.ts for timing/performance analysis.
|
|
3
|
+
* Uses the general stats utilities from `stats.ts` for timing/performance analysis.
|
|
4
4
|
* All timing values are in nanoseconds.
|
|
5
5
|
*
|
|
6
6
|
* @module
|
|
@@ -204,10 +204,10 @@ export class BenchmarkStats {
|
|
|
204
204
|
* calibrated for social science and produce false positives in benchmarking
|
|
205
205
|
* where within-run variance is tight.
|
|
206
206
|
*
|
|
207
|
-
* @param a -
|
|
208
|
-
* @param b -
|
|
209
|
-
* @param options -
|
|
210
|
-
* @returns
|
|
207
|
+
* @param a - first benchmark stats (or any object with required properties)
|
|
208
|
+
* @param b - second benchmark stats (or any object with required properties)
|
|
209
|
+
* @param options - comparison options
|
|
210
|
+
* @returns comparison result with significance, effect size, and recommendation
|
|
211
211
|
*
|
|
212
212
|
* @example
|
|
213
213
|
* ```ts
|
|
@@ -41,7 +41,7 @@ export interface BenchmarkConfig {
|
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Custom timer to use for measurements.
|
|
44
|
-
* Default: timer_default (auto-detects environment)
|
|
44
|
+
* Default: `timer_default` (auto-detects environment)
|
|
45
45
|
*/
|
|
46
46
|
timer?: Timer;
|
|
47
47
|
|
|
@@ -54,9 +54,9 @@ export interface BenchmarkConfig {
|
|
|
54
54
|
* after the timing capture. However, frequent GC calls will slow overall benchmark
|
|
55
55
|
* execution time.
|
|
56
56
|
*
|
|
57
|
-
* @param task_name -
|
|
58
|
-
* @param iteration -
|
|
59
|
-
* @param abort -
|
|
57
|
+
* @param task_name - name of the current task being benchmarked
|
|
58
|
+
* @param iteration - current iteration number (1-indexed)
|
|
59
|
+
* @param abort - call to stop the benchmark early for this task
|
|
60
60
|
*
|
|
61
61
|
* @example
|
|
62
62
|
* ```ts
|
|
@@ -90,9 +90,9 @@ export interface BenchmarkConfig {
|
|
|
90
90
|
* Callback invoked after each task completes.
|
|
91
91
|
* Useful for logging progress during long benchmark runs.
|
|
92
92
|
*
|
|
93
|
-
* @param result -
|
|
94
|
-
* @param index -
|
|
95
|
-
* @param total -
|
|
93
|
+
* @param result - the completed benchmark result
|
|
94
|
+
* @param index - zero-based index of the completed task
|
|
95
|
+
* @param total - total number of tasks to run
|
|
96
96
|
*
|
|
97
97
|
* @example
|
|
98
98
|
* ```ts
|
package/src/lib/bytes.ts
CHANGED
|
@@ -10,8 +10,8 @@ const encoder = new TextEncoder();
|
|
|
10
10
|
* Converts string or binary data to a `Uint8Array`.
|
|
11
11
|
* Strings are UTF-8 encoded. `Uint8Array` inputs are returned as-is.
|
|
12
12
|
*
|
|
13
|
-
* @param data -
|
|
14
|
-
* @returns `Uint8Array` view of the data
|
|
13
|
+
* @param data - string or `BufferSource` to convert
|
|
14
|
+
* @returns `Uint8Array` view of the data
|
|
15
15
|
*/
|
|
16
16
|
export const to_bytes = (data: BufferSource | string): Uint8Array => {
|
|
17
17
|
if (typeof data === 'string') return encoder.encode(data);
|
|
@@ -23,8 +23,8 @@ export const to_bytes = (data: BufferSource | string): Uint8Array => {
|
|
|
23
23
|
/**
|
|
24
24
|
* Formats a byte count as a human-readable string.
|
|
25
25
|
*
|
|
26
|
-
* @param n - byte count
|
|
27
|
-
* @returns formatted string like `'1.2 KB'` or `'3.4 MB'
|
|
26
|
+
* @param n - byte count
|
|
27
|
+
* @returns formatted string like `'1.2 KB'` or `'3.4 MB'`
|
|
28
28
|
*/
|
|
29
29
|
export const format_bytes = (n: number): string => {
|
|
30
30
|
if (n < 1024) return n + ' B';
|
package/src/lib/dag.ts
CHANGED
|
@@ -80,8 +80,8 @@ export interface DagResult {
|
|
|
80
80
|
* eligible to start. Failure cascading and stop-on-failure are handled
|
|
81
81
|
* per the options.
|
|
82
82
|
*
|
|
83
|
-
* @param options - DAG execution options
|
|
84
|
-
* @returns
|
|
83
|
+
* @param options - DAG execution options
|
|
84
|
+
* @returns aggregated result with per-node details
|
|
85
85
|
*/
|
|
86
86
|
export const run_dag = async <T extends DagNode>(options: DagOptions<T>): Promise<DagResult> => {
|
|
87
87
|
const {
|
package/src/lib/deep_equal.ts
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* - Promises always return false (cannot be meaningfully compared)
|
|
11
11
|
* - Maps/Sets compare by reference for object keys/values
|
|
12
12
|
*
|
|
13
|
-
* @param a first value to compare
|
|
14
|
-
* @param b second value to compare
|
|
13
|
+
* @param a - first value to compare
|
|
14
|
+
* @param b - second value to compare
|
|
15
15
|
* @returns true if deeply equal, false otherwise
|
|
16
16
|
*/
|
|
17
17
|
export const deep_equal = (a: unknown, b: unknown): boolean => {
|
package/src/lib/diff.ts
CHANGED
|
@@ -15,9 +15,9 @@ export interface DiffLine {
|
|
|
15
15
|
/**
|
|
16
16
|
* Generate a line-based diff between two strings using LCS algorithm.
|
|
17
17
|
*
|
|
18
|
-
* @param a -
|
|
19
|
-
* @param b -
|
|
20
|
-
* @returns
|
|
18
|
+
* @param a - the original/current content
|
|
19
|
+
* @param b - the new/desired content
|
|
20
|
+
* @returns array of diff lines with type annotations
|
|
21
21
|
*/
|
|
22
22
|
export const diff_lines = (a: string, b: string): Array<DiffLine> => {
|
|
23
23
|
const a_lines = a.split('\n');
|
|
@@ -94,9 +94,9 @@ const compute_lcs = (a: Array<string>, b: Array<string>): Array<string> => {
|
|
|
94
94
|
/**
|
|
95
95
|
* Filter diff to only include lines within N lines of context around changes.
|
|
96
96
|
*
|
|
97
|
-
* @param diff -
|
|
98
|
-
* @param context_lines -
|
|
99
|
-
* @returns
|
|
97
|
+
* @param diff - the full diff lines
|
|
98
|
+
* @param context_lines - number of context lines to show around changes (default: 3)
|
|
99
|
+
* @returns filtered diff with ellipsis markers for skipped regions
|
|
100
100
|
*/
|
|
101
101
|
export const filter_diff_context = (diff: Array<DiffLine>, context_lines = 3): Array<DiffLine> => {
|
|
102
102
|
if (diff.length === 0) return [];
|
|
@@ -163,11 +163,11 @@ export interface FormatDiffOptions {
|
|
|
163
163
|
/**
|
|
164
164
|
* Format a diff for display.
|
|
165
165
|
*
|
|
166
|
-
* @param diff -
|
|
167
|
-
* @param current_path -
|
|
168
|
-
* @param desired_path -
|
|
169
|
-
* @param options -
|
|
170
|
-
* @returns
|
|
166
|
+
* @param diff - the diff lines to format
|
|
167
|
+
* @param current_path - path label for "current" content
|
|
168
|
+
* @param desired_path - path label for "desired" content
|
|
169
|
+
* @param options - formatting options
|
|
170
|
+
* @returns formatted diff string
|
|
171
171
|
*/
|
|
172
172
|
export const format_diff = (
|
|
173
173
|
diff: Array<DiffLine>,
|
|
@@ -208,14 +208,14 @@ export const format_diff = (
|
|
|
208
208
|
/**
|
|
209
209
|
* Generate a formatted diff between two strings.
|
|
210
210
|
*
|
|
211
|
-
* Combines diff_lines
|
|
211
|
+
* Combines `diff_lines`, `filter_diff_context`, and `format_diff` for convenience.
|
|
212
212
|
* Returns null if content is binary.
|
|
213
213
|
*
|
|
214
|
-
* @param current -
|
|
215
|
-
* @param desired -
|
|
216
|
-
* @param path -
|
|
217
|
-
* @param options -
|
|
218
|
-
* @returns
|
|
214
|
+
* @param current - current content
|
|
215
|
+
* @param desired - desired content
|
|
216
|
+
* @param path - file path for labels
|
|
217
|
+
* @param options - formatting options
|
|
218
|
+
* @returns formatted diff string, or null if binary
|
|
219
219
|
*/
|
|
220
220
|
export const generate_diff = (
|
|
221
221
|
current: string,
|
package/src/lib/dom.ts
CHANGED
|
@@ -60,11 +60,11 @@ export const is_interactive = (el: any): boolean => {
|
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* Stops an event from bubbling and doing default behavior.
|
|
63
|
-
* @param event
|
|
64
|
-
* @param immediate defaults to `true` to use `stopImmediatePropagation` over `stopPropagation`
|
|
65
|
-
* @param preventDefault defaults to `true`
|
|
63
|
+
* @param event - the event to swallow
|
|
64
|
+
* @param immediate - defaults to `true` to use `stopImmediatePropagation` over `stopPropagation`
|
|
65
|
+
* @param preventDefault - defaults to `true`
|
|
66
|
+
* @returns the swallowed event
|
|
66
67
|
* @mutates event - calls preventDefault(), stopPropagation(), or stopImmediatePropagation()
|
|
67
|
-
* @returns
|
|
68
68
|
*/
|
|
69
69
|
export const swallow = <
|
|
70
70
|
T extends Pick<Event, 'preventDefault' | 'stopPropagation' | 'stopImmediatePropagation'>,
|
package/src/lib/fetch.ts
CHANGED
|
@@ -34,7 +34,7 @@ export interface FetchValueOptions<TValue, TParams = undefined> {
|
|
|
34
34
|
* (you can still provide headers directly)
|
|
35
35
|
*
|
|
36
36
|
* Unlike `fetch`, this throws on ratelimits (status code 429)
|
|
37
|
-
* to halt whatever is
|
|
37
|
+
* to halt whatever is happening in its tracks to avoid accidental abuse,
|
|
38
38
|
* but returns a `Result` in all other cases.
|
|
39
39
|
* Handling ratelimit headers with more sophistication gets tricky because behavior
|
|
40
40
|
* differs across services.
|
package/src/lib/git.ts
CHANGED
|
@@ -122,7 +122,7 @@ export interface GitWorkspaceStatus {
|
|
|
122
122
|
* Note: This implementation treats submodules the same as regular files.
|
|
123
123
|
* Submodule-specific status codes (lowercase m, ?) are interpreted as changes.
|
|
124
124
|
*
|
|
125
|
-
* @param stdout -
|
|
125
|
+
* @param stdout - the raw output from `git status --porcelain -z`
|
|
126
126
|
* @returns status object with flags for unstaged changes, staged changes, and untracked files
|
|
127
127
|
*/
|
|
128
128
|
export const git_parse_workspace_status = (stdout: string | null): GitWorkspaceStatus => {
|
package/src/lib/hash.ts
CHANGED
|
@@ -15,9 +15,9 @@ const encoder = new TextEncoder();
|
|
|
15
15
|
/**
|
|
16
16
|
* Computes a hash using Web Crypto API.
|
|
17
17
|
*
|
|
18
|
-
* @param algorithm - Web Crypto algorithm name (e.g. `'SHA-256'`)
|
|
18
|
+
* @param algorithm - Web Crypto algorithm name (e.g. `'SHA-256'`)
|
|
19
19
|
* @param data - String or binary data to hash. Strings are UTF-8 encoded.
|
|
20
|
-
* @returns hexadecimal hash string
|
|
20
|
+
* @returns hexadecimal hash string
|
|
21
21
|
*/
|
|
22
22
|
const hash_webcrypto = async (algorithm: string, data: BufferSource | string): Promise<string> => {
|
|
23
23
|
const buffer = typeof data === 'string' ? encoder.encode(data) : data;
|
|
@@ -29,7 +29,7 @@ const hash_webcrypto = async (algorithm: string, data: BufferSource | string): P
|
|
|
29
29
|
* Computes a SHA-1 hash using Web Crypto API.
|
|
30
30
|
*
|
|
31
31
|
* @param data - String or binary data to hash. Strings are UTF-8 encoded.
|
|
32
|
-
* @returns 40-character hexadecimal hash string
|
|
32
|
+
* @returns 40-character hexadecimal hash string
|
|
33
33
|
*/
|
|
34
34
|
export const hash_sha1 = (data: BufferSource | string): Promise<string> =>
|
|
35
35
|
hash_webcrypto('SHA-1', data);
|
|
@@ -38,7 +38,7 @@ export const hash_sha1 = (data: BufferSource | string): Promise<string> =>
|
|
|
38
38
|
* Computes a SHA-256 hash using Web Crypto API.
|
|
39
39
|
*
|
|
40
40
|
* @param data - String or binary data to hash. Strings are UTF-8 encoded.
|
|
41
|
-
* @returns 64-character hexadecimal hash string
|
|
41
|
+
* @returns 64-character hexadecimal hash string
|
|
42
42
|
*/
|
|
43
43
|
export const hash_sha256 = (data: BufferSource | string): Promise<string> =>
|
|
44
44
|
hash_webcrypto('SHA-256', data);
|
|
@@ -47,7 +47,7 @@ export const hash_sha256 = (data: BufferSource | string): Promise<string> =>
|
|
|
47
47
|
* Computes a SHA-384 hash using Web Crypto API.
|
|
48
48
|
*
|
|
49
49
|
* @param data - String or binary data to hash. Strings are UTF-8 encoded.
|
|
50
|
-
* @returns 96-character hexadecimal hash string
|
|
50
|
+
* @returns 96-character hexadecimal hash string
|
|
51
51
|
*/
|
|
52
52
|
export const hash_sha384 = (data: BufferSource | string): Promise<string> =>
|
|
53
53
|
hash_webcrypto('SHA-384', data);
|
|
@@ -56,7 +56,7 @@ export const hash_sha384 = (data: BufferSource | string): Promise<string> =>
|
|
|
56
56
|
* Computes a SHA-512 hash using Web Crypto API.
|
|
57
57
|
*
|
|
58
58
|
* @param data - String or binary data to hash. Strings are UTF-8 encoded.
|
|
59
|
-
* @returns 128-character hexadecimal hash string
|
|
59
|
+
* @returns 128-character hexadecimal hash string
|
|
60
60
|
*/
|
|
61
61
|
export const hash_sha512 = (data: BufferSource | string): Promise<string> =>
|
|
62
62
|
hash_webcrypto('SHA-512', data);
|
|
@@ -68,8 +68,8 @@ export const hash_sha512 = (data: BufferSource | string): Promise<string> =>
|
|
|
68
68
|
* Note: Strings use UTF-16 code units, buffers use raw bytes.
|
|
69
69
|
* For non-ASCII, `hash_insecure(str) !== hash_insecure(encoder.encode(str))`.
|
|
70
70
|
*
|
|
71
|
-
* @param data -
|
|
72
|
-
* @returns 8-character hex-encoded unsigned 32-bit hash
|
|
71
|
+
* @param data - string or binary data to hash
|
|
72
|
+
* @returns 8-character hex-encoded unsigned 32-bit hash
|
|
73
73
|
*/
|
|
74
74
|
export const hash_insecure = (data: BufferSource | string): string => {
|
|
75
75
|
let hash = 5381; // DJB2 initial value, chosen empirically for good distribution
|
package/src/lib/hash_blake3.ts
CHANGED
|
@@ -25,7 +25,7 @@ export const blake3_ready = init();
|
|
|
25
25
|
* Computes a BLAKE3 hash synchronously.
|
|
26
26
|
*
|
|
27
27
|
* @param data - String or binary data to hash. Strings are UTF-8 encoded.
|
|
28
|
-
* @returns 64-character hexadecimal hash string (32 bytes)
|
|
28
|
+
* @returns 64-character hexadecimal hash string (32 bytes)
|
|
29
29
|
*/
|
|
30
30
|
export const hash_blake3 = (data: BufferSource | string): string => to_hex(hash(to_bytes(data)));
|
|
31
31
|
|
package/src/lib/hex.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* Converts a `Uint8Array` to a lowercase hex string.
|
|
9
9
|
*
|
|
10
|
-
* @param bytes -
|
|
11
|
-
* @returns
|
|
10
|
+
* @param bytes - binary data to encode
|
|
11
|
+
* @returns hex string with two characters per byte
|
|
12
12
|
*/
|
|
13
13
|
export const to_hex = (bytes: Uint8Array): string => {
|
|
14
14
|
const lookup = get_byte_to_hex();
|
|
@@ -23,8 +23,8 @@ export const to_hex = (bytes: Uint8Array): string => {
|
|
|
23
23
|
* Decodes a hex string to a `Uint8Array`.
|
|
24
24
|
* Whitespace is stripped before parsing. Returns `null` for invalid hex.
|
|
25
25
|
*
|
|
26
|
-
* @param hex -
|
|
27
|
-
* @returns
|
|
26
|
+
* @param hex - hex string to decode (case-insensitive, whitespace allowed)
|
|
27
|
+
* @returns decoded bytes, or `null` if the input is not valid hex
|
|
28
28
|
*/
|
|
29
29
|
export const from_hex = (hex: string): Uint8Array | null => {
|
|
30
30
|
const clean = hex.replace(/\s/g, '');
|
package/src/lib/json.ts
CHANGED
|
@@ -44,8 +44,8 @@ export const json_embed = <T>(data: T, stringify: (data: T) => string = JSON.str
|
|
|
44
44
|
* Recursively sorts object keys alphabetically for consistent hashing.
|
|
45
45
|
* Arrays and primitives are serialized as-is.
|
|
46
46
|
*
|
|
47
|
-
* @param value
|
|
48
|
-
* @returns
|
|
47
|
+
* @param value - any JSON-serializable value
|
|
48
|
+
* @returns deterministic JSON string representation
|
|
49
49
|
*/
|
|
50
50
|
export const json_stringify_deterministic = (value: unknown): string =>
|
|
51
51
|
JSON.stringify(value, (_key, val) => {
|