deep6 1.1.4 → 1.2.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 (48) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +40 -39
  3. package/llms-full.txt +371 -0
  4. package/llms.txt +154 -0
  5. package/package.json +31 -109
  6. package/src/env.d.ts +174 -0
  7. package/src/env.js +4 -4
  8. package/src/index.d.ts +86 -0
  9. package/src/index.js +10 -7
  10. package/src/traverse/assemble.d.ts +59 -0
  11. package/src/traverse/assemble.js +4 -3
  12. package/src/traverse/clone.d.ts +57 -0
  13. package/src/traverse/clone.js +4 -2
  14. package/src/traverse/deref.d.ts +59 -0
  15. package/src/traverse/deref.js +3 -2
  16. package/src/traverse/preprocess.d.ts +65 -0
  17. package/src/traverse/preprocess.js +2 -1
  18. package/src/traverse/walk.d.ts +219 -0
  19. package/src/traverse/walk.js +9 -4
  20. package/src/unifiers/matchCondition.d.ts +45 -0
  21. package/src/unifiers/matchCondition.js +1 -0
  22. package/src/unifiers/matchInstanceOf.d.ts +37 -0
  23. package/src/unifiers/matchInstanceOf.js +1 -0
  24. package/src/unifiers/matchString.d.ts +56 -0
  25. package/src/unifiers/matchString.js +1 -0
  26. package/src/unifiers/matchTypeOf.d.ts +37 -0
  27. package/src/unifiers/matchTypeOf.js +1 -0
  28. package/src/unifiers/ref.d.ts +52 -0
  29. package/src/unifiers/ref.js +1 -0
  30. package/src/unify.d.ts +95 -0
  31. package/src/unify.js +130 -66
  32. package/src/utils/replaceVars.d.ts +25 -0
  33. package/src/utils/replaceVars.js +23 -19
  34. package/cjs/env.js +0 -183
  35. package/cjs/index.js +0 -44
  36. package/cjs/package.json +0 -1
  37. package/cjs/traverse/assemble.js +0 -129
  38. package/cjs/traverse/clone.js +0 -82
  39. package/cjs/traverse/deref.js +0 -87
  40. package/cjs/traverse/preprocess.js +0 -84
  41. package/cjs/traverse/walk.js +0 -263
  42. package/cjs/unifiers/matchCondition.js +0 -18
  43. package/cjs/unifiers/matchInstanceOf.js +0 -18
  44. package/cjs/unifiers/matchString.js +0 -38
  45. package/cjs/unifiers/matchTypeOf.js +0 -18
  46. package/cjs/unifiers/ref.js +0 -23
  47. package/cjs/unify.js +0 -473
  48. package/cjs/utils/replaceVars.js +0 -28
