with one click
add-type-support
// Add support for a new type to unify and clone registries. Use when asked to support a new JavaScript type or custom class in deep6.
// Add support for a new type to unify and clone registries. Use when asked to support a new JavaScript type or custom class in deep6.
Use the deep6 library for deep equality, deep cloning, unification, and pattern matching with logical variables in a JavaScript/TypeScript project. Use when adding structural comparison, structured clone with circular references, extensible pattern matching with extraction, or unification-based logic to a project that depends on `deep6`.
Write or update tests for a module or feature. Use when asked to write tests, add test coverage, or verify functionality for deep6.
Add a new unifier module to deep6. Use when asked to create custom pattern matching logic or extend unification behavior.
Debug unification failures in deep6. Use when unification returns null or produces unexpected results.
| name | add-type-support |
| description | Add support for a new type to unify and clone registries. Use when asked to support a new JavaScript type or custom class in deep6. |
Add support for a new type to the unification and cloning registries.
Identify the type — Determine what type needs support (built-in or custom class).
Read existing patterns — Check src/unify.js and src/traverse/clone.js for how similar types are handled.
Add unifier to src/unify.js:
(l, r, ls, rs, env) => booleantrue for match, false for failurels/rs for recursive comparisonregistry.push(Type, compareFunction)Add cloner to src/traverse/clone.js:
(val, context) => voidcontext.stackOutregistry.push(Type, processorFunction)Add tests in tests/tests.js:
equal()clone()Run tests: npm test
Update documentation:
llms.txt and llms-full.txtARCHITECTURE.md if neededUnifier (src/unify.js):
registry.push(Date, (l, r) => l instanceof Date && r instanceof Date && l.getTime() == r.getTime());
Cloner (src/traverse/clone.js):
registry.push(Date, (val, context) => context.stackOut.push(new Date(val.getTime())));
Unifier (src/unify.js):
const unifySet = (l, r, ls, rs, env) => {
if (!(l instanceof Set) || !(r instanceof Set) || l.size != r.size) return false;
for (const item of l) {
if (!r.has(item)) return false;
}
return true;
};
registry.push(Set, unifySet);
Cloner (src/traverse/clone.js):
registry.push(Set, (val, context) => context.stackOut.push(new Set(val)));
For typed arrays, use a factory function:
const unifyTypedArrays = Type => (l, r, ls, rs, env) => {
if (!(l instanceof Type) || !(r instanceof Type) || l.length != r.length) return false;
for (let i = 0; i < l.length; ++i) {
if (l[i] != r[i]) return false;
}
return true;
};
typeof Int8Array == 'function' && addType(Int8Array);
For custom classes, extend Unifier:
import {Unifier} from 'deep6/env.js';
class MyClassMatcher extends Unifier {
unify(val, ls, rs, env) {
if (!(val instanceof MyClass)) return false;
// Compare properties
ls.push(this.value);
rs.push(val.value);
return true;
}
}
instanceof for type checking