@fuzdev/fuz_util 0.54.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.
Files changed (106) hide show
  1. package/dist/args.d.ts +12 -12
  2. package/dist/args.js +11 -11
  3. package/dist/async.d.ts +12 -12
  4. package/dist/async.js +12 -12
  5. package/dist/benchmark.d.ts +24 -24
  6. package/dist/benchmark.js +26 -26
  7. package/dist/benchmark_baseline.d.ts +17 -11
  8. package/dist/benchmark_baseline.d.ts.map +1 -1
  9. package/dist/benchmark_baseline.js +26 -19
  10. package/dist/benchmark_format.d.ts +15 -15
  11. package/dist/benchmark_format.js +15 -15
  12. package/dist/benchmark_stats.d.ts +30 -10
  13. package/dist/benchmark_stats.d.ts.map +1 -1
  14. package/dist/benchmark_stats.js +48 -40
  15. package/dist/benchmark_types.d.ts +7 -7
  16. package/dist/bytes.d.ts +4 -4
  17. package/dist/bytes.js +4 -4
  18. package/dist/dag.d.ts +2 -2
  19. package/dist/dag.js +2 -2
  20. package/dist/deep_equal.d.ts +2 -2
  21. package/dist/deep_equal.js +2 -2
  22. package/dist/diff.d.ts +17 -17
  23. package/dist/diff.js +17 -17
  24. package/dist/dom.d.ts +4 -4
  25. package/dist/dom.js +4 -4
  26. package/dist/fetch.d.ts +1 -1
  27. package/dist/fetch.js +1 -1
  28. package/dist/git.d.ts +1 -1
  29. package/dist/git.js +1 -1
  30. package/dist/hash.d.ts +6 -6
  31. package/dist/hash.js +8 -8
  32. package/dist/hash_blake3.d.ts +1 -1
  33. package/dist/hash_blake3.js +1 -1
  34. package/dist/hex.d.ts +4 -4
  35. package/dist/hex.js +4 -4
  36. package/dist/json.d.ts +2 -2
  37. package/dist/json.js +2 -2
  38. package/dist/log.d.ts +12 -12
  39. package/dist/log.js +11 -11
  40. package/dist/map.d.ts +1 -1
  41. package/dist/map.js +1 -1
  42. package/dist/object.d.ts +1 -1
  43. package/dist/object.js +1 -1
  44. package/dist/package_json.d.ts +1 -1
  45. package/dist/package_json.js +1 -1
  46. package/dist/path.d.ts +5 -5
  47. package/dist/path.js +5 -5
  48. package/dist/process.d.ts +22 -22
  49. package/dist/process.js +22 -22
  50. package/dist/random.d.ts +2 -2
  51. package/dist/random.js +2 -2
  52. package/dist/result.d.ts +6 -6
  53. package/dist/result.js +6 -6
  54. package/dist/sort.d.ts +3 -3
  55. package/dist/sort.js +3 -3
  56. package/dist/source_json.d.ts +3 -3
  57. package/dist/source_json.js +3 -3
  58. package/dist/stats.d.ts +17 -17
  59. package/dist/stats.js +17 -17
  60. package/dist/string.d.ts +6 -6
  61. package/dist/string.js +6 -6
  62. package/dist/svelte_preprocess_helpers.d.ts +42 -42
  63. package/dist/svelte_preprocess_helpers.js +42 -42
  64. package/dist/testing.d.ts +44 -0
  65. package/dist/testing.d.ts.map +1 -0
  66. package/dist/testing.js +59 -0
  67. package/dist/time.d.ts +19 -19
  68. package/dist/time.js +19 -19
  69. package/dist/zod.d.ts +16 -16
  70. package/dist/zod.d.ts.map +1 -1
  71. package/dist/zod.js +24 -24
  72. package/package.json +6 -6
  73. package/src/lib/args.ts +12 -12
  74. package/src/lib/async.ts +12 -12
  75. package/src/lib/benchmark.ts +28 -28
  76. package/src/lib/benchmark_baseline.ts +37 -20
  77. package/src/lib/benchmark_format.ts +15 -15
  78. package/src/lib/benchmark_stats.ts +66 -44
  79. package/src/lib/benchmark_types.ts +7 -7
  80. package/src/lib/bytes.ts +4 -4
  81. package/src/lib/dag.ts +2 -2
  82. package/src/lib/deep_equal.ts +2 -2
  83. package/src/lib/diff.ts +17 -17
  84. package/src/lib/dom.ts +4 -4
  85. package/src/lib/fetch.ts +1 -1
  86. package/src/lib/git.ts +1 -1
  87. package/src/lib/hash.ts +8 -8
  88. package/src/lib/hash_blake3.ts +1 -1
  89. package/src/lib/hex.ts +4 -4
  90. package/src/lib/json.ts +2 -2
  91. package/src/lib/log.ts +12 -12
  92. package/src/lib/map.ts +1 -1
  93. package/src/lib/object.ts +1 -1
  94. package/src/lib/package_json.ts +1 -1
  95. package/src/lib/path.ts +5 -5
  96. package/src/lib/process.ts +22 -22
  97. package/src/lib/random.ts +2 -2
  98. package/src/lib/result.ts +6 -6
  99. package/src/lib/sort.ts +3 -3
  100. package/src/lib/source_json.ts +3 -3
  101. package/src/lib/stats.ts +17 -17
  102. package/src/lib/string.ts +6 -6
  103. package/src/lib/svelte_preprocess_helpers.ts +42 -42
  104. package/src/lib/testing.ts +80 -0
  105. package/src/lib/time.ts +19 -19
  106. package/src/lib/zod.ts +24 -24
