Poetree is a collection of utilities functions to work with trees.
It works in Node.js and the web environments. The package is OSS and licensed under the MIT license.
npm i poetree
The tree
function organizes a flat array of documents into an ordered document hierarchy.
-
documents (object[], required)
A flatten list of documents to organized into a tree. -
options.conflict (boolean, optional)
Throw an error if the same slug is found accross multiple documents. -
options.children (string, required)
The document property which stores the child documents when documents are organized as a tree. The value should not conflict with an existing document property. -
options.relative (string, default to property)
Same asproperty
but common path is discovered and strip-out from the relative path. -
options.slug (string, required)
The document property which stores the unique path used to identify a document in the tree. -
options.sort (string, optional)
An optional document property which stores an attribute used for sorting instead of using the slug last element by default.
The sort
function orders a flatten list of documents by slugs and an optional sort property.
-
documents (object[], required)
A flatten list of documents to sort. -
options.conflict (boolean, optional)
Throw an error if the same slug is found accross multiple documents. -
options.slug (string, required)
The document property which stores the unique path used to identify a document in the tree. -
options.sort (string, optional)
An optional document property which stores an attribute used for sorting instead of using the slug last element by default.
The project is sponsored by Adaltas based in Paris, France. Adaltas offers support and consulting on distributed systems, big data and open source.