JSPM

tree-morph

0.2.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 52
  • Score
    100M100P100Q62251F
  • License MIT

Agnostic tree morphing library.

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

Greenkeeper badge

Agnostic tree morphing library.

travis codecov

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-morph

Usage

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.

  • 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