Skip to content
This repository was archived by the owner on Apr 4, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2ab1769
Fix TypeError when loading arboreal.js: Cannot set property 'Arboreal…
EvgenyGusev Jul 25, 2013
cecae65
Fix compatibility errors with IE.
EvgenyGusev Jul 30, 2013
c00f800
Update README: length now is getLength().
EvgenyGusev Jul 30, 2013
b68fe61
Add appendChildren function and ability to append whole tree.
EvgenyGusev Aug 22, 2013
6e56bea
Add bubbleUp function.
EvgenyGusev Aug 23, 2013
4a29fda
Fix bug in parse method when parent parameter is used.
EvgenyGusev Aug 23, 2013
0bd611a
Fix IE incompatibility that affected versions 10 and 11.
Jan 21, 2015
d33c6db
Fix tests by using length property instead of getLength() method.
shonzilla May 25, 2016
0522b31
Make tests pass by fixing syntax error.
shonzilla May 25, 2016
2eb1ed6
Define module's entry point making require('arboreal') work.
shonzilla May 25, 2016
af706c4
Update dev dependencies to the latest and remove node.js engine limit…
shonzilla May 25, 2016
3606e35
Rely on semver for dev dependencies.
shonzilla May 25, 2016
a604b52
Add @shonzilla to contributors.
shonzilla May 25, 2016
bc5e232
Release 0.0.2
shonzilla May 25, 2016
244afcd
Trigger Travis CI build.
shonzilla May 26, 2016
194e38c
Update package.json: Add license and repository fields.
shonzilla May 27, 2016
a46e9d8
Update package.json: Move to node.js 4.0.0+ engine.
shonzilla May 27, 2016
85fc201
Instruct Travis to build for node.js versions 4 and 5 only.
shonzilla May 27, 2016
e9e1b56
New name Arboreal.js
vasiliyaltunin Apr 12, 2017
c94cd63
Updated readme and added examples to site
vasiliyaltunin Apr 12, 2017
7afa7b4
Added minified version of script and lib for example
vasiliyaltunin Apr 12, 2017
b0d3521
Site now use minified version of script
vasiliyaltunin Apr 12, 2017
c306c56
Fixed readme
vasiliyaltunin Apr 12, 2017
44aee46
Fixed readme for site
vasiliyaltunin Apr 12, 2017
020d935
Updated readme
vasiliyaltunin Apr 12, 2017
fa9d60f
Updated readme
vasiliyaltunin Apr 12, 2017
e501d7d
Readme update
vasiliyaltunin Apr 12, 2017
6e6aa39
Update travis to build with 5 and 6 version of node.js
vasiliyaltunin Apr 12, 2017
76fb9d3
Dev dependencies updated
vasiliyaltunin Apr 12, 2017
ea5aa34
Updated versions for npm
vasiliyaltunin Apr 12, 2017
e116bf1
Readme and docs update
vasiliyaltunin Apr 13, 2017
3c4c45b
Fixed jsdoc link error
vasiliyaltunin Apr 13, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
coverage/
.nyc_output/
nyc_output/
docs/
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
before_script: "npm install --dev"
language: node_js
node_js:
- "6"
- "5"
script: "npm test"
91 changes: 91 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"use strict";

module.exports = function (grunt) {



// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('arboreal.json'),
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %> (<%= pkg.author.email %>);' +
' Licensed <%= _.map(pkg.licenses, "type").join(", ") %>; See MIT-LICENSE.txt for more info*/\n',
// Task configuration.
clean: {
files: ['lib/arboreal.min.js']
},
uglify: {
options: {
banner: '<%= banner %>',
mangle: true
},
dist: {
files: [{
'lib/arboreal.min.js': 'lib/arboreal.js',
}]
}
},
jshint: {
options: {
jshintrc: true,
reporterOutput: "",
},
gruntfile: {
src: 'Gruntfile.js'
},
src: {
src: ['lib/**/*.js']
},
test: {
src: ['test/**/*.js']
},
},
watch: {
gruntfile: {
files: '<%= jshint.gruntfile.src %>',
tasks: ['jshint:gruntfile']
},
src: {
files: '',
tasks: ['', '']
},
test: {
files: '<%= jshint.test.src %>',
tasks: ['jshint:test', 'qunit']
},
},
qunit: {
files: ['test/**/*.html']
},

jsdoc : {
dist : {
expand: true,
src: ['lib/**/*.js', 'README.md'],
options: {
destination: 'docs/doc',
template : "node_modules/ink-docstrap/template",
configure : "jsdoc.json",
}
}
},


});

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-jsdoc');


