simple-nary-trees

1.0.1 • Public • Published

simple-nary-trees

Project Status: Active – The project has reached a stable, usable state and is being actively developed. npm version Build Status codecov

About

simple-nary-trees is a package for creating a nary-tree structure.
It provides two classes Tree and TreeNode you can instanciate and populate with any data you want.

Install

npm install --save simple-nary-trees
yarn add simple-nary-trees

Usage

simple-nary-trees exports a Tree and a TreeNode classes you can import:

// ES6
import { Tree, TreeNode } from "simple-nary-trees";

// ES5
const Tree = require("simple-nary-trees").Tree;
const TreeNode = require("simple-nary-trees").TreeNode;

Once imported, you just have to instanciate a Tree and add data to have an usable tree structure.

import { Tree } from "simple-nary-trees";

const tree = new Tree();
const node = new TreeNode("node-id");
const secondNode = new TreeNode("second-id");

tree.root = node;
tree.addNode(secondNode, "node-id");

We do suggest you extends the TreeNode class to create your own representation of a tree node. The common pattern is the following:

import { TreeNode } from "simple-nary-trees";

class MyTreeNode extends TreeNode {
  constructor({ id, name }) {
    super(id);

    // You can use whatever suits you for your data
    this.name = name;
  }
}

Authors

simple-nary-trees is maintained by M4dNation Company.
First version written by axelvaindal.

Contributors

There is actually no other contributors for this project. If you want to contribute, feel free to make any suggestions or to contact us.

Contributing to the package

We try to keep simple-nary-trees as simple as possible.
Before proposing a PR or opening an issue, please keep in mind :

- This package is meant to be as simple as possible
- This package tries to respect the [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle)
- This package tries to use the minimum of dependencies possible

Taking into account the previous points leads us to NOT merge proposed pull-request if those :

- Integrate changes that are too far from the initial purpose of the package
- Integrate changes that are adding additional dependencies
- Integrate changes that are not unit tested and motivationated

This being said, we really welcome pull-request and bug report, so feel free to start a contribution.

Moreover, Pull Requests should always come with related unit tests, and won't be considered if tests aren't included.

Testing

simple-nary-trees uses jest for unit testing.
If you don't know about jest yet, you can check out their documentation.

To run the tests, just run :

yarn test

Note that we are using codecov to keep track of code coverage related to our tests and you shouldn't affect negatively the current coverage of the code by removing tests or not covering new features with new unit tests.

Licence

simple-nary-trees is available under the terms of the MIT LICENSE.
Check the licence file for more information.

Readme

Keywords

Package Sidebar

Install

npm i simple-nary-trees

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

18.4 kB

Total Files

8

Last publish

Collaborators

  • axelvaindal