Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/loopmode/treegen
Javascript random tree data generator
https://github.com/loopmode/treegen
Last synced: 4 days ago
JSON representation
Javascript random tree data generator
- Host: GitHub
- URL: https://github.com/loopmode/treegen
- Owner: loopmode
- License: mit
- Created: 2015-07-20T08:31:17.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-18T01:25:42.000Z (almost 9 years ago)
- Last Synced: 2024-05-28T16:05:58.041Z (6 months ago)
- Language: JavaScript
- Size: 84 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# treegen
Generates random tree data using https://github.com/Marak/Faker.js## usage
The module exports a generator function with two required params: `depth` and `spread`, and both should be integer numbers.
The function will create a tree of objects that contain `name` (string), `data` (object) and `children` (array) properties.
You can specify two additional, optional params in order to control the kind of data that is generated: `nameGen` and `dataGen`, both of type `Function`.
If you do not specify the generator functions, `faker.js` will be used to create some dummy data:var treegen = require('treegen');
var tree = treegen(1, 3);
// only one level of depth, but spread=3: result is an object with 3 children:
/*
{
"name": "Evert Carroll",
"data": {
"user": "Preston_Oberbrunner",
"host": "leopold.name",
"city": "West Roy bury"
},
"children": [
{
"name": "Jayme Wyman",
"data": {
"user": "Keaton_Braun96",
"host": "izabella.com",
"city": "East Marquis"
},
"children": []
},
{
"name": "Madisen Kulas",
"data": {
"user": "Bernard86",
"host": "tony.org",
"city": "Barry haven"
},
"children": []
},
{
"name": "Joanie Maggio",
"data": {
"user": "Jamie22",
"host": "jamar.name",
"city": "North Marian"
},
"children": []
}
]
}
*/When specifying generator functions, the name generator should return a string, while the data generator should return an object:
var treegen = require('treegen');
function generateName() {
return 'myObjectName';
}
function generateData() {
return {
foo: 'bar'
}
}
var tree = treegen(1, 3, generateName, generateData);
// same as before, but with different values
/*
{
"name": "myObjectName",
"data": {
"foo": "bar"
},
"children": [
{
"name": "myObjectName",
"data": {
"foo": "bar"
},
"children": []
},
{
"name": "myObjectName",
"data": {
"foo": "bar"
},
"children": []
},
{
"name": "myObjectName",
"data": {
"foo": "bar"
},
"children": []
}
]
}
*/TODO: Figure out mathematical formula for predicting number of created objects, just for the readme. Should be some power or faculty between spread and depth, right?