-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Eugene Lazutkin edited this page Nov 9, 2020
·
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:
-
equal(a, b [, options)
— deep equality. -
match(a, b [, options)
— object pattern matching-
any
— special object that matches anything.
-
-
clone(a [, options)
— deep cloning.
Advanced functionality:
- env — environments and variables.
-
unify(a, b [, env] [, options])
— generalized unification of objects. - Traverse objects:
-
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:
-
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:
-
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: