-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Eugene Lazutkin edited this page Dec 28, 2021
·
10 revisions
deep6
is a no-dependency ES6 mini-library:
- Advanced deep equivalency for JavaScript structures.
- Extensible to accommodate custom objects.
- Traversing objects.
- Extensible deep cloning.
- Written in ES6:
- Use it in Node or browsers without transpiling.
- Natively supports
Map
,Set
, typed arrays. - Natively supports symbols and property descriptors.
- Presented as ES6 modules, yet provides CommonJS modules for convenience.
- Efficient non-recursive algorithms.
- ~500 tests to ensure correctness.
- Support for circular dependencies.
- Support for "loose" comparisons.
- Unification.
- Identifying and capturing object fragments.
The library is written as a collection of ES6 modules. For convenience, and to support older versions of Node, it provides a collection of CommonJS (require()
-style) modules as well.
Most popular functions available from the main module as named properties:
-
equal(a, b [, options])
— deep equality.- Also this function is the default export of the module.
-
match(a, b [, options])
(orisShape()
) — object pattern matching. -
clone(a [, options])
— deep cloning.
Advanced functionality:
-
env — environments and variables:
-
Env
— a class to create an environment object. -
Unifier
— an interface for custom unifiers.-
isUnifier(x)
— returns a truthy value for objects based onUnifier
.
-
-
Variable
— a class to create variable objects that can be used withEnv
.-
isVariable(x)
— returns a truthy value for objects based onVariable
. -
variable([name])
— creates a variable object.
-
-
any
(or_
) — special object that matches anything.
-
-
unify(a, b [, env] [, options])
— generalized unification of objects. - Traverse objects (in
traverse/
):-
walk(o [, options])
— visit all primitives of an object. -
assemble(o [, env] [, options])
— assemble an object resolving variables. -
deref(o [, env] [, options])
— assemble an object in place resolving variables. -
preprocess(o [, options])
— mark up objects for custom unification.
-
- Useful unifiers (in
unifiers/
):-
matchConditions(fn)
— match if a counterpart satisfies a given function. -
matchInstanceOf(types)
— match if a counterpart is of certain instances. -
matchString(regexp [, matches] [, props])
— match if a counterpart satisfies a regular expression. -
matchTypeOf(types)
— match if a counterpart is of certain type names. -
ref(variable, value)
— binds a variable to a value and continue comparing this values against the other object.
-
- Utilities (in
utils/
):-
replaceVars(strings, ...vars)
— uses a template literal to resolve variables.
-
It is the next generation of heya-unify, which basic concepts were explained and demonstrated in the following blog posts: