Code Monkey home page Code Monkey logo

tree-json-generator's Introduction


Tree JSON Generator

version

More than 150 000 nodes per second!
Simple library for generating JSON trees
No external dependency, highly customizable

Installation

You can install it using yarn or npm

npm install tree-json-generator
# or
yarn add tree-json-generator

Usage

NodeJS:

const TreeGen = require("tree-json-generator");

WebPack:

import * as TreeGen from "tree-json-generator";

Use generate(config) for generating tree

const config = {
  node: { // Node fields, required
    id: "@id()", // Pipes
    parent: "@parent()",
    level: "@level()",
    name: "@randomName()", 
    age: "@randomInteger(14,99)",
    email: "@randomEmail()",
    registered: "@randomBoolean(0.79)",
    child: "@child()" // Child field pointer (not required, if children are not needed)
  },
  rootNodesNumber: 7, // Number of root nodes
  childNodesNumber: [2, 5], // Number of children nodes (from 2 to 5)
  hasChildRate: 0.4, // Probability of children
  maxLevel: 3 // Max nesting
}

let tree = TreeGen.generate(config);

Pipes

This allows you to generate fields values for the nodes.

Warning: custom user functions only assign the same value to all nodes

Remember: Pipes are strings

Prebuilded pipes:

"@id()"

Random node ID

"@child()"

Child field pointer

"@parent()"

Field with parent node ID. (For this field, a field with an "@id" pipe before required.

"@level()"

Node level

"@randomName()"

Random name

"@randomFruit()"

Random fruit

"@randomEmail()"

Random E-Mail

"@randomInteger(min, max)"

Random Integer from range

"@randomBoolean(value = 0.5)"

Random Boolean (value - coefficient)

Config API

node: {}

Required. Contains node fields with pipes.

rootNodesNumber:

Not required. Number (5) or array range ([1, 40]). Default is 1.

childNodesNumber:

Not required. Number (9) or array range ([1, 15]). Default is 1.

maxLevel:

Not required. Max node level. Number (3). Default is 3.

hasChildRate:

Not required. The probability that the node has children. From 0 to 1. Default is 1.

tree-json-generator's People

Contributors

kelreel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dimazholobov

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.