@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/log.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {DEV} from 'esm-env';
|
|
|
12
12
|
export type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Console interface subset used by Logger for output.
|
|
15
|
+
* Console interface subset used by `Logger` for output.
|
|
16
16
|
* Allows custom console implementations for testing.
|
|
17
17
|
*/
|
|
18
18
|
export type LogConsole = Pick<typeof console, 'error' | 'warn' | 'log'>;
|
|
@@ -42,15 +42,15 @@ const LOG_LEVEL_VALUES: Record<LogLevel, number> = {
|
|
|
42
42
|
/**
|
|
43
43
|
* Converts a log level to its numeric value for comparison.
|
|
44
44
|
* Higher numbers indicate more verbose logging.
|
|
45
|
-
* @param level
|
|
46
|
-
* @returns
|
|
45
|
+
* @param level - the log level to convert
|
|
46
|
+
* @returns numeric value (0-4)
|
|
47
47
|
*/
|
|
48
48
|
export const log_level_to_number = (level: LogLevel): number => LOG_LEVEL_VALUES[level];
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Parses and validates a log level string.
|
|
52
|
-
* @param value
|
|
53
|
-
* @returns
|
|
52
|
+
* @param value - the value to parse as a log level
|
|
53
|
+
* @returns the validated log level, or undefined if value is undefined
|
|
54
54
|
* @throws Error if value is provided but invalid
|
|
55
55
|
*/
|
|
56
56
|
export const log_level_parse = (value: string | undefined): LogLevel | undefined => {
|
|
@@ -112,10 +112,10 @@ export class Logger {
|
|
|
112
112
|
/**
|
|
113
113
|
* Creates a new Logger instance.
|
|
114
114
|
*
|
|
115
|
-
* @param label
|
|
115
|
+
* @param label - optional label for this logger. Can be `undefined` for no label, or an
|
|
116
116
|
* empty string `''` which is functionally equivalent (both produce no brackets in output).
|
|
117
117
|
* Note: Empty strings are only allowed for root loggers - child loggers cannot have empty labels.
|
|
118
|
-
* @param options
|
|
118
|
+
* @param options - optional configuration for level, colors, and console
|
|
119
119
|
*/
|
|
120
120
|
constructor(label?: string, options: LoggerOptions = {}) {
|
|
121
121
|
this.label = label;
|
|
@@ -205,7 +205,7 @@ export class Logger {
|
|
|
205
205
|
/**
|
|
206
206
|
* Gets the root logger by walking up the parent chain.
|
|
207
207
|
* Useful for setting global configuration that affects all child loggers.
|
|
208
|
-
* @returns
|
|
208
|
+
* @returns the root logger (the one without a parent)
|
|
209
209
|
*/
|
|
210
210
|
get root(): Logger {
|
|
211
211
|
let current: Logger = this; // eslint-disable-line consistent-this, @typescript-eslint/no-this-alias
|
|
@@ -360,11 +360,11 @@ export class Logger {
|
|
|
360
360
|
* Creates a child logger with automatic label concatenation.
|
|
361
361
|
* Children inherit parent configuration unless overridden.
|
|
362
362
|
*
|
|
363
|
-
* @param label
|
|
363
|
+
* @param label - child label (will be concatenated with parent label using `:`)
|
|
364
364
|
* Cannot be an empty string - empty labels would result in confusing output like `parent:`
|
|
365
365
|
* with a trailing colon. Use `undefined` or `''` only for root loggers.
|
|
366
|
-
* @param options
|
|
367
|
-
* @returns
|
|
366
|
+
* @param options - optional configuration overrides
|
|
367
|
+
* @returns new `Logger` instance with concatenated label
|
|
368
368
|
* @throws Error if label is an empty string
|
|
369
369
|
*
|
|
370
370
|
* @example
|
|
@@ -440,7 +440,7 @@ export class Logger {
|
|
|
440
440
|
* Note: This method ignores the configured log level - it always outputs regardless of
|
|
441
441
|
* whether the logger is set to 'off' or any other level.
|
|
442
442
|
*
|
|
443
|
-
* @param args
|
|
443
|
+
* @param args - values to log directly to console
|
|
444
444
|
*/
|
|
445
445
|
raw(...args: Array<unknown>): void {
|
|
446
446
|
this.console.log(...args);
|
package/src/lib/map.ts
CHANGED
package/src/lib/object.ts
CHANGED
|
@@ -61,7 +61,7 @@ export const pick_by = <T extends Record<K, any>, K extends string | number>(
|
|
|
61
61
|
* `omit_undefined` is a commonly used form of `pick_by`.
|
|
62
62
|
* See this issue for why it's used so much:
|
|
63
63
|
* https://github.com/Microsoft/TypeScript/issues/13195
|
|
64
|
-
* @param obj
|
|
64
|
+
* @param obj - the object to filter
|
|
65
65
|
* @returns `obj` with all `undefined` properties removed
|
|
66
66
|
*/
|
|
67
67
|
export const omit_undefined = <T extends Record<string | number, any>>(obj: T): T =>
|
package/src/lib/package_json.ts
CHANGED
|
@@ -66,7 +66,7 @@ export type PackageJsonExports = z.infer<typeof PackageJsonExports>;
|
|
|
66
66
|
export const PackageJson = z.looseObject({
|
|
67
67
|
// according to the npm docs, `name` and `version` are the only required properties
|
|
68
68
|
name: z.string(),
|
|
69
|
-
version: z.string(),
|
|
69
|
+
version: z.string().optional(),
|
|
70
70
|
private: z
|
|
71
71
|
.boolean()
|
|
72
72
|
.meta({description: 'disallow publishing to the configured registry'})
|
package/src/lib/path.ts
CHANGED
|
@@ -106,9 +106,9 @@ export const parse_path_pieces = (raw_path: string): Array<PathPiece> => {
|
|
|
106
106
|
* Returns `false` when `filename` is `undefined`, empty string, or `exclude` is empty.
|
|
107
107
|
* String patterns use substring matching. RegExp patterns use `.test()`.
|
|
108
108
|
*
|
|
109
|
-
* @param filename
|
|
110
|
-
* @param exclude
|
|
111
|
-
* @returns `true` if the file should be excluded from processing
|
|
109
|
+
* @param filename - the file path to check, or `undefined` for virtual files
|
|
110
|
+
* @param exclude - array of string or RegExp exclusion patterns
|
|
111
|
+
* @returns `true` if the file should be excluded from processing
|
|
112
112
|
*/
|
|
113
113
|
export const should_exclude_path = (
|
|
114
114
|
filename: string | undefined,
|
|
@@ -122,8 +122,8 @@ export const should_exclude_path = (
|
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
124
|
* Converts a string into a URL-compatible slug.
|
|
125
|
-
* @param str the string to convert
|
|
126
|
-
* @param map_special_characters if `true`, characters like `ñ` are converted to their ASCII equivalents, runs around 5x faster when disabled
|
|
125
|
+
* @param str - the string to convert
|
|
126
|
+
* @param map_special_characters - if `true`, characters like `ñ` are converted to their ASCII equivalents, runs around 5x faster when disabled
|
|
127
127
|
* @mutates special_char_mappers - calls `get_special_char_mappers()` which lazily initializes the module-level array if `map_special_characters` is true
|
|
128
128
|
*/
|
|
129
129
|
export const slugify = (str: string, map_special_characters = true): string => {
|
package/src/lib/process.ts
CHANGED
|
@@ -250,10 +250,10 @@ export class ProcessRegistry {
|
|
|
250
250
|
* Spawns a process and tracks it in this registry.
|
|
251
251
|
* The process is automatically unregistered when it exits.
|
|
252
252
|
*
|
|
253
|
-
* @param command -
|
|
254
|
-
* @param args -
|
|
255
|
-
* @param options -
|
|
256
|
-
* @returns
|
|
253
|
+
* @param command - the command to run
|
|
254
|
+
* @param args - arguments to pass to the command
|
|
255
|
+
* @param options - spawn options including `signal` and `timeout_ms`
|
|
256
|
+
* @returns handle with `child` process and `closed` promise
|
|
257
257
|
*/
|
|
258
258
|
spawn(
|
|
259
259
|
command: string,
|
|
@@ -295,10 +295,10 @@ export class ProcessRegistry {
|
|
|
295
295
|
* Spawns a process and captures stdout/stderr as strings.
|
|
296
296
|
* Sets `stdio: 'pipe'` automatically.
|
|
297
297
|
*
|
|
298
|
-
* @param command -
|
|
299
|
-
* @param args -
|
|
300
|
-
* @param options -
|
|
301
|
-
* @returns
|
|
298
|
+
* @param command - the command to run
|
|
299
|
+
* @param args - arguments to pass to the command
|
|
300
|
+
* @param options - spawn options
|
|
301
|
+
* @returns result with captured `stdout` and `stderr`
|
|
302
302
|
* - `null` means spawn failed (ENOENT, etc.) or stream was unavailable
|
|
303
303
|
* - `''` (empty string) means process ran but produced no output
|
|
304
304
|
* - non-empty string contains the captured output
|
|
@@ -337,9 +337,9 @@ export class ProcessRegistry {
|
|
|
337
337
|
/**
|
|
338
338
|
* Kills a child process and waits for it to exit.
|
|
339
339
|
*
|
|
340
|
-
* @param child -
|
|
341
|
-
* @param options -
|
|
342
|
-
* @returns
|
|
340
|
+
* @param child - the child process to kill
|
|
341
|
+
* @param options - kill options including signal and timeout
|
|
342
|
+
* @returns the spawn result after the process exits
|
|
343
343
|
*/
|
|
344
344
|
async despawn(child: ChildProcess, options?: DespawnOptions): Promise<SpawnResult> {
|
|
345
345
|
const {signal = 'SIGTERM', timeout_ms} = options ?? {};
|
|
@@ -382,8 +382,8 @@ export class ProcessRegistry {
|
|
|
382
382
|
/**
|
|
383
383
|
* Kills all processes in this registry.
|
|
384
384
|
*
|
|
385
|
-
* @param options -
|
|
386
|
-
* @returns
|
|
385
|
+
* @param options - kill options applied to all processes
|
|
386
|
+
* @returns array of spawn results
|
|
387
387
|
*/
|
|
388
388
|
async despawn_all(options?: DespawnOptions): Promise<Array<SpawnResult>> {
|
|
389
389
|
return Promise.all([...this.processes].map((child) => this.despawn(child, options)));
|
|
@@ -401,14 +401,14 @@ export class ProcessRegistry {
|
|
|
401
401
|
* graceful shutdown uses a blocking busy-wait. This may not be sufficient
|
|
402
402
|
* for processes that need significant cleanup time.
|
|
403
403
|
*
|
|
404
|
-
* @param options -
|
|
404
|
+
* @param options - configuration options
|
|
405
405
|
* @param options.to_error_label - Customize error label, return `null` for default
|
|
406
406
|
* @param options.map_error_text - Customize error text, return `''` to silence
|
|
407
407
|
* @param options.handle_error - Called after cleanup, defaults to `process.exit(1)`
|
|
408
408
|
* @param options.graceful_timeout_ms - If set, sends SIGTERM first and waits this
|
|
409
409
|
* many ms before SIGKILL. Recommended: 100-500ms. If null/undefined, uses
|
|
410
410
|
* immediate SIGKILL (default).
|
|
411
|
-
* @returns
|
|
411
|
+
* @returns cleanup function to remove the handler
|
|
412
412
|
*/
|
|
413
413
|
attach_error_handler(options?: {
|
|
414
414
|
to_error_label?: (err: Error, origin: NodeJS.UncaughtExceptionOrigin) => string | null;
|
|
@@ -552,7 +552,7 @@ export const despawn_all = (options?: DespawnOptions): Promise<Array<SpawnResult
|
|
|
552
552
|
/**
|
|
553
553
|
* Attaches an `uncaughtException` handler to the default registry.
|
|
554
554
|
*
|
|
555
|
-
* @see ProcessRegistry.attach_error_handler
|
|
555
|
+
* @see `ProcessRegistry.attach_error_handler`
|
|
556
556
|
*/
|
|
557
557
|
export const attach_process_error_handler = (
|
|
558
558
|
options?: Parameters<ProcessRegistry['attach_error_handler']>[0],
|
|
@@ -561,13 +561,13 @@ export const attach_process_error_handler = (
|
|
|
561
561
|
/**
|
|
562
562
|
* Spawns a detached process that continues after parent exits.
|
|
563
563
|
*
|
|
564
|
-
* Unlike other spawn functions, this is NOT tracked in any ProcessRegistry
|
|
564
|
+
* Unlike other spawn functions, this is NOT tracked in any `ProcessRegistry`.
|
|
565
565
|
* The spawned process is meant to outlive the parent (e.g., daemon processes).
|
|
566
566
|
*
|
|
567
|
-
* @param command -
|
|
568
|
-
* @param args -
|
|
569
|
-
* @param options -
|
|
570
|
-
* @returns
|
|
567
|
+
* @param command - the command to run
|
|
568
|
+
* @param args - arguments to pass to the command
|
|
569
|
+
* @param options - spawn options (use `stdio` to redirect output to file descriptors)
|
|
570
|
+
* @returns result with pid on success, or error message on failure
|
|
571
571
|
*
|
|
572
572
|
* @example
|
|
573
573
|
* ```ts
|
|
@@ -820,7 +820,7 @@ export const spawn_restartable_process = (
|
|
|
820
820
|
* Checks if a process with the given PID is running.
|
|
821
821
|
* Uses signal 0 which checks existence without sending a signal.
|
|
822
822
|
*
|
|
823
|
-
* @param pid -
|
|
823
|
+
* @param pid - the process ID to check (must be a positive integer)
|
|
824
824
|
* @returns `true` if the process exists (even without permission to signal it),
|
|
825
825
|
* `false` if the process doesn't exist or if pid is invalid (non-positive, non-integer, NaN, Infinity)
|
|
826
826
|
*/
|
package/src/lib/random.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Random helpers that accept an optional `random` parameter,
|
|
3
3
|
* defaulting to `Math.random`. Pass a seeded PRNG for reproducible results:
|
|
4
4
|
*
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
5
|
+
* - `create_random_xoshiro` — fast, high-quality numeric seeding (recommended)
|
|
6
|
+
* - `create_random_alea` — supports string and variadic seeds
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
package/src/lib/result.ts
CHANGED
|
@@ -21,9 +21,9 @@ export const NOT_OK = Object.freeze({ok: false} as const);
|
|
|
21
21
|
* A helper that says,
|
|
22
22
|
* "hey I know this is wrapped in a `Result`, but I expect it to be `ok`,
|
|
23
23
|
* so if it's not, I understand it will throw an error that wraps the result".
|
|
24
|
-
* @param result
|
|
25
|
-
* @param message
|
|
26
|
-
* @returns
|
|
24
|
+
* @param result - some `Result` object
|
|
25
|
+
* @param message - optional custom error message
|
|
26
|
+
* @returns the wrapped value
|
|
27
27
|
*/
|
|
28
28
|
export const unwrap = <TValue extends {value?: unknown}, TError extends {message?: string}>(
|
|
29
29
|
result: Result<TValue, TError>,
|
|
@@ -54,9 +54,9 @@ export class ResultError extends Error {
|
|
|
54
54
|
/**
|
|
55
55
|
* A helper that does the opposite of `unwrap`, throwing if the `Result` is ok.
|
|
56
56
|
* Note that while `unwrap` returns the wrapped `value`, `unwrap_error` returns the entire result.
|
|
57
|
-
* @param result
|
|
58
|
-
* @param message
|
|
59
|
-
* @returns
|
|
57
|
+
* @param result - some `Result` object
|
|
58
|
+
* @param message - optional custom error message
|
|
59
|
+
* @returns the type-narrowed result
|
|
60
60
|
*/
|
|
61
61
|
export const unwrap_error = <TError extends object>(
|
|
62
62
|
result: Result<object, TError>,
|
package/src/lib/sort.ts
CHANGED
|
@@ -28,9 +28,9 @@ export type TopologicalSortResult<T extends Sortable> =
|
|
|
28
28
|
* Returns items ordered so that dependencies come before dependents.
|
|
29
29
|
* If a cycle is detected, returns an error with the cycle path.
|
|
30
30
|
*
|
|
31
|
-
* @param items -
|
|
32
|
-
* @param label -
|
|
33
|
-
* @returns
|
|
31
|
+
* @param items - array of items to sort
|
|
32
|
+
* @param label - label for error messages (e.g. "resource", "step")
|
|
33
|
+
* @returns sorted items or error if cycle detected
|
|
34
34
|
*/
|
|
35
35
|
export const topological_sort = <T extends Sortable>(
|
|
36
36
|
items: Array<T>,
|
package/src/lib/source_json.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* extracted at build time via TypeScript compiler analysis.
|
|
6
6
|
* Used for generating API documentation and enabling code search.
|
|
7
7
|
*
|
|
8
|
-
* Hierarchy: SourceJson → ModuleJson → DeclarationJson
|
|
8
|
+
* Hierarchy: `SourceJson` → `ModuleJson` → `DeclarationJson`
|
|
9
9
|
*
|
|
10
10
|
* @module
|
|
11
11
|
*/
|
|
@@ -43,7 +43,7 @@ export type GenericParamInfo = z.infer<typeof GenericParamInfo>;
|
|
|
43
43
|
/**
|
|
44
44
|
* Parameter information for functions and methods.
|
|
45
45
|
*
|
|
46
|
-
* Kept distinct from ComponentPropInfo despite structural similarity.
|
|
46
|
+
* Kept distinct from `ComponentPropInfo` despite structural similarity.
|
|
47
47
|
* Function parameters form a tuple with positional semantics:
|
|
48
48
|
* calling order matters (`fn(a, b)` vs `fn(b, a)`),
|
|
49
49
|
* may include rest parameters and destructuring patterns.
|
|
@@ -60,7 +60,7 @@ export type ParameterInfo = z.infer<typeof ParameterInfo>;
|
|
|
60
60
|
/**
|
|
61
61
|
* Component prop information for Svelte components.
|
|
62
62
|
*
|
|
63
|
-
* Kept distinct from ParameterInfo despite structural similarity.
|
|
63
|
+
* Kept distinct from `ParameterInfo` despite structural similarity.
|
|
64
64
|
* Component props are named attributes with different semantics:
|
|
65
65
|
* no positional order when passing (`<Foo {a} {b} />` = `<Foo {b} {a} />`),
|
|
66
66
|
* support two-way binding via `$bindable` rune.
|
package/src/lib/stats.ts
CHANGED
|
@@ -59,8 +59,8 @@ export const stats_variance = (values: Array<number>, mean?: number): number =>
|
|
|
59
59
|
* Calculate a percentile of an array of numbers using linear interpolation.
|
|
60
60
|
* Uses the "R-7" method (default in R, NumPy, Excel) which interpolates between
|
|
61
61
|
* data points for more accurate percentile estimates, especially with smaller samples.
|
|
62
|
-
* @param values -
|
|
63
|
-
* @param p -
|
|
62
|
+
* @param values - array of numbers
|
|
63
|
+
* @param p - percentile (0-1, e.g., 0.95 for 95th percentile)
|
|
64
64
|
*/
|
|
65
65
|
export const stats_percentile = (values: Array<number>, p: number): number => {
|
|
66
66
|
if (values.length === 0) return NaN;
|
|
@@ -329,8 +329,8 @@ export interface StatsConfidenceIntervalOptions {
|
|
|
329
329
|
|
|
330
330
|
/**
|
|
331
331
|
* Calculate confidence interval for the mean.
|
|
332
|
-
* @param values -
|
|
333
|
-
* @param options -
|
|
332
|
+
* @param values - array of numbers
|
|
333
|
+
* @param options - configuration options
|
|
334
334
|
* @returns [lower_bound, upper_bound]
|
|
335
335
|
*/
|
|
336
336
|
export const stats_confidence_interval = (
|
|
@@ -348,10 +348,10 @@ export const stats_confidence_interval = (
|
|
|
348
348
|
/**
|
|
349
349
|
* Calculate confidence interval from summary statistics (mean, std_dev, sample_size).
|
|
350
350
|
* Useful when raw data is not available.
|
|
351
|
-
* @param mean -
|
|
352
|
-
* @param std_dev -
|
|
353
|
-
* @param sample_size -
|
|
354
|
-
* @param options -
|
|
351
|
+
* @param mean - mean of the data
|
|
352
|
+
* @param std_dev - standard deviation of the data
|
|
353
|
+
* @param sample_size - number of samples
|
|
354
|
+
* @param options - configuration options
|
|
355
355
|
* @returns [lower_bound, upper_bound]
|
|
356
356
|
*/
|
|
357
357
|
export const stats_confidence_interval_from_summary = (
|
|
@@ -393,12 +393,12 @@ export interface StatsWelchTTestResult {
|
|
|
393
393
|
* Calculate Welch's t-test statistic and degrees of freedom.
|
|
394
394
|
* Welch's t-test is more robust than Student's t-test when variances are unequal.
|
|
395
395
|
*
|
|
396
|
-
* @param mean1 -
|
|
397
|
-
* @param std1 -
|
|
398
|
-
* @param n1 -
|
|
399
|
-
* @param mean2 -
|
|
400
|
-
* @param std2 -
|
|
401
|
-
* @param n2 -
|
|
396
|
+
* @param mean1 - mean of first sample
|
|
397
|
+
* @param std1 - standard deviation of first sample
|
|
398
|
+
* @param n1 - size of first sample
|
|
399
|
+
* @param mean2 - mean of second sample
|
|
400
|
+
* @param std2 - standard deviation of second sample
|
|
401
|
+
* @param n2 - size of second sample
|
|
402
402
|
*/
|
|
403
403
|
export const stats_welch_t_test = (
|
|
404
404
|
mean1: number,
|
|
@@ -516,9 +516,9 @@ export const stats_incomplete_beta = (x: number, a: number, b: number): number =
|
|
|
516
516
|
* For large df (>100), uses normal approximation.
|
|
517
517
|
* For smaller df, uses incomplete beta function.
|
|
518
518
|
*
|
|
519
|
-
* @param t -
|
|
520
|
-
* @param df -
|
|
521
|
-
* @returns
|
|
519
|
+
* @param t - absolute value of t-statistic
|
|
520
|
+
* @param df - degrees of freedom
|
|
521
|
+
* @returns two-tailed p-value
|
|
522
522
|
*/
|
|
523
523
|
export const stats_t_distribution_p_value = (t: number, df: number): number => {
|
|
524
524
|
// Use normal approximation for large df
|
package/src/lib/string.ts
CHANGED
|
@@ -86,7 +86,7 @@ export const count_graphemes = (str: string): number =>
|
|
|
86
86
|
count_iterator(new Intl.Segmenter().segment(str));
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
* Strips ANSI escape sequences from a string
|
|
89
|
+
* Strips ANSI escape sequences from a string.
|
|
90
90
|
*/
|
|
91
91
|
export const strip_ansi = (str: string): string => str.replaceAll(/\x1B\[[0-9;]*[a-zA-Z]/g, ''); // eslint-disable-line no-control-regex
|
|
92
92
|
|
|
@@ -168,9 +168,9 @@ export const pad_width = (
|
|
|
168
168
|
* Calculates the Levenshtein distance between two strings.
|
|
169
169
|
* Useful for typo detection and fuzzy matching.
|
|
170
170
|
*
|
|
171
|
-
* @param a -
|
|
172
|
-
* @param b -
|
|
173
|
-
* @returns
|
|
171
|
+
* @param a - first string
|
|
172
|
+
* @param b - second string
|
|
173
|
+
* @returns the edit distance between the strings
|
|
174
174
|
*/
|
|
175
175
|
export const levenshtein_distance = (a: string, b: string): number => {
|
|
176
176
|
if (a.length === 0) return b.length;
|
|
@@ -240,7 +240,7 @@ export const escape_js_string = (value: string): string =>
|
|
|
240
240
|
*
|
|
241
241
|
* Checks for null bytes in the first 8KB of content.
|
|
242
242
|
*
|
|
243
|
-
* @param content -
|
|
244
|
-
* @returns
|
|
243
|
+
* @param content - content to check
|
|
244
|
+
* @returns true if content appears to be binary
|
|
245
245
|
*/
|
|
246
246
|
export const string_is_binary = (content: string): boolean => content.slice(0, 8192).includes('\0');
|
|
@@ -44,9 +44,9 @@ export interface ResolvedComponentImport {
|
|
|
44
44
|
* Iterates the node's `attributes` array and returns the first `Attribute`
|
|
45
45
|
* node whose `name` matches. Skips `SpreadAttribute`, directive, and other node types.
|
|
46
46
|
*
|
|
47
|
-
* @param node
|
|
48
|
-
* @param name
|
|
49
|
-
* @returns
|
|
47
|
+
* @param node - the component AST node to search
|
|
48
|
+
* @param name - the attribute name to find
|
|
49
|
+
* @returns the matching `Attribute` node, or `undefined` if not found
|
|
50
50
|
*/
|
|
51
51
|
export const find_attribute = (node: AST.Component, name: string): AST.Attribute | undefined => {
|
|
52
52
|
for (const attr of node.attributes) {
|
|
@@ -65,9 +65,9 @@ export const find_attribute = (node: AST.Component, name: string): AST.Attribute
|
|
|
65
65
|
* via an optional bindings map built by `build_static_bindings`.
|
|
66
66
|
* Returns `null` for dynamic expressions, non-string literals, or unsupported node types.
|
|
67
67
|
*
|
|
68
|
-
* @param expr
|
|
69
|
-
* @param bindings
|
|
70
|
-
* @returns
|
|
68
|
+
* @param expr - an ESTree expression AST node
|
|
69
|
+
* @param bindings - optional map of variable names to their resolved static string values
|
|
70
|
+
* @returns the resolved static string, or `null` if the expression is dynamic
|
|
71
71
|
*/
|
|
72
72
|
export const evaluate_static_expr = (
|
|
73
73
|
expr: Expression,
|
|
@@ -116,9 +116,9 @@ export const evaluate_static_expr = (
|
|
|
116
116
|
*
|
|
117
117
|
* Returns `null` for null literals, mixed arrays, dynamic expressions, and non-string values.
|
|
118
118
|
*
|
|
119
|
-
* @param value
|
|
120
|
-
* @param bindings
|
|
121
|
-
* @returns
|
|
119
|
+
* @param value - the attribute value from `AST.Attribute['value']`
|
|
120
|
+
* @param bindings - optional map of variable names to their resolved static string values
|
|
121
|
+
* @returns the resolved static string, or `null` if the value is dynamic
|
|
122
122
|
*/
|
|
123
123
|
export const extract_static_string = (
|
|
124
124
|
value: AST.Attribute['value'],
|
|
@@ -165,10 +165,10 @@ export interface ConditionalChainBranch {
|
|
|
165
165
|
*
|
|
166
166
|
* A 2-branch result covers the simple ternary case (`a ? 'x' : 'y'`).
|
|
167
167
|
*
|
|
168
|
-
* @param value
|
|
169
|
-
* @param source
|
|
170
|
-
* @param bindings
|
|
171
|
-
* @returns
|
|
168
|
+
* @param value - the attribute value from `AST.Attribute['value']`
|
|
169
|
+
* @param source - the full source string (needed to slice test expression source text)
|
|
170
|
+
* @param bindings - map of variable names to their resolved static string values
|
|
171
|
+
* @returns array of conditional chain branches, or `null` if not extractable
|
|
172
172
|
*/
|
|
173
173
|
export const try_extract_conditional_chain = (
|
|
174
174
|
value: AST.Attribute['value'],
|
|
@@ -223,8 +223,8 @@ export const try_extract_conditional_chain = (
|
|
|
223
223
|
* Skips destructuring patterns, `let`/`var` declarations, and declarations
|
|
224
224
|
* whose initializers reference dynamic values.
|
|
225
225
|
*
|
|
226
|
-
* @param ast
|
|
227
|
-
* @returns
|
|
226
|
+
* @param ast - the parsed Svelte AST root node
|
|
227
|
+
* @returns map of variable names to their resolved static string values
|
|
228
228
|
*/
|
|
229
229
|
export const build_static_bindings = (ast: AST.Root): Map<string, string> => {
|
|
230
230
|
const bindings: Map<string, string> = new Map();
|
|
@@ -253,9 +253,9 @@ export const build_static_bindings = (ast: AST.Root): Map<string, string> => {
|
|
|
253
253
|
* and `import type` declarations (both whole-declaration and per-specifier).
|
|
254
254
|
* Returns import node references alongside names to support import removal.
|
|
255
255
|
*
|
|
256
|
-
* @param ast
|
|
257
|
-
* @param component_imports
|
|
258
|
-
* @returns
|
|
256
|
+
* @param ast - the parsed Svelte AST root node
|
|
257
|
+
* @param component_imports - array of import source paths to match against
|
|
258
|
+
* @returns map of local names to their resolved import info
|
|
259
259
|
*/
|
|
260
260
|
export const resolve_component_names = (
|
|
261
261
|
ast: AST.Root,
|
|
@@ -287,8 +287,8 @@ export const resolve_component_names = (
|
|
|
287
287
|
* Returns the end position of the last `ImportDeclaration`, or the start
|
|
288
288
|
* of the script body content if no imports exist.
|
|
289
289
|
*
|
|
290
|
-
* @param script
|
|
291
|
-
* @returns
|
|
290
|
+
* @param script - the parsed `AST.Script` node
|
|
291
|
+
* @returns the character position where new imports should be inserted
|
|
292
292
|
*/
|
|
293
293
|
export const find_import_insert_position = (script: AST.Script): number => {
|
|
294
294
|
let last_import_end = -1;
|
|
@@ -310,9 +310,9 @@ export const find_import_insert_position = (script: AST.Script): number => {
|
|
|
310
310
|
* Default imports produce `import Name from 'path';` lines.
|
|
311
311
|
* Named imports are grouped by path into `import {a, b} from 'path';` lines.
|
|
312
312
|
*
|
|
313
|
-
* @param imports
|
|
314
|
-
* @param indent
|
|
315
|
-
* @returns
|
|
313
|
+
* @param imports - map of local names to their import info
|
|
314
|
+
* @param indent - indentation prefix for each line @default '\t'
|
|
315
|
+
* @returns a string of newline-separated import statements
|
|
316
316
|
*/
|
|
317
317
|
export const generate_import_lines = (
|
|
318
318
|
imports: Map<string, PreprocessImportInfo>,
|
|
@@ -383,10 +383,10 @@ const NON_REFERENCE_FIELDS: Map<
|
|
|
383
383
|
* Safe for Svelte template ASTs: `Component.name` is a plain string property
|
|
384
384
|
* (not an `Identifier` node), so `<Mdz>` tags do not produce false matches.
|
|
385
385
|
*
|
|
386
|
-
* @param node
|
|
387
|
-
* @param name
|
|
388
|
-
* @param skip
|
|
389
|
-
* @returns `true` if a matching `Identifier` node is found
|
|
386
|
+
* @param node - the AST subtree to search
|
|
387
|
+
* @param name - the identifier name to look for
|
|
388
|
+
* @param skip - set of AST nodes to skip during traversal
|
|
389
|
+
* @returns `true` if a matching `Identifier` node is found
|
|
390
390
|
*/
|
|
391
391
|
export const has_identifier_in_tree = (
|
|
392
392
|
node: unknown,
|
|
@@ -449,9 +449,9 @@ export const escape_svelte_text = (text: string): string =>
|
|
|
449
449
|
* blank lines. Only safe for single-declarator statements (`const x = 'val';`);
|
|
450
450
|
* callers must verify `node.declarations.length === 1` before calling.
|
|
451
451
|
*
|
|
452
|
-
* @param s
|
|
453
|
-
* @param declaration_node
|
|
454
|
-
* @param source
|
|
452
|
+
* @param s - the MagicString instance to modify
|
|
453
|
+
* @param declaration_node - the `VariableDeclaration` AST node with Svelte position data
|
|
454
|
+
* @param source - the original source string
|
|
455
455
|
*/
|
|
456
456
|
export const remove_variable_declaration = (
|
|
457
457
|
s: {remove: (start: number, end: number) => unknown},
|
|
@@ -467,9 +467,9 @@ export const remove_variable_declaration = (
|
|
|
467
467
|
* Consumes leading whitespace (tabs/spaces) and trailing newline to avoid leaving
|
|
468
468
|
* blank lines.
|
|
469
469
|
*
|
|
470
|
-
* @param s
|
|
471
|
-
* @param import_node
|
|
472
|
-
* @param source
|
|
470
|
+
* @param s - the MagicString instance to modify
|
|
471
|
+
* @param import_node - the `ImportDeclaration` AST node with Svelte position data
|
|
472
|
+
* @param source - the original source string
|
|
473
473
|
*/
|
|
474
474
|
export const remove_import_declaration = (
|
|
475
475
|
s: {remove: (start: number, end: number) => unknown},
|
|
@@ -520,11 +520,11 @@ const remove_positioned_node = (
|
|
|
520
520
|
* - `import {default as Mdz, other} from '...'` → `import {other} from '...'`
|
|
521
521
|
* - `import {Mdz, other} from '...'` → `import {other} from '...'`
|
|
522
522
|
*
|
|
523
|
-
* @param s
|
|
524
|
-
* @param node
|
|
525
|
-
* @param specifier_to_remove
|
|
526
|
-
* @param source
|
|
527
|
-
* @param additional_lines
|
|
523
|
+
* @param s - the MagicString instance to modify
|
|
524
|
+
* @param node - the positioned `ImportDeclaration` AST node
|
|
525
|
+
* @param specifier_to_remove - the specifier to remove from the import
|
|
526
|
+
* @param source - the original source string
|
|
527
|
+
* @param additional_lines - extra content appended after the reconstructed import
|
|
528
528
|
* (used to bundle new imports into the overwrite to avoid MagicString boundary conflicts).
|
|
529
529
|
*/
|
|
530
530
|
export const remove_import_specifier = (
|
|
@@ -585,10 +585,10 @@ const format_named_specifiers = (specs: Array<ImportDeclaration['specifiers'][nu
|
|
|
585
585
|
/**
|
|
586
586
|
* Handles errors during Svelte preprocessing with configurable behavior.
|
|
587
587
|
*
|
|
588
|
-
* @param error
|
|
589
|
-
* @param prefix
|
|
590
|
-
* @param filename
|
|
591
|
-
* @param on_error `'throw'` to re-throw as a new Error, `'log'` to console.error
|
|
588
|
+
* @param error - the caught error
|
|
589
|
+
* @param prefix - log prefix (e.g. `'[fuz-mdz]'`, `'[fuz-code]'`)
|
|
590
|
+
* @param filename - the file being processed
|
|
591
|
+
* @param on_error - `'throw'` to re-throw as a new Error, `'log'` to console.error
|
|
592
592
|
*/
|
|
593
593
|
export const handle_preprocess_error = (
|
|
594
594
|
error: unknown,
|