@@ -33,9 +33,9 @@ export interface ResolvedComponentImport {
33
33
  * Iterates the node's `attributes` array and returns the first `Attribute`
34
34
  * node whose `name` matches. Skips `SpreadAttribute`, directive, and other node types.
35
35
  *
36
- * @param node The component AST node to search.
37
- * @param name The attribute name to find.
38
- * @returns The matching `Attribute` node, or `undefined` if not found.
36
+ * @param node - the component AST node to search
37
+ * @param name - the attribute name to find
38
+ * @returns the matching `Attribute` node, or `undefined` if not found
39
39
  */
40
40
  export declare const find_attribute: (node: AST.Component, name: string) => AST.Attribute | undefined;
41
41
  /**
@@ -46,9 +46,9 @@ export declare const find_attribute: (node: AST.Component, name: string) => AST.
46
46
  * via an optional bindings map built by `build_static_bindings`.
47
47
  * Returns `null` for dynamic expressions, non-string literals, or unsupported node types.
48
48
  *
49
- * @param expr An ESTree expression AST node.
50
- * @param bindings Optional map of variable names to their resolved static string values.
51
- * @returns The resolved static string, or `null` if the expression is dynamic.
49
+ * @param expr - an ESTree expression AST node
50
+ * @param bindings - optional map of variable names to their resolved static string values
51
+ * @returns the resolved static string, or `null` if the expression is dynamic
52
52
  */
53
53
  export declare const evaluate_static_expr: (expr: Expression, bindings?: ReadonlyMap<string, string>) => string | null;
54
54
  /**
@@ -62,9 +62,9 @@ export declare const evaluate_static_expr: (expr: Expression, bindings?: Readonl
62
62
  *
63
63
  * Returns `null` for null literals, mixed arrays, dynamic expressions, and non-string values.
64
64
  *
65
- * @param value The attribute value from `AST.Attribute['value']`.
66
- * @param bindings Optional map of variable names to their resolved static string values.
67
- * @returns The resolved static string, or `null` if the value is dynamic.
65
+ * @param value - the attribute value from `AST.Attribute['value']`
66
+ * @param bindings - optional map of variable names to their resolved static string values
67
+ * @returns the resolved static string, or `null` if the value is dynamic
68
68
  */
69
69
  export declare const extract_static_string: (value: AST.Attribute["value"], bindings?: ReadonlyMap<string, string>) => string | null;
70
70
  /** A single branch in a conditional chain extracted from nested ternary expressions. */
@@ -88,10 +88,10 @@ export interface ConditionalChainBranch {
88
88
  *
89
89
  * A 2-branch result covers the simple ternary case (`a ? 'x' : 'y'`).
90
90
  *
91
- * @param value The attribute value from `AST.Attribute['value']`.
92
- * @param source The full source string (needed to slice test expression source text).
93
- * @param bindings Map of variable names to their resolved static string values.
94
- * @returns Array of conditional chain branches, or `null` if not extractable.
91
+ * @param value - the attribute value from `AST.Attribute['value']`
92
+ * @param source - the full source string (needed to slice test expression source text)
93
+ * @param bindings - map of variable names to their resolved static string values
94
+ * @returns array of conditional chain branches, or `null` if not extractable
95
95
  */
96
96
  export declare const try_extract_conditional_chain: (value: AST.Attribute["value"], source: string, bindings: ReadonlyMap<string, string>) => Array<ConditionalChainBranch> | null;
97
97
  /**
@@ -105,8 +105,8 @@ export declare const try_extract_conditional_chain: (value: AST.Attribute["value
105
105
  * Skips destructuring patterns, `let`/`var` declarations, and declarations
106
106
  * whose initializers reference dynamic values.
107
107
  *
108
- * @param ast The parsed Svelte AST root node.
109
- * @returns Map of variable names to their resolved static string values.
108
+ * @param ast - the parsed Svelte AST root node
109
+ * @returns map of variable names to their resolved static string values
110
110
  */
111
111
  export declare const build_static_bindings: (ast: AST.Root) => Map<string, string>;
112
112
  /**
@@ -117,9 +117,9 @@ export declare const build_static_bindings: (ast: AST.Root) => Map<string, strin
117
117
  * and `import type` declarations (both whole-declaration and per-specifier).
118
118
  * Returns import node references alongside names to support import removal.
119
119
  *
120
- * @param ast The parsed Svelte AST root node.
121
- * @param component_imports Array of import source paths to match against.
122
- * @returns Map of local names to their resolved import info.
120
+ * @param ast - the parsed Svelte AST root node
121
+ * @param component_imports - array of import source paths to match against
122
+ * @returns map of local names to their resolved import info
123
123
  */
124
124
  export declare const resolve_component_names: (ast: AST.Root, component_imports: Array<string>) => Map<string, ResolvedComponentImport>;
125
125
  /**
@@ -128,8 +128,8 @@ export declare const resolve_component_names: (ast: AST.Root, component_imports:
128
128
  * Returns the end position of the last `ImportDeclaration`, or the start
129
129
  * of the script body content if no imports exist.
130
130
  *
131
- * @param script The parsed `AST.Script` node.
132
- * @returns The character position where new imports should be inserted.
131
+ * @param script - the parsed `AST.Script` node
132
+ * @returns the character position where new imports should be inserted
133
133
  */
134
134
  export declare const find_import_insert_position: (script: AST.Script) => number;
135
135
  /**
@@ -138,9 +138,9 @@ export declare const find_import_insert_position: (script: AST.Script) => number
138
138
  * Default imports produce `import Name from 'path';` lines.
139
139
  * Named imports are grouped by path into `import {a, b} from 'path';` lines.
140
140
  *
141
- * @param imports Map of local names to their import info.
142
- * @param indent Indentation prefix for each line. @default '\t'
143
- * @returns A string of newline-separated import statements.
141
+ * @param imports - map of local names to their import info
142
+ * @param indent - indentation prefix for each line @default '\t'
143
+ * @returns a string of newline-separated import statements
144
144
  */
145
145
  export declare const generate_import_lines: (imports: Map<string, PreprocessImportInfo>, indent?: string) => string;
146
146
  /**
@@ -158,10 +158,10 @@ export declare const generate_import_lines: (imports: Map<string, PreprocessImpo
158
158
  * Safe for Svelte template ASTs: `Component.name` is a plain string property
159
159
  * (not an `Identifier` node), so `<Mdz>` tags do not produce false matches.
160
160
  *
161
- * @param node The AST subtree to search.
162
- * @param name The identifier name to look for.
163
- * @param skip Set of AST nodes to skip during traversal.
164
- * @returns `true` if a matching `Identifier` node is found.
161
+ * @param node - the AST subtree to search
162
+ * @param name - the identifier name to look for
163
+ * @param skip - set of AST nodes to skip during traversal
164
+ * @returns `true` if a matching `Identifier` node is found
165
165
  */
166
166
  export declare const has_identifier_in_tree: (node: unknown, name: string, skip?: Set<unknown>) => boolean;
167
167
  /**
@@ -188,9 +188,9 @@ export declare const escape_svelte_text: (text: string) => string;
188
188
  * blank lines. Only safe for single-declarator statements (`const x = 'val';`);
189
189
  * callers must verify `node.declarations.length === 1` before calling.
190
190
  *
191
- * @param s The MagicString instance to modify.
192
- * @param declaration_node The `VariableDeclaration` AST node with Svelte position data.
193
- * @param source The original source string.
191
+ * @param s - the MagicString instance to modify
192
+ * @param declaration_node - the `VariableDeclaration` AST node with Svelte position data
193
+ * @param source - the original source string
194
194
  */
195
195
  export declare const remove_variable_declaration: (s: {
196
196
  remove: (start: number, end: number) => unknown;
@@ -204,9 +204,9 @@ export declare const remove_variable_declaration: (s: {
204
204
  * Consumes leading whitespace (tabs/spaces) and trailing newline to avoid leaving
205
205
  * blank lines.
206
206
  *
207
- * @param s The MagicString instance to modify.
208
- * @param import_node The `ImportDeclaration` AST node with Svelte position data.
209
- * @param source The original source string.
207
+ * @param s - the MagicString instance to modify
208
+ * @param import_node - the `ImportDeclaration` AST node with Svelte position data
209
+ * @param source - the original source string
210
210
  */
211
211
  export declare const remove_import_declaration: (s: {
212
212
  remove: (start: number, end: number) => unknown;
@@ -225,11 +225,11 @@ export declare const remove_import_declaration: (s: {
225
225
  * - `import {default as Mdz, other} from '...'` → `import {other} from '...'`
226
226
  * - `import {Mdz, other} from '...'` → `import {other} from '...'`
227
227
  *
228
- * @param s The MagicString instance to modify.
229
- * @param node The positioned `ImportDeclaration` AST node.
230
- * @param specifier_to_remove The specifier to remove from the import.
231
- * @param source The original source string.
232
- * @param additional_lines Extra content appended after the reconstructed import
228
+ * @param s - the MagicString instance to modify
229
+ * @param node - the positioned `ImportDeclaration` AST node
230
+ * @param specifier_to_remove - the specifier to remove from the import
231
+ * @param source - the original source string
232
+ * @param additional_lines - extra content appended after the reconstructed import
233
233
  * (used to bundle new imports into the overwrite to avoid MagicString boundary conflicts).
234
234
  */
235
235
  export declare const remove_import_specifier: (s: {
@@ -241,10 +241,10 @@ export declare const remove_import_specifier: (s: {
241
241
  /**
242
242
  * Handles errors during Svelte preprocessing with configurable behavior.
243
243
  *
244
- * @param error The caught error.
245
- * @param prefix Log prefix (e.g. `'[fuz-mdz]'`, `'[fuz-code]'`).
246
- * @param filename The file being processed.
247
- * @param on_error `'throw'` to re-throw as a new Error, `'log'` to console.error.
244
+ * @param error - the caught error
245
+ * @param prefix - log prefix (e.g. `'[fuz-mdz]'`, `'[fuz-code]'`)
246
+ * @param filename - the file being processed
247
+ * @param on_error - `'throw'` to re-throw as a new Error, `'log'` to console.error
248
248
  */
249
249
  export declare const handle_preprocess_error: (error: unknown, prefix: string, filename: string | undefined, on_error: "throw" | "log") => void;
250
250
  //# sourceMappingURL=svelte_preprocess_helpers.d.ts.map
@@ -17,9 +17,9 @@
17
17
  * Iterates the node's `attributes` array and returns the first `Attribute`
18
18
  * node whose `name` matches. Skips `SpreadAttribute`, directive, and other node types.
19
19
  *
20
- * @param node The component AST node to search.
21
- * @param name The attribute name to find.
22
- * @returns The matching `Attribute` node, or `undefined` if not found.
20
+ * @param node - the component AST node to search
21
+ * @param name - the attribute name to find
22
+ * @returns the matching `Attribute` node, or `undefined` if not found
23
23
  */
24
24
  export const find_attribute = (node, name) => {
25
25
  for (const attr of node.attributes) {
@@ -37,9 +37,9 @@ export const find_attribute = (node, name) => {
37
37
  * via an optional bindings map built by `build_static_bindings`.
38
38
  * Returns `null` for dynamic expressions, non-string literals, or unsupported node types.
39
39
  *
40
- * @param expr An ESTree expression AST node.
41
- * @param bindings Optional map of variable names to their resolved static string values.
42
- * @returns The resolved static string, or `null` if the expression is dynamic.
40
+ * @param expr - an ESTree expression AST node
41
+ * @param bindings - optional map of variable names to their resolved static string values
42
+ * @returns the resolved static string, or `null` if the expression is dynamic
43
43
  */
44
44
  export const evaluate_static_expr = (expr, bindings) => {
45
45
  if (expr.type === 'Literal' && typeof expr.value === 'string')
@@ -89,9 +89,9 @@ export const evaluate_static_expr = (expr, bindings) => {
89
89
  *
90
90
  * Returns `null` for null literals, mixed arrays, dynamic expressions, and non-string values.
91
91
  *
92
- * @param value The attribute value from `AST.Attribute['value']`.
93
- * @param bindings Optional map of variable names to their resolved static string values.
94
- * @returns The resolved static string, or `null` if the value is dynamic.
92
+ * @param value - the attribute value from `AST.Attribute['value']`
93
+ * @param bindings - optional map of variable names to their resolved static string values
94
+ * @returns the resolved static string, or `null` if the value is dynamic
95
95
  */
96
96
  export const extract_static_string = (value, bindings) => {
97
97
  // Boolean attribute (e.g., <Mdz inline />)
@@ -126,10 +126,10 @@ export const extract_static_string = (value, bindings) => {
126
126
  *
127
127
  * A 2-branch result covers the simple ternary case (`a ? 'x' : 'y'`).
128
128
  *
129
- * @param value The attribute value from `AST.Attribute['value']`.
130
- * @param source The full source string (needed to slice test expression source text).
131
- * @param bindings Map of variable names to their resolved static string values.
132
- * @returns Array of conditional chain branches, or `null` if not extractable.
129
+ * @param value - the attribute value from `AST.Attribute['value']`
130
+ * @param source - the full source string (needed to slice test expression source text)
131
+ * @param bindings - map of variable names to their resolved static string values
132
+ * @returns array of conditional chain branches, or `null` if not extractable
133
133
  */
134
134
  export const try_extract_conditional_chain = (value, source, bindings) => {
135
135
  if (value === true || Array.isArray(value))
@@ -178,8 +178,8 @@ export const try_extract_conditional_chain = (value, source, bindings) => {
178
178
  * Skips destructuring patterns, `let`/`var` declarations, and declarations
179
179
  * whose initializers reference dynamic values.
180
180
  *
181
- * @param ast The parsed Svelte AST root node.
182
- * @returns Map of variable names to their resolved static string values.
181
+ * @param ast - the parsed Svelte AST root node
182
+ * @returns map of variable names to their resolved static string values
183
183
  */
184
184
  export const build_static_bindings = (ast) => {
185
185
  const bindings = new Map();
@@ -211,9 +211,9 @@ export const build_static_bindings = (ast) => {
211
211
  * and `import type` declarations (both whole-declaration and per-specifier).
212
212
  * Returns import node references alongside names to support import removal.
213
213
  *
214
- * @param ast The parsed Svelte AST root node.
215
- * @param component_imports Array of import source paths to match against.
216
- * @returns Map of local names to their resolved import info.
214
+ * @param ast - the parsed Svelte AST root node
215
+ * @param component_imports - array of import source paths to match against
216
+ * @returns map of local names to their resolved import info
217
217
  */
218
218
  export const resolve_component_names = (ast, component_imports) => {
219
219
  const names = new Map();
@@ -247,8 +247,8 @@ export const resolve_component_names = (ast, component_imports) => {
247
247
  * Returns the end position of the last `ImportDeclaration`, or the start
248
248
  * of the script body content if no imports exist.
249
249
  *
250
- * @param script The parsed `AST.Script` node.
251
- * @returns The character position where new imports should be inserted.
250
+ * @param script - the parsed `AST.Script` node
251
+ * @returns the character position where new imports should be inserted
252
252
  */
253
253
  export const find_import_insert_position = (script) => {
254
254
  let last_import_end = -1;
@@ -269,9 +269,9 @@ export const find_import_insert_position = (script) => {
269
269
  * Default imports produce `import Name from 'path';` lines.
270
270
  * Named imports are grouped by path into `import {a, b} from 'path';` lines.
271
271
  *
272
- * @param imports Map of local names to their import info.
273
- * @param indent Indentation prefix for each line. @default '\t'
274
- * @returns A string of newline-separated import statements.
272
+ * @param imports - map of local names to their import info
273
+ * @param indent - indentation prefix for each line @default '\t'
274
+ * @returns a string of newline-separated import statements
275
275
  */
276
276
  export const generate_import_lines = (imports, indent = '\t') => {
277
277
  const default_imports = [];
@@ -333,10 +333,10 @@ const NON_REFERENCE_FIELDS = new Map([
333
333
  * Safe for Svelte template ASTs: `Component.name` is a plain string property
334
334
  * (not an `Identifier` node), so `<Mdz>` tags do not produce false matches.
335
335
  *
336
- * @param node The AST subtree to search.
337
- * @param name The identifier name to look for.
338
- * @param skip Set of AST nodes to skip during traversal.
339
- * @returns `true` if a matching `Identifier` node is found.
336
+ * @param node - the AST subtree to search
337
+ * @param name - the identifier name to look for
338
+ * @param skip - set of AST nodes to skip during traversal
339
+ * @returns `true` if a matching `Identifier` node is found
340
340
  */
341
341
  export const has_identifier_in_tree = (node, name, skip) => {
342
342
  if (node === null || node === undefined || typeof node !== 'object')
@@ -396,9 +396,9 @@ export const escape_svelte_text = (text) => text.replace(/[{}<&]/g, (ch) => {
396
396
  * blank lines. Only safe for single-declarator statements (`const x = 'val';`);
397
397
  * callers must verify `node.declarations.length === 1` before calling.
398
398
  *
399
- * @param s The MagicString instance to modify.
400
- * @param declaration_node The `VariableDeclaration` AST node with Svelte position data.
401
- * @param source The original source string.
399
+ * @param s - the MagicString instance to modify
400
+ * @param declaration_node - the `VariableDeclaration` AST node with Svelte position data
401
+ * @param source - the original source string
402
402
  */
403
403
  export const remove_variable_declaration = (s, declaration_node, source) => {
404
404
  remove_positioned_node(s, declaration_node, source);
@@ -409,9 +409,9 @@ export const remove_variable_declaration = (s, declaration_node, source) => {
409
409
  * Consumes leading whitespace (tabs/spaces) and trailing newline to avoid leaving
410
410
  * blank lines.
411
411
  *
412
- * @param s The MagicString instance to modify.
413
- * @param import_node The `ImportDeclaration` AST node with Svelte position data.
414
- * @param source The original source string.
412
+ * @param s - the MagicString instance to modify
413
+ * @param import_node - the `ImportDeclaration` AST node with Svelte position data
414
+ * @param source - the original source string
415
415
  */
416
416
  export const remove_import_declaration = (s, import_node, source) => {
417
417
  remove_positioned_node(s, import_node, source);
@@ -450,11 +450,11 @@ const remove_positioned_node = (s, node, source) => {
450
450
  * - `import {default as Mdz, other} from '...'` → `import {other} from '...'`
451
451
  * - `import {Mdz, other} from '...'` → `import {other} from '...'`
452
452
  *
453
- * @param s The MagicString instance to modify.
454
- * @param node The positioned `ImportDeclaration` AST node.
455
- * @param specifier_to_remove The specifier to remove from the import.
456
- * @param source The original source string.
457
- * @param additional_lines Extra content appended after the reconstructed import
453
+ * @param s - the MagicString instance to modify
454
+ * @param node - the positioned `ImportDeclaration` AST node
455
+ * @param specifier_to_remove - the specifier to remove from the import
456
+ * @param source - the original source string
457
+ * @param additional_lines - extra content appended after the reconstructed import
458
458
  * (used to bundle new imports into the overwrite to avoid MagicString boundary conflicts).
459
459
  */
460
460
  export const remove_import_specifier = (s, node, specifier_to_remove, source, additional_lines = '') => {
@@ -501,10 +501,10 @@ const format_named_specifiers = (specs) => specs
501
501
  /**
502
502
  * Handles errors during Svelte preprocessing with configurable behavior.
503
503
  *
504
- * @param error The caught error.
505
- * @param prefix Log prefix (e.g. `'[fuz-mdz]'`, `'[fuz-code]'`).
506
- * @param filename The file being processed.
507
- * @param on_error `'throw'` to re-throw as a new Error, `'log'` to console.error.
504
+ * @param error - the caught error
505
+ * @param prefix - log prefix (e.g. `'[fuz-mdz]'`, `'[fuz-code]'`)
506
+ * @param filename - the file being processed
507
+ * @param on_error - `'throw'` to re-throw as a new Error, `'log'` to console.error
508
508
  */
509
509
  export const handle_preprocess_error = (error, prefix, filename, on_error) => {
510
510
  const message = `${prefix} Preprocessing failed${filename ? ` in ${filename}` : ''}: ${error instanceof Error ? error.message : String(error)}`;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Shared test assertions for the `@fuzdev` ecosystem.
3
+ *
4
+ * Extends the fuz-stack testing conventions (`assert` from vitest, tests in `src/test/`,
5
+ * plain object mocks) with reusable helpers for patterns that appear across multiple repos.
6
+ * Only depends on vitest — safe for fuz_util's zero-runtime-deps constraint.
7
+ *
8
+ * @module
9
+ */
10
+ import type { Logger } from './log.js';
11
+ /**
12
+ * Asserts that `fn` rejects with an `Error`.
13
+ * Optionally matches the error message against `pattern`.
14
+ * Returns the caught `Error` for further assertions by the caller.
15
+ *
16
+ * `assert.fail` is placed after the catch block so that assertion failures
17
+ * from the test itself are not swallowed by the catch.
18
+ *
19
+ * @param fn - async function expected to reject
20
+ * @param pattern - optional regex to match against the error message
21
+ * @returns the caught `Error`
22
+ */
23
+ export declare const assert_rejects: (fn: () => Promise<unknown>, pattern?: RegExp) => Promise<Error>;
24
+ /**
25
+ * A mock `Logger` with `vi.fn()` methods and call tracking arrays.
26
+ * Assignable to `Logger` for use in code under test.
27
+ * Each tracking array captures the first argument of each call.
28
+ * For full call details, use `vi.fn()` introspection on the methods directly.
29
+ */
30
+ export type MockLogger = Logger & {
31
+ error_calls: Array<unknown>;
32
+ warn_calls: Array<unknown>;
33
+ info_calls: Array<unknown>;
34
+ debug_calls: Array<unknown>;
35
+ };
36
+ /**
37
+ * Creates a mock `Logger` with `vi.fn()` on each logging method
38
+ * and tracking arrays for inspecting logged messages.
39
+ * Follows the fuz-stack convention of plain object mocks over mocking libraries.
40
+ *
41
+ * @returns a `MockLogger` assignable to `Logger`
42
+ */
43
+ export declare const create_mock_logger: () => MockLogger;
44
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAErC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAC1B,IAAI,MAAM,OAAO,CAAC,OAAO,CAAC,EAC1B,UAAU,MAAM,KACd,OAAO,CAAC,KAAK,CAWf,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IACjC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;CAC5B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,QAAO,UAiBrC,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Shared test assertions for the `@fuzdev` ecosystem.
3
+ *
4
+ * Extends the fuz-stack testing conventions (`assert` from vitest, tests in `src/test/`,
5
+ * plain object mocks) with reusable helpers for patterns that appear across multiple repos.
6
+ * Only depends on vitest — safe for fuz_util's zero-runtime-deps constraint.
7
+ *
8
+ * @module
9
+ */
10
+ import { assert, vi } from 'vitest';
11
+ /**
12
+ * Asserts that `fn` rejects with an `Error`.
13
+ * Optionally matches the error message against `pattern`.
14
+ * Returns the caught `Error` for further assertions by the caller.
15
+ *
16
+ * `assert.fail` is placed after the catch block so that assertion failures
17
+ * from the test itself are not swallowed by the catch.
18
+ *
19
+ * @param fn - async function expected to reject
20
+ * @param pattern - optional regex to match against the error message
21
+ * @returns the caught `Error`
22
+ */
23
+ export const assert_rejects = async (fn, pattern) => {
24
+ try {
25
+ await fn();
26
+ }
27
+ catch (err) {
28
+ assert(err instanceof Error, 'Expected rejection to be an Error');
29
+ if (pattern) {
30
+ assert.match(err.message, pattern);
31
+ }
32
+ return err;
33
+ }
34
+ assert.fail('Expected to throw');
35
+ };
36
+ /**
37
+ * Creates a mock `Logger` with `vi.fn()` on each logging method
38
+ * and tracking arrays for inspecting logged messages.
39
+ * Follows the fuz-stack convention of plain object mocks over mocking libraries.
40
+ *
41
+ * @returns a `MockLogger` assignable to `Logger`
42
+ */
43
+ export const create_mock_logger = () => {
44
+ const error_calls = [];
45
+ const warn_calls = [];
46
+ const info_calls = [];
47
+ const debug_calls = [];
48
+ return {
49
+ error: vi.fn((msg) => error_calls.push(msg)),
50
+ warn: vi.fn((msg) => warn_calls.push(msg)),
51
+ info: vi.fn((msg) => info_calls.push(msg)),
52
+ debug: vi.fn((msg) => debug_calls.push(msg)),
53
+ raw: vi.fn(),
54
+ error_calls,
55
+ warn_calls,
56
+ info_calls,
57
+ debug_calls,
58
+ };
59
+ };
package/dist/time.d.ts CHANGED
@@ -65,23 +65,23 @@ export declare const TIME_UNIT_DISPLAY: Record<TimeUnit, string>;
65
65
  /**
66
66
  * Detect the best time unit for a set of nanosecond values.
67
67
  * Chooses the unit where most values fall in the range 1-9999.
68
- * @param values_ns - Array of times in nanoseconds
69
- * @returns Best unit to use for all values
68
+ * @param values_ns - array of times in nanoseconds
69
+ * @returns best unit to use for all values
70
70
  */
71
71
  export declare const time_unit_detect_best: (values_ns: Array<number>) => TimeUnit;
72
72
  /**
73
73
  * Format time with a specific unit.
74
- * @param ns - Time in nanoseconds
75
- * @param unit - Unit to use ('ns', 'us', 'ms', 's')
76
- * @param decimals - Number of decimal places (default: 2)
77
- * @returns Formatted string like "3.87μs"
74
+ * @param ns - time in nanoseconds
75
+ * @param unit - unit to use ('ns', 'us', 'ms', 's')
76
+ * @param decimals - number of decimal places (default: 2)
77
+ * @returns formatted string like "3.87μs"
78
78
  */
79
79
  export declare const time_format: (ns: number, unit: TimeUnit, decimals?: number) => string;
80
80
  /**
81
81
  * Format time with adaptive units (ns/μs/ms/s) based on magnitude.
82
- * @param ns - Time in nanoseconds
83
- * @param decimals - Number of decimal places (default: 2)
84
- * @returns Formatted string like "3.87μs" or "1.23ms"
82
+ * @param ns - time in nanoseconds
83
+ * @param decimals - number of decimal places (default: 2)
84
+ * @returns formatted string like "3.87μs" or "1.23ms"
85
85
  *
86
86
  * @example
87
87
  * ```ts
@@ -110,9 +110,9 @@ export interface TimeResult {
110
110
  }
111
111
  /**
112
112
  * Time an asynchronous function execution.
113
- * @param fn - Async function to time
114
- * @param timer - Timer to use (defaults to timer_default)
115
- * @returns Object containing the function result and timing information
113
+ * @param fn - async function to time
114
+ * @param timer - timer to use (defaults to `timer_default`)
115
+ * @returns object containing the function result and timing information
116
116
  *
117
117
  * @example
118
118
  * ```ts
@@ -129,9 +129,9 @@ export declare const time_async: <T>(fn: () => Promise<T>, timer?: Timer) => Pro
129
129
  }>;
130
130
  /**
131
131
  * Time a synchronous function execution.
132
- * @param fn - Sync function to time
133
- * @param timer - Timer to use (defaults to timer_default)
134
- * @returns Object containing the function result and timing information
132
+ * @param fn - sync function to time
133
+ * @param timer - timer to use (defaults to `timer_default`)
134
+ * @returns object containing the function result and timing information
135
135
  *
136
136
  * @example
137
137
  * ```ts
@@ -147,10 +147,10 @@ export declare const time_sync: <T>(fn: () => T, timer?: Timer) => {
147
147
  };
148
148
  /**
149
149
  * Measure multiple executions of a function and return all timings.
150
- * @param fn - Function to measure (sync or async)
151
- * @param iterations - Number of times to execute
152
- * @param timer - Timer to use (defaults to timer_default)
153
- * @returns Array of elapsed times in nanoseconds
150
+ * @param fn - function to measure (sync or async)
151
+ * @param iterations - number of times to execute
152
+ * @param timer - timer to use (defaults to `timer_default`)
153
+ * @returns array of elapsed times in nanoseconds
154
154
  *
155
155
  * @example
156
156
  * ```ts
package/dist/time.js CHANGED
@@ -96,8 +96,8 @@ export const TIME_UNIT_DISPLAY = { ns: 'ns', us: 'μs', ms: 'ms', s: 's' };
96
96
  /**
97
97
  * Detect the best time unit for a set of nanosecond values.
98
98
  * Chooses the unit where most values fall in the range 1-9999.
99
- * @param values_ns - Array of times in nanoseconds
100
- * @returns Best unit to use for all values
99
+ * @param values_ns - array of times in nanoseconds
100
+ * @returns best unit to use for all values
101
101
  */
102
102
  export const time_unit_detect_best = (values_ns) => {
103
103
  if (values_ns.length === 0)
@@ -125,10 +125,10 @@ export const time_unit_detect_best = (values_ns) => {
125
125
  };
126
126
  /**
127
127
  * Format time with a specific unit.
128
- * @param ns - Time in nanoseconds
129
- * @param unit - Unit to use ('ns', 'us', 'ms', 's')
130
- * @param decimals - Number of decimal places (default: 2)
131
- * @returns Formatted string like "3.87μs"
128
+ * @param ns - time in nanoseconds
129
+ * @param unit - unit to use ('ns', 'us', 'ms', 's')
130
+ * @param decimals - number of decimal places (default: 2)
131
+ * @returns formatted string like "3.87μs"
132
132
  */
133
133
  export const time_format = (ns, unit, decimals = 2) => {
134
134
  if (!isFinite(ns))
@@ -146,9 +146,9 @@ export const time_format = (ns, unit, decimals = 2) => {
146
146
  };
147
147
  /**
148
148
  * Format time with adaptive units (ns/μs/ms/s) based on magnitude.
149
- * @param ns - Time in nanoseconds
150
- * @param decimals - Number of decimal places (default: 2)
151
- * @returns Formatted string like "3.87μs" or "1.23ms"
149
+ * @param ns - time in nanoseconds
150
+ * @param decimals - number of decimal places (default: 2)
151
+ * @returns formatted string like "3.87μs" or "1.23ms"
152
152
  *
153
153
  * @example
154
154
  * ```ts
@@ -177,9 +177,9 @@ export const time_format_adaptive = (ns, decimals = 2) => {
177
177
  };
178
178
  /**
179
179
  * Time an asynchronous function execution.
180
- * @param fn - Async function to time
181
- * @param timer - Timer to use (defaults to timer_default)
182
- * @returns Object containing the function result and timing information
180
+ * @param fn - async function to time
181
+ * @param timer - timer to use (defaults to `timer_default`)
182
+ * @returns object containing the function result and timing information
183
183
  *
184
184
  * @example
185
185
  * ```ts
@@ -208,9 +208,9 @@ export const time_async = async (fn, timer = timer_default) => {
208
208
  };
209
209
  /**
210
210
  * Time a synchronous function execution.
211
- * @param fn - Sync function to time
212
- * @param timer - Timer to use (defaults to timer_default)
213
- * @returns Object containing the function result and timing information
211
+ * @param fn - sync function to time
212
+ * @param timer - timer to use (defaults to `timer_default`)
213
+ * @returns object containing the function result and timing information
214
214
  *
215
215
  * @example
216
216
  * ```ts
@@ -238,10 +238,10 @@ export const time_sync = (fn, timer = timer_default) => {
238
238
  };
239
239
  /**
240
240
  * Measure multiple executions of a function and return all timings.
241
- * @param fn - Function to measure (sync or async)
242
- * @param iterations - Number of times to execute
243
- * @param timer - Timer to use (defaults to timer_default)
244
- * @returns Array of elapsed times in nanoseconds
241
+ * @param fn - function to measure (sync or async)
242
+ * @param iterations - number of times to execute
243
+ * @param timer - timer to use (defaults to `timer_default`)
244
+ * @returns array of elapsed times in nanoseconds
245
245
  *
246
246
  * @example
247
247
  * ```ts