// Default task.
grunt.registerTask('default', ['clean', 'jshint', 'qunit', 'jsdoc','uglify']);

};
4 changes: 4 additions & 0 deletions MIT-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
The MIT License (MIT)
Copyright © 2013 Andrea Fiore
Copyright © 2013 Evgeny Gusev
Copyright © 2014 Alex Pernot
Copyright © 2016 Nenad V. Nikolić
Copyright © 2017 Vasiliy Altunin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
Expand Down
171 changes: 51 additions & 120 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,153 +1,84 @@
# Arboreal.js
[![NPM](https://nodei.co/npm/arboreal.js.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/arboreal.js/)

A micro-library for traversing and manipulating tree-like data
structures in JavaScript; works with both node.js and the browser.

<img src="http://travis-ci.org/afiore/arboreal.png" />

## Installation

In node.js:

git clone git://github.com/afiore/arboreal
npm install

To use it in the browser, just load `lib/arboreal.js` in
a script tag.
# Arboreal.js [![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)

## Usage

Arboreal provides a set of methods for parsing, manipulating, and
traversing tree like data structures. A tree can be created from scratch and then extended with child elements.

var tree = new Arboreal()

tree
.appendChild()
.appendChild()
.children[0]
.appendChild()
.appendChild();

For each child node, Arboreal will automatically assign an id string representing the depth and the index
the position of the node within the tree structure.
[![Build Status](https://travis-ci.org/vasiliyaltunin/arboreal.js.svg?branch=master)](https://travis-ci.org/vasiliyaltunin/arboreal.js) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/vasiliyaltunin/arboreal.js/master/MIT-LICENSE.txt) [![dependencies Status](https://david-dm.org/vasiliyaltunin/arboreal.js/status.svg)](https://david-dm.org/vasiliyaltunin/arboreal.js) [![devDependencies Status](https://david-dm.org/vasiliyaltunin/arboreal.js/dev-status.svg)](https://david-dm.org/vasiliyaltunin/arboreal.js?type=dev)

tree.children[0].children[1].id

// => 0/0/1

Alternatively, Arboreal can also parse an existing object into a tree (though it will need to
know the name of the 'children' attribute).

var wikipediaJsCategory = {
category: 'JavaScript',
subcategories: [
{category: 'Ajax (programming)'},
{category: 'JavaScript engines'},
{category: 'JavaScript programming languages family',
subcategories: [{
category: 'JavaScript dialect engines'
}]
},
{category: 'JavaScript based calendar components'},
{category: 'JavaScript based HTML editors'}
]
};

var tree = Arborel.parse(wikipediaJsCategory, 'subcategories');

### Traversal

An Arboreal object can be traversed either upwards or downwards.

function iterator (node) {
var depth = "", i;
for (i = 1; i <= node.depth; i++) depth += ">>";
console.info([depth, node.data.category].join(" "));
}

tree.traverseDown(iterator);
A micro-library for traversing and manipulating tree-like data
structures in JavaScript, works with both node.js and the browser.

// => JavaScript
// >> Ajax (programming)
// >> JavaScript engines
// >> JavaScript produgramming languages family
// >>>> JavaScript dialect engines
// >> JavaScript based calendar components
// >> JavaScript based HTML editors
(Forked from [Nenad V. Nikolić](https://github.com/shonzilla/arboreal), originally by [Andrea Fiore](https://github.com/afiore/arboreal))

## Installation

tree.children[2].traverseUp(iterator);
Install via npm:

// => >> JavaScript produgramming languages family
// >>>> JavaScript dialect engines
// JavaScript
// >> Ajax (programming)
// >> JavaScript engines
// >> JavaScript based calendar components
// >> JavaScript based HTML editors
```bash
% npm install arboreal.js
```

## Usage

Note that in both the `traverseDown` and the `traverseUp` methods, the
value of `this` in the iterator is bound to the value of the
currently traversed `node`. Our iterator function can in fact be
rewritten as:

function iterator () {
var depth = "", i;
for (i = 1; i <= this.depth; i++) depth += ">>";
console.info([depth, this.data.category].join(" "));
}
Add script to you webpage

### Search
```html
<script src="../lib/arboreal.min.js" type="text/javascript"></script>
```

In order to search for a single node into an arboreal object, one can use the `find`
method.
Arboreal.js provides a set of methods for parsing, manipulating, and
traversing tree like data structures. A tree can be created from scratch and then extended with child elements.

tree.find(function (node) {
return (/calendar/).test(node.data.category)
}).data.category;
var tree = new Arboreal(null, {category: 'JavaScript'});

// => JavaScript based calendar components
tree.appendChild({category: 'Ajax (programming)'})
.appendChild({category: 'JavaScript engines'})
.appendChild({category: 'JavaScript programming languages family'})
.children[2]
.appendChild({category: 'JavaScript dialect engines'})
.parent
.appendChild({category: 'JavaScript based calendar components'})
.appendChild({category: 'JavaScript based HTML editors'});

The find method will also accept a string as an argument. In that case,
it will try to find a node by id.
For each child node, Arboreal.js will automatically assign an id string representing the depth and the index
the position of the node within the tree structure.

tree.find("0/2/0").data.category
0 {"category":"JavaScript"}
|- 0/0 {"category":"Ajax (programming)"}
|- 0/1 {"category":"JavaScript engines"}
|- 0/2 {"category":"JavaScript programming languages family"}
|- 0/2/0 {"category":"JavaScript dialect engines"}
|- 0/3 {"category":"JavaScript based calendar components"}
|- 0/4 {"category":"JavaScript based HTML editors"}

// => JavaScript dialect engines
Check our [wiki](https://github.com/vasiliyaltunin/arboreal.js/wiki) for more usage examples.

### Manipulation
Check our [documentation](https://vasiliyaltunin.github.io/arboreal.js/doc/module-arboreal.html)

While traversing a tree, nodes can be deleted by calling the `remove`
method on the node object bound to the iterator function.
Also check this [demo](https://vasiliyaltunin.github.io/arboreal.js/examples).

tree.length
## Contributing

// => 7
Here's a quick guide:

tree.traverseDown(function (item) {
var toDelete = 'JavaScript programming languages family';
if (item.data.category === toDelete) {
this.remove();
}
});
1. Fork the repo

tree.length;
2. `npm install`

// 5
3. `grunt`

## Testing
4. Make you changes and add test for you functionality. Look into `/test` folder.

Arboreal test suite uses [Jasmine](http://pivotal.github.com/jasmine/).
To run it in node.js..
5. Check that all test passed by running `grunt`

cd /home/me/code/arboreal && npm test
6. Push to your fork and submit a pull request.

To run it in the browser, just open the `test/index.html`

## Minfication

A minified version of Arboreal can be generated by running
A minified version generated into `/lib` when you run `grunt`

## Licence

node make.js
Released under MIT License - https://opensource.org/licenses/MIT
26 changes: 26 additions & 0 deletions arboreal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "arboreal.js",
"title": "Arboreal.js",
"description": "Javascript tree traversal and manipulation library (Forked from Nenad V. Nikolić, originally by Andrea Fiore)",
"version": "0.0.3",
"homepage": "https://github.com/vasiliyaltunin/arboreal.js",
"author": {
"name": "Vasiliy Altunin",
"email": "skyr@altunin.online",
"url": "http://altunin.online"
},
"repository": {
"type": "git",
"url": "git://github.com/vasiliyaltunin/arboreal.git"
},
"bugs": "https://github.com/vasiliyaltunin/arboreal/issues",
"licenses": [
{
"type": "MIT",
"url": "https://opensource.org/licenses/MIT"
}
],
"dependencies": {
},
"keywords": []
}
19 changes: 0 additions & 19 deletions config.json

This file was deleted.

14 changes: 14 additions & 0 deletions contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
###### Contributors
[Nenad V. Nikolić](https://github.com/shonzilla)
<font color="#999">11 Commits</font> / <font color="#6cc644">37++</font> / <font color="#bd3c00"> 22--</font>
<font color="#dedede">57.89%&nbsp;<font color="#dedede">|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||</font><font color="#f4f4f4">|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||</font><br><br>
[EvgenyGusev](https://github.com/EvgenyGusev)
<font color="#999">6 Commits</font> / <font color="#6cc644">124++</font> / <font color="#bd3c00"> 20--</font>
<font color="#dedede">31.58%&nbsp;<font color="#dedede">|||||||||||||||||||||||||||||||||||||||||||||||||||||||||</font><font color="#f4f4f4">|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||</font><br><br>
[Alex Pernot](https://github.com/AlexPernot)
<font color="#999">1 Commits</font> / <font color="#6cc644">7++</font> / <font color="#bd3c00"> 5--</font>
<font color="#dedede">05.26%&nbsp;<font color="#dedede">|||||||||</font><font color="#f4f4f4">|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||</font><br><br>
[Andrea Fiore](https://github.com/afiore)
<font color="#999">1 Commits</font> / <font color="#6cc644">20++</font> / <font color="#bd3c00"> 0--</font>
<font color="#dedede">05.26%&nbsp;<font color="#dedede">|||||||||</font><font color="#f4f4f4">|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||</font><br><br>
###### [Generated](https://github.com/jakeleboeuf/contributor) on Wed Apr 12 2017
Loading