tape-six 1.7.13 → 1.7.14

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.
@@ -0,0 +1,219 @@
1
+ // Type definitions for deep6 walk
2
+ // Generated from src/traverse/walk.js
3
+
4
+ /**
5
+ * Context object available during walk traversal
6
+ */
7
+ export interface WalkContext {
8
+ /** Stack of values to process */
9
+ stack: unknown[];
10
+ /** Output stack for processed values */
11
+ stackOut: unknown[];
12
+ /** Map tracking circular references (present when circular: true) */
13
+ seen: Map<unknown, {value?: unknown; actions?: Array<[unknown, unknown]>}> | null;
14
+ /** Include symbol properties */
15
+ symbols?: boolean;
16
+ /** Include non-enumerable properties */
17
+ allProps?: boolean;
18
+ /** Optional environment for variable handling */
19
+ env?: unknown;
20
+ /** Wrapper for Maps (set by preprocess) */
21
+ wrapMap?: (map: Map<unknown, unknown>) => unknown;
22
+ /** Wrapper for Arrays (set by preprocess) */
23
+ wrapArray?: (array: unknown[]) => unknown;
24
+ /** Wrapper for Objects (set by preprocess) */
25
+ wrapObject?: (object: unknown) => unknown;
26
+ /** Wrapper for Sets (set by preprocess) */
27
+ wrapSet?: (set: Set<unknown>) => unknown;
28
+ /** Additional context properties */
29
+ [key: string]: unknown;
30
+ }
31
+
32
+ /**
33
+ * Options for walk traversal
34
+ */
35
+ export interface WalkOptions {
36
+ /** Custom object processor */
37
+ processObject?: (object: unknown, context: WalkContext) => void;
38
+ /** Custom non-object value processor */
39
+ processOther?: (value: unknown, context: WalkContext) => void;
40
+ /** Custom circular reference processor */
41
+ processCircular?: (value: unknown, context: WalkContext) => void;
42
+ /**
43
+ * Flat array of type handler pairs: [Constructor, handler, Constructor, handler, ...]
44
+ *
45
+ * Each pair maps a constructor to a processing function.
46
+ */
47
+ registry?: unknown[];
48
+ /** Array of filter functions — return true to indicate value was handled */
49
+ filters?: Array<(val: unknown, context: WalkContext) => boolean>;
50
+ /** Enable circular reference detection */
51
+ circular?: boolean;
52
+ /** Include symbol properties */
53
+ symbols?: boolean;
54
+ /** Include non-enumerable properties */
55
+ allProps?: boolean;
56
+ /** Custom context object (properties are merged into WalkContext) */
57
+ context?: Record<string, unknown>;
58
+ }
59
+
60
+ /**
61
+ * Marker for values that were already seen (circular references)
62
+ */
63
+ export declare class Circular {
64
+ /** The already-seen value */
65
+ value: unknown;
66
+ constructor(value: unknown);
67
+ }
68
+
69
+ /**
70
+ * Deferred processing command pushed onto the walk stack
71
+ */
72
+ export declare class Command {
73
+ /** Function to execute during post-processing */
74
+ f: (context: WalkContext) => void;
75
+ /** Source object being processed */
76
+ s: unknown;
77
+ constructor(f: (context: WalkContext) => void, s: unknown);
78
+ }
79
+
80
+ /**
81
+ * Non-recursive stack-based object tree walker
82
+ *
83
+ * Traverses values using an explicit stack with support for
84
+ * circular references, type registries, and filters.
85
+ *
86
+ * @param o - Value to traverse
87
+ * @param options - Walk options and processors
88
+ */
89
+ export declare const walk: ((o: unknown, options?: WalkOptions) => void) & {
90
+ Command: typeof Command;
91
+ };
92
+
93
+ /**
94
+ * Default type handler registry (flat array of [Constructor, handler] pairs)
95
+ */
96
+ export declare const registry: unknown[];
97
+
98
+ /**
99
+ * Default filter functions
100
+ */
101
+ export declare const filters: Array<(val: unknown, context: WalkContext) => boolean>;
102
+
103
+ // Utility processors
104
+
105
+ /** Pushes value to stackOut unchanged */
106
+ export declare const processOther: (value: unknown, context: WalkContext) => void;
107
+
108
+ /** Pushes a Circular marker to stackOut */
109
+ export declare const processCircular: (value: unknown, context: WalkContext) => void;
110
+
111
+ /**
112
+ * Creates a Map processor with optional post-processing
113
+ * @param postProcess - Post-processor for normal flow
114
+ * @param postProcessSeen - Post-processor when circular refs are tracked
115
+ * @returns Map processing function
116
+ */
117
+ export declare const processMap: (
118
+ postProcess?: (context: WalkContext) => void,
119
+ postProcessSeen?: (context: WalkContext) => void
120
+ ) => (object: Map<unknown, unknown>, context: WalkContext) => void;
121
+
122
+ /**
123
+ * Post-processes a Map with circular reference resolution
124
+ * @param source - Original Map
125
+ * @param context - Walk context
126
+ */
127
+ export declare const postMapCircular: (source: Map<unknown, unknown>, context: WalkContext) => void;
128
+
129
+ /**
130
+ * Builds a new Map from processed values on stackOut
131
+ * @param keys - Keys for the new Map
132
+ * @param stackOut - Output stack with values
133
+ * @param wrap - Optional wrapper function
134
+ */
135
+ export declare const buildNewMap: (keys: Iterable<unknown>, stackOut: unknown[], wrap?: (map: Map<unknown, unknown>) => unknown) => void;
136
+
137
+ /**
138
+ * Replaces stackOut entries from upTo to end with a single object
139
+ * @param upTo - Index offset from end
140
+ * @param object - Object to push
141
+ * @param stackOut - Output stack
142
+ */
143
+ export declare const replaceObject: (upTo: number, object: unknown, stackOut: unknown[]) => void;
144
+
145
+ /**
146
+ * Creates an Object processor with optional post-processing
147
+ * @param postProcess - Post-processor for normal flow
148
+ * @param postProcessSeen - Post-processor when circular refs are tracked
149
+ * @returns Object processing function
150
+ */
151
+ export declare const processObject: (
152
+ postProcess?: (context: WalkContext) => void,
153
+ postProcessSeen?: (context: WalkContext) => void
154
+ ) => (object: unknown, context: WalkContext) => void;
155
+
156
+ /**
157
+ * Post-processes an Object with circular reference resolution
158
+ * @param source - Original object
159
+ * @param descriptors - Property descriptors
160
+ * @param keys - Property keys
161
+ * @param context - Walk context
162
+ */
163
+ export declare const postObjectCircular: (
164
+ source: unknown,
165
+ descriptors: Record<string | symbol, PropertyDescriptor>,
166
+ keys: Array<string | symbol>,
167
+ context: WalkContext
168
+ ) => void;
169
+
170
+ /**
171
+ * Extracts property descriptors and keys from an object
172
+ * @param object - Object to analyze
173
+ * @param context - Walk context (uses symbols and allProps flags)
174
+ * @returns Descriptors and keys
175
+ */
176
+ export declare const getObjectData: (
177
+ object: unknown,
178
+ context: WalkContext
179
+ ) => {descriptors: Record<string | symbol, PropertyDescriptor>; keys: Array<string | symbol>};
180
+
181
+ /**
182
+ * Builds a new object from processed values on stackOut
183
+ * @param source - Original object (used for prototype and array detection)
184
+ * @param descriptors - Property descriptors
185
+ * @param keys - Property keys
186
+ * @param stackOut - Output stack with values
187
+ * @param wrap - Optional wrapper function
188
+ */
189
+ export declare const buildNewObject: (
190
+ source: unknown,
191
+ descriptors: Record<string | symbol, PropertyDescriptor>,
192
+ keys: Array<string | symbol>,
193
+ stackOut: unknown[],
194
+ wrap?: (object: unknown) => unknown
195
+ ) => void;
196
+
197
+ /**
198
+ * Resolves a Variable to its bound value and pushes to the stack
199
+ * @param val - Variable instance
200
+ * @param context - Walk context (uses context.env)
201
+ */
202
+ export declare const processVariable: (val: unknown, context: WalkContext) => void;
203
+
204
+ /**
205
+ * Executes a Command's function
206
+ * @param val - Command instance
207
+ * @param context - Walk context
208
+ */
209
+ export declare const processCommand: (val: unknown, context: WalkContext) => void;
210
+
211
+ /**
212
+ * Resolves circular reference actions for a seen object
213
+ * @param seen - Map of seen objects
214
+ * @param source - Source object
215
+ * @param value - Resolved value
216
+ */
217
+ export declare const setObject: (seen: Map<unknown, {value?: unknown; actions?: Array<[unknown, unknown]>}>, source: unknown, value: unknown) => void;
218
+
219
+ export default walk;
@@ -34,7 +34,10 @@ const processCircular = (value, context) => context.stackOut.push(new Circular(v
34
34
 
35
35
  const processMap = (postProcess, postProcessSeen) => (object, context) => {
36
36
  const stack = context.stack;
37
- postProcess && stack.push(new Command(postProcessSeen ? (context.seen ? postProcessSeen : postProcess) : postProcess, object));
37
+ if (postProcess) {
38
+ const processor = context.seen && postProcessSeen ? postProcessSeen : postProcess;
39
+ stack.push(new Command(processor, object));
40
+ }
38
41
  for (const value of object.values()) {
39
42
  stack.push(value);
40
43
  }
@@ -170,8 +173,9 @@ class Command {
170
173
 
171
174
  const processCommand = (val, context) => val.f(context);
172
175
 
173
- const defaultRegistry = [Command, processCommand, Array, processObject(), Date, nop, RegExp, nop, Map, processMap(), Set, nop, Promise, nop],
174
- defaultFilters = [];
176
+ const defaultRegistry = [Command, processCommand, Array, processObject(), Date, nop, RegExp, nop, Map, processMap(), Set, nop, Promise, nop];
177
+ typeof URL == 'function' && defaultRegistry.push(URL, nop);
178
+ const defaultFilters = [];
175
179
 
176
180
  // add more types
177
181
 
@@ -257,6 +261,7 @@ export {
257
261
  getObjectData,
258
262
  buildNewObject,
259
263
  processVariable,
260
- processCommand
264
+ processCommand,
265
+ walk
261
266
  };
262
267
  export default walk;
@@ -0,0 +1,45 @@
1
+ // Type definitions for deep6 matchCondition unifier
2
+ // Generated from src/unifiers/matchCondition.js
3
+
4
+ import type {Unifier, Env} from '../env.js';
5
+
6
+ /**
7
+ * Predicate-based matching unifier
8
+ *
9
+ * Delegates matching to a user-supplied function that receives
10
+ * the full unification context (value, stacks, environment).
11
+ */
12
+ export declare class MatchCondition extends Unifier {
13
+ /** Predicate function */
14
+ f: (val: unknown, ls: unknown[], rs: unknown[], env: Env) => boolean;
15
+
16
+ /**
17
+ * @param f - Predicate that returns true if the value matches
18
+ */
19
+ constructor(f: (val: unknown, ls: unknown[], rs: unknown[], env: Env) => boolean);
20
+
21
+ /**
22
+ * Delegates to the predicate function
23
+ * @param val - Value to test
24
+ * @param ls - Left argument stack
25
+ * @param rs - Right argument stack
26
+ * @param env - Unification environment
27
+ * @returns Result of the predicate
28
+ */
29
+ unify(val: unknown, ls: unknown[], rs: unknown[], env: Env): boolean;
30
+ }
31
+
32
+ /**
33
+ * Creates a predicate matcher
34
+ *
35
+ * @param f - Predicate function `(val, ls, rs, env) => boolean`
36
+ * @returns A new MatchCondition instance
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const isPositive = matchCondition(val => typeof val === 'number' && val > 0);
41
+ * match({n: 5}, {n: isPositive}); // true
42
+ * ```
43
+ */
44
+ export declare const matchCondition: (f: (val: unknown, ls: unknown[], rs: unknown[], env: Env) => boolean) => MatchCondition;
45
+ export default matchCondition;
@@ -13,4 +13,5 @@ class MatchCondition extends Unifier {
13
13
 
14
14
  const matchCondition = f => new MatchCondition(f);
15
15
 
16
+ export {matchCondition};
16
17
  export default matchCondition;
@@ -0,0 +1,37 @@
1
+ // Type definitions for deep6 matchInstanceOf unifier
2
+ // Generated from src/unifiers/matchInstanceOf.js
3
+
4
+ import type {Unifier} from '../env.js';
5
+
6
+ /**
7
+ * Instanceof-based matching unifier
8
+ *
9
+ * Matches values by their prototype chain. Rejects falsy values and unbound Variables.
10
+ */
11
+ export declare class MatchInstanceOf extends Unifier {
12
+ /** Array of constructors to match against */
13
+ types: (new (...args: any[]) => unknown)[];
14
+
15
+ /**
16
+ * @param types - Constructor or array of constructors
17
+ */
18
+ constructor(types: (new (...args: any[]) => unknown) | (new (...args: any[]) => unknown)[]);
19
+
20
+ /**
21
+ * Tests if the value is an instance of one of the configured constructors
22
+ * @param val - Value to check
23
+ * @param ls - Left argument stack (unused)
24
+ * @param rs - Right argument stack (unused)
25
+ * @returns True if val is an instance of any configured type
26
+ */
27
+ unify(val: unknown, ls: unknown[], rs: unknown[]): boolean;
28
+ }
29
+
30
+ /**
31
+ * Creates an instanceof matcher
32
+ *
33
+ * @param types - Constructor(s) to match against
34
+ * @returns A new MatchInstanceOf instance
35
+ */
36
+ export declare const matchInstanceOf: (types: (new (...args: any[]) => unknown) | (new (...args: any[]) => unknown)[]) => MatchInstanceOf;
37
+ export default matchInstanceOf;
@@ -13,4 +13,5 @@ class MatchInstanceOf extends Unifier {
13
13
 
14
14
  const matchInstanceOf = types => new MatchInstanceOf(types);
15
15
 
16
+ export {matchInstanceOf};
16
17
  export default matchInstanceOf;
@@ -0,0 +1,56 @@
1
+ // Type definitions for deep6 matchString unifier
2
+ // Generated from src/unifiers/matchString.js
3
+
4
+ import type {Unifier} from '../env.js';
5
+
6
+ /**
7
+ * RegExp-based string matching unifier
8
+ *
9
+ * Matches values against a regular expression. Optionally captures
10
+ * the match array and match properties (index, input) for variable binding.
11
+ */
12
+ export declare class MatchString extends Unifier {
13
+ /** Regular expression to match against */
14
+ regexp: RegExp;
15
+ /** Pattern to unify with the match result array (optional) */
16
+ matches?: unknown;
17
+ /** Pattern to unify with match properties {index, input} (optional) */
18
+ props?: unknown;
19
+
20
+ /**
21
+ * @param regexp - Regular expression to match
22
+ * @param matches - Pattern to unify with match array (optional)
23
+ * @param props - Pattern to unify with {index, input} (optional)
24
+ */
25
+ constructor(regexp: RegExp, matches?: unknown, props?: unknown);
26
+
27
+ /**
28
+ * Tests a value against the regex and pushes capture bindings
29
+ * @param val - Value to match (coerced to string)
30
+ * @param ls - Left argument stack
31
+ * @param rs - Right argument stack
32
+ * @returns Truthy if the regex matches
33
+ */
34
+ unify(val: unknown, ls: unknown[], rs: unknown[]): boolean;
35
+ }
36
+
37
+ /**
38
+ * Creates a regex string matcher
39
+ *
40
+ * @param regexp - Regular expression to match against
41
+ * @param matches - Pattern to unify with the full match array (optional)
42
+ * @param props - Pattern to unify with {index, input} (optional)
43
+ * @returns A new MatchString instance
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * // Simple matching
48
+ * matchString(/^hello/i);
49
+ *
50
+ * // With captures bound to a variable array
51
+ * const names = [any, variable('first'), variable('last')];
52
+ * matchString(/^(\w+)\s+(\w+)$/, names);
53
+ * ```
54
+ */
55
+ export declare const matchString: (regexp: RegExp, matches?: unknown, props?: unknown) => MatchString;
56
+ export default matchString;
@@ -30,4 +30,5 @@ class MatchString extends Unifier {
30
30
 
31
31
  const matchString = (regexp, matches, props) => new MatchString(regexp, matches, props);
32
32
 
33
+ export {matchString};
33
34
  export default matchString;
@@ -0,0 +1,37 @@
1
+ // Type definitions for deep6 matchTypeOf unifier
2
+ // Generated from src/unifiers/matchTypeOf.js
3
+
4
+ import type {Unifier} from '../env.js';
5
+
6
+ /**
7
+ * Type-based matching unifier
8
+ *
9
+ * Matches values by their `typeof` result. Rejects unbound Variables.
10
+ */
11
+ export declare class MatchTypeOf extends Unifier {
12
+ /** Array of type names to match against */
13
+ types: string[];
14
+
15
+ /**
16
+ * @param types - Type name or array of type names
17
+ */
18
+ constructor(types: string | string[]);
19
+
20
+ /**
21
+ * Tests if the value's typeof matches one of the configured types
22
+ * @param val - Value to check
23
+ * @param ls - Left argument stack (unused)
24
+ * @param rs - Right argument stack (unused)
25
+ * @returns True if typeof val matches
26
+ */
27
+ unify(val: unknown, ls: unknown[], rs: unknown[]): boolean;
28
+ }
29
+
30
+ /**
31
+ * Creates a typeof matcher
32
+ *
33
+ * @param types - Type name(s) to match against (e.g. 'string', ['number', 'bigint'])
34
+ * @returns A new MatchTypeOf instance
35
+ */
36
+ export declare const matchTypeOf: (types: string | string[]) => MatchTypeOf;
37
+ export default matchTypeOf;
@@ -13,4 +13,5 @@ class MatchTypeOf extends Unifier {
13
13
 
14
14
  const matchTypeOf = types => new MatchTypeOf(types);
15
15
 
16
+ export {matchTypeOf};
16
17
  export default matchTypeOf;
@@ -0,0 +1,52 @@
1
+ // Type definitions for deep6 ref unifier
2
+ // Generated from src/unifiers/ref.js
3
+
4
+ import type {Variable, Env} from '../env.js';
5
+
6
+ /**
7
+ * Reference unifier for cross-pattern variable binding
8
+ *
9
+ * Binds both a variable and a value to the same input during unification.
10
+ * Pushes `(this.value, val)` and `(this.variable, val)` onto the stacks.
11
+ */
12
+ export declare class Ref extends Variable {
13
+ /** The variable being referenced */
14
+ variable: Variable;
15
+ /** The value pattern to unify against */
16
+ value: unknown;
17
+
18
+ /**
19
+ * @param variable - Variable name (string) or Variable instance
20
+ * @param value - Value pattern to bind alongside the variable
21
+ */
22
+ constructor(variable: string | Variable, value: unknown);
23
+
24
+ /**
25
+ * Pushes value and variable bindings onto the stacks
26
+ * @param val - Input value
27
+ * @param ls - Left argument stack
28
+ * @param rs - Right argument stack
29
+ * @param env - Unification environment
30
+ * @returns Always true
31
+ */
32
+ unify(val: unknown, ls: unknown[], rs: unknown[], env: Env): boolean;
33
+ }
34
+
35
+ /**
36
+ * Creates a reference unifier
37
+ *
38
+ * @param variable - Variable name or Variable instance
39
+ * @param value - Value pattern to bind alongside the variable
40
+ * @returns A new Ref instance
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const r = ref('x', variable('y'));
45
+ * // During unification, both 'x' and 'y' get bound to the matched value
46
+ * ```
47
+ */
48
+ export declare const ref: ((variable: string | Variable, value: unknown) => Ref) & {
49
+ Ref: typeof Ref;
50
+ };
51
+
52
+ export default ref;
@@ -18,4 +18,5 @@ class Ref extends Variable {
18
18
  const ref = (variable, value) => new Ref(variable, value);
19
19
  ref.Ref = Ref;
20
20
 
21
+ export {ref};
21
22
  export default ref;
@@ -0,0 +1,95 @@
1
+ // Type definitions for deep6 unification
2
+ // Generated from src/unify.js
3
+
4
+ import {Env, Unifier, Variable} from './env.js';
5
+
6
+ /**
7
+ * Options for unification
8
+ */
9
+ export interface UnifyOptions {
10
+ /** Handle circular references (default: false) */
11
+ circular?: boolean;
12
+ /** Include symbol properties (default: false) */
13
+ symbols?: boolean;
14
+ /** Use loose equality for primitives (default: false) */
15
+ loose?: boolean;
16
+ /** Ignore function properties (default: false) */
17
+ ignoreFunctions?: boolean;
18
+ /** Distinguish +0 from -0 (default: false) */
19
+ signedZero?: boolean;
20
+ /** Allow extra keys on target objects (default: false) */
21
+ openObjects?: boolean;
22
+ /** Allow extra elements in target arrays (default: false) */
23
+ openArrays?: boolean;
24
+ /** Allow extra entries in target Maps (default: false) */
25
+ openMaps?: boolean;
26
+ /** Allow extra entries in target Sets (default: false) */
27
+ openSets?: boolean;
28
+ }
29
+
30
+ /**
31
+ * Core unification algorithm
32
+ *
33
+ * Attempts to unify two values, optionally binding variables.
34
+ * Returns an Env with bindings on success, or null on failure.
35
+ *
36
+ * @param l - Left value
37
+ * @param r - Right value
38
+ * @param env - Existing environment, options object, or null
39
+ * @param options - Unification options (when env is provided separately)
40
+ * @returns Environment with bindings, or null on failure
41
+ */
42
+ export declare const unify: (l: unknown, r: unknown, env?: Env | UnifyOptions | null, options?: UnifyOptions) => Env | null;
43
+
44
+ /**
45
+ * Flat array of type-specific unifier pairs: [Constructor, handler, Constructor, handler, ...]
46
+ *
47
+ * Use `registry.push(Type, handler)` to register a custom type handler.
48
+ * Handler signature: `(l, r, ls, rs, env) => boolean`
49
+ */
50
+ export declare const registry: unknown[];
51
+
52
+ /**
53
+ * Flat array of filter pairs: [predicate, handler, predicate, handler, ...]
54
+ *
55
+ * Use `filters.push(predicate, handler)` to register a custom filter.
56
+ */
57
+ export declare const filters: unknown[];
58
+
59
+ /**
60
+ * Wraps a value for open matching (target may have extra properties)
61
+ * @param o - Value to wrap
62
+ * @returns Open-wrapped value
63
+ */
64
+ export declare const open: <T>(o: T) => T;
65
+
66
+ /**
67
+ * Wraps a value for soft matching (bidirectional open, updates both sides)
68
+ * @param o - Value to wrap
69
+ * @returns Soft-wrapped value
70
+ */
71
+ export declare const soft: <T>(o: T) => T;
72
+
73
+ /**
74
+ * Checks if a value is open-wrapped
75
+ * @param o - Value to check
76
+ */
77
+ export declare const isOpen: (o: unknown) => boolean;
78
+
79
+ /**
80
+ * Checks if a value is soft-wrapped
81
+ * @param o - Value to check
82
+ */
83
+ export declare const isSoft: (o: unknown) => boolean;
84
+
85
+ /**
86
+ * Checks if a value is wrapped (open or soft)
87
+ * @param o - Value to check
88
+ */
89
+ export declare const isWrapped: (o: unknown) => boolean;
90
+
91
+ // Re-exports from env.js (value exports, usable as constructors)
92
+ export {Env, Unifier, Variable} from './env.js';
93
+ export {_, any, isUnifier, isVariable, variable} from './env.js';
94
+
95
+ export default unify;