@@ -1,263 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.setObject = exports.replaceObject = exports.registry = exports.processVariable = exports.processOther = exports.processObject = exports.processMap = exports.processCommand = exports.processCircular = exports.postObjectCircular = exports.postMapCircular = exports.getObjectData = exports.filters = exports.default = exports.buildNewObject = exports.buildNewMap = exports.Command = exports.Circular = void 0;
7
- var _unify = require("../unify.js");
8
- const empty = {};
9
- const nop = () => {};
10
-
11
- // public utilities to build walkers
12
-
13
- class Circular {
14
- constructor(value) {
15
- this.value = value;
16
- }
17
- }
18
- exports.Circular = Circular;
19
- const setObject = (seen, source, value) => {
20
- const record = seen.get(source);
21
- if (record) {
22
- record.actions.forEach(([object, key]) => {
23
- if (object instanceof Map) {
24
- object.set(key, value);
25
- } else {
26
- const d = Object.getOwnPropertyDescriptor(object, key);
27
- d.value = value;
28
- Object.defineProperty(object, key, d);
29
- }
30
- });
31
- }
32
- seen.set(source, {
33
- value
34
- });
35
- };
36
- exports.setObject = setObject;
37
- const processOther = (value, context) => context.stackOut.push(value);
38
- exports.processOther = processOther;
39
- const processCircular = (value, context) => context.stackOut.push(new Circular(value));
40
- exports.processCircular = processCircular;
41
- const processMap = (postProcess, postProcessSeen) => (object, context) => {
42
- const stack = context.stack;
43
- postProcess && stack.push(new Command(postProcessSeen ? context.seen ? postProcessSeen : postProcess : postProcess, object));
44
- for (const value of object.values()) {
45
- stack.push(value);
46
- }
47
- };
48
- exports.processMap = processMap;
49
- const postMapCircular = (source, context) => {
50
- const {
51
- stackOut,
52
- seen,
53
- wrapMap
54
- } = context,
55
- t = new Map();
56
- for (const k of source.keys()) {
57
- const value = stackOut.pop();
58
- if (!(value instanceof Circular)) {
59
- t.set(k, value);
60
- continue;
61
- }
62
- const record = seen.get(value.value);
63
- if (record) {
64
- if (record.actions) {
65
- record.actions.push([t, k]);
66
- } else {
67
- t.set(k, record.value);
68
- }
69
- } else {
70
- seen.set(value.value, {
71
- actions: [[t, k]]
72
- });
73
- }
74
- }
75
- const o = wrapMap ? wrapMap(t) : t;
76
- setObject(seen, source, o);
77
- stackOut.push(o);
78
- };
79
- exports.postMapCircular = postMapCircular;
80
- const buildNewMap = (keys, stackOut, wrap) => {
81
- const t = new Map();
82
- for (const k of keys) {
83
- t.set(k, stackOut.pop());
84
- }
85
- stackOut.push(wrap ? wrap(t) : t);
86
- };
87
- exports.buildNewMap = buildNewMap;
88
- const replaceObject = (upTo, object, stackOut) => {
89
- const l = stackOut.length - 1 - upTo;
90
- if (l) {
91
- stackOut.splice(-l, l, object);
92
- } else {
93
- stackOut.push(object);
94
- }
95
- };
96
- exports.replaceObject = replaceObject;
97
- const processObject = (postProcess, postProcessSeen) => (object, context) => {
98
- const stack = context.stack;
99
- postProcess && stack.push(new Command(postProcessSeen ? context.seen ? postProcessSeen : postProcess : postProcess, object));
100
- const {
101
- descriptors,
102
- keys
103
- } = getObjectData(object, context);
104
- for (const k of keys) {
105
- const d = descriptors[k];
106
- !(d.get || d.set) && stack.push(d.value);
107
- }
108
- };
109
- exports.processObject = processObject;
110
- const postObjectCircular = (source, descriptors, keys, context) => {
111
- const {
112
- stackOut,
113
- seen
114
- } = context,
115
- isArray = Array.isArray(source),
116
- wrap = context[isArray ? 'wrapArray' : 'wrapObject'],
117
- t = isArray ? [] : Object.create(Object.getPrototypeOf(source));
118
- for (const k of keys) {
119
- const d = descriptors[k];
120
- if (d.get || d.set) {
121
- Object.defineProperty(t, k, d);
122
- continue;
123
- }
124
- const value = stackOut.pop();
125
- if (!(value instanceof Circular)) {
126
- d.value = value;
127
- Object.defineProperty(t, k, d);
128
- continue;
129
- }
130
- const record = seen.get(value.value);
131
- if (record) {
132
- if (record.actions) {
133
- record.actions.push([t, k]);
134
- d.value = null;
135
- } else {
136
- d.value = record.value;
137
- }
138
- Object.defineProperty(t, k, d);
139
- continue;
140
- }
141
- seen.set(value.value, {
142
- actions: [[t, k]]
143
- });
144
- d.value = null;
145
- Object.defineProperty(t, k, d);
146
- }
147
- const o = wrap ? wrap(t) : t;
148
- setObject(seen, source, o);
149
- stackOut.push(o);
150
- };
151
- exports.postObjectCircular = postObjectCircular;
152
- const getObjectData = (object, context) => {
153
- const descriptors = Object.getOwnPropertyDescriptors(object);
154
- if (Array.isArray(object)) delete descriptors.length;
155
- let keys = Object.keys(descriptors);
156
- if (context.symbols) keys = keys.concat(Object.getOwnPropertySymbols(descriptors));
157
- if (!context.allProps) keys = keys.filter(key => descriptors[key].enumerable);
158
- return {
159
- descriptors,
160
- keys
161
- };
162
- };
163
- exports.getObjectData = getObjectData;
164
- const buildNewObject = (source, descriptors, keys, stackOut, wrap) => {
165
- const t = Array.isArray(source) ? [] : Object.create(Object.getPrototypeOf(source));
166
- for (const k of keys) {
167
- const d = descriptors[k];
168
- if (!(d.get || d.set)) {
169
- d.value = stackOut.pop();
170
- }
171
- Object.defineProperty(t, k, d);
172
- }
173
- stackOut.push(wrap ? wrap(t) : t);
174
- };
175
- exports.buildNewObject = buildNewObject;
176
- const processVariable = (val, context) => {
177
- const env = context.env;
178
- if (val.isBound(env)) {
179
- context.stack.push(val.get(env));
180
- } else {
181
- context.stackOut.push(val);
182
- }
183
- };
184
-
185
- // implementation
186
- exports.processVariable = processVariable;
187
- class Command {
188
- constructor(f, s) {
189
- this.f = f;
190
- this.s = s;
191
- }
192
- }
193
- exports.Command = Command;
194
- const processCommand = (val, context) => val.f(context);
195
- exports.processCommand = processCommand;
196
- const defaultRegistry = exports.registry = [Command, processCommand, Array, processObject(), Date, nop, RegExp, nop, Map, processMap(), Set, nop, Promise, nop],
197
- defaultFilters = exports.filters = [];
198
-
199
- // add more types
200
-
201
- const addType = (Type, process) => defaultRegistry.push(Type, process || nop);
202
- typeof Int8Array == 'function' && addType(Int8Array);
203
- typeof Uint8Array == 'function' && addType(Uint8Array);
204
- typeof Uint8ClampedArray == 'function' && addType(Uint8ClampedArray);
205
- typeof Int16Array == 'function' && addType(Int16Array);
206
- typeof Uint16Array == 'function' && addType(Uint16Array);
207
- typeof Int32Array == 'function' && addType(Int32Array);
208
- typeof Uint32Array == 'function' && addType(Uint32Array);
209
- typeof Float32Array == 'function' && addType(Float32Array);
210
- typeof Float64Array == 'function' && addType(Float64Array);
211
- typeof BigInt64Array == 'function' && addType(BigInt64Array);
212
- typeof BigUint64Array == 'function' && addType(BigUint64Array);
213
- typeof DataView == 'function' && addType(DataView);
214
- typeof ArrayBuffer == 'function' && addType(ArrayBuffer);
215
-
216
- // main
217
-
218
- const walk = (o, options) => {
219
- // non-recursive stack-based walk about an object tree
220
- options = options || empty;
221
- const doObject = options.processObject || processObject(),
222
- doOther = options.processOther || nop,
223
- doCircular = options.processCircular || nop,
224
- registry = options.registry || defaultRegistry,
225
- filters = options.filters || defaultFilters,
226
- context = options.context || {},
227
- stack = [o],
228
- seen = options.circular ? new Map() : null;
229
- context.stack = stack;
230
- context.seen = seen;
231
- context.symbols = options.symbols;
232
- context.allProps = options.allProps;
233
- main: while (stack.length) {
234
- o = stack.pop();
235
- if (!o || typeof o != 'object' || o === _unify._) {
236
- doOther(o, context);
237
- continue;
238
- }
239
- // process circular dependencies
240
- if (seen) {
241
- if (seen.has(o)) {
242
- doCircular(o, context);
243
- continue;
244
- }
245
- seen.set(o, null);
246
- }
247
- // process registered constructors
248
- for (let i = 0; i < registry.length; i += 2) {
249
- if (o instanceof registry[i]) {
250
- registry[i + 1](o, context);
251
- continue main;
252
- }
253
- }
254
- // process registered filters
255
- for (let i = 0; i < filters.length; ++i) {
256
- if (filters[i](o, context)) continue main;
257
- }
258
- // process naked objects
259
- doObject(o, context);
260
- }
261
- };
262
- walk.Command = Command;
263
- var _default = exports.default = walk;
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _env = require("../env.js");
8
- class MatchCondition extends _env.Unifier {
9
- constructor(f) {
10
- super();
11
- this.f = f;
12
- }
13
- unify(val, ls, rs, env) {
14
- return this.f(val, ls, rs, env);
15
- }
16
- }
17
- const matchCondition = f => new MatchCondition(f);
18
- var _default = exports.default = matchCondition;
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _env = require("../env.js");
8
- class MatchInstanceOf extends _env.Unifier {
9
- constructor(types) {
10
- super();
11
- this.types = types instanceof Array ? types : [types];
12
- }
13
- unify(val, ls, rs) {
14
- return val && !(0, _env.isVariable)(val) && this.types.some(type => val instanceof type);
15
- }
16
- }
17
- const matchInstanceOf = types => new MatchInstanceOf(types);
18
- var _default = exports.default = matchInstanceOf;
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _env = require("../env.js");
8
- class MatchString extends _env.Unifier {
9
- constructor(regexp, matches, props) {
10
- super();
11
- this.regexp = regexp;
12
- this.matches = matches;
13
- this.props = props;
14
- }
15
- unify(val, ls, rs) {
16
- if ((0, _env.isVariable)(val)) {
17
- // cannot match with an unbound variable
18
- return false;
19
- }
20
- const result = this.regexp.exec('' + val);
21
- if (result) {
22
- if (this.matches) {
23
- ls.push(this.matches);
24
- rs.push(Array.prototype.slice.call(result, 0));
25
- }
26
- if (this.props) {
27
- ls.push(this.props);
28
- rs.push({
29
- index: result.index,
30
- input: result.input
31
- });
32
- }
33
- }
34
- return result;
35
- }
36
- }
37
- const matchString = (regexp, matches, props) => new MatchString(regexp, matches, props);
38
- var _default = exports.default = matchString;
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _env = require("../env.js");
8
- class MatchTypeOf extends _env.Unifier {
9
- constructor(types) {
10
- super();
11
- this.types = types instanceof Array ? types : [types];
12
- }
13
- unify(val, ls, rs) {
14
- return !(0, _env.isVariable)(val) && this.types.indexOf(typeof val) >= 0;
15
- }
16
- }
17
- const matchTypeOf = types => new MatchTypeOf(types);
18
- var _default = exports.default = matchTypeOf;
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _env = require("../env.js");
8
- class Ref extends _env.Variable {
9
- constructor(variable, value) {
10
- const v = typeof variable == 'string' ? new _env.Variable(variable) : variable;
11
- super(v.name);
12
- this.variable = v;
13
- this.value = value;
14
- }
15
- unify(val, ls, rs, env) {
16
- ls.push(this.value, this.variable);
17
- rs.push(val, val);
18
- return true;
19
- }
20
- }
21
- const ref = (variable, value) => new Ref(variable, value);
22
- ref.Ref = Ref;
23
- var _default = exports.default = ref;