Package Exports
- tree-morph
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tree-morph) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
tree-morph
Agnostic tree morphing library.
tree-morph allows you to apply either homomorphisms or isomorphisms to an immutable tree. You can mutate nodes at a data level and at a structural level. In other words, tree-morph lets you easily create high-order functions such as map or filter that work well with your tree structure.
tree-morph works around mutators. Those mutators contain logic to handle tree mutations. Depending on your needs and your tree structure, you can mutate your tree however you want, making tree-morph a versatile and agnostic tree mutation library.
Install
npm install --save tree-morphUsage
import morph from 'tree-morph'
// add a `depth` property to each node
const tree1 = morph(tree,
(node, context) => cloneWith(node, { depth: context.depth })
, add)
// only keep `type` property
const tree2 = morph(tree, node => pick(node, 'type'), add)
// filter nodes with type=foo
const tree3 = morph(tree,
node => ('foo' === node.type ? clone(node) : null)
, add)See more examples.
API
See the api documentation.
Related
- tree-mutate Little brother of
tree-morph, but for mutable trees. - tree-crawl Generic tree traversal library. This module uses it.
License
MIT © Nicolas Gryman