Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tree-crawl

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-crawl - npm Package Compare versions

Comparing version 0.5.0 to 0.6.1

305

dist/tree-crawl.browser.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.treeCrawl = factory());
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.treeCrawl = factory());
}(this, (function () { 'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**

@@ -13,3 +17,3 @@ * Enum of context flags.

*/
const FLAGS = {
var FLAGS = {
siblings: 0x0001,

@@ -34,7 +38,10 @@ children: 0x0010,

*/
class Context {
var Context = function () {
/**
* Create a context.
*/
constructor() {
function Context() {
_classCallCheck(this, Context);
this._path = [];

@@ -48,130 +55,176 @@ this._index = -1;

*/
walk() {
this._flags = FLAGS.walk;
}
/**
* Break the walk, any further nodes won't be visited.
*/
break() {
this._flags = FLAGS.break;
}
/**
* Skip current node, any children won't be visited.
*/
skip() {
this._flags = FLAGS.siblings;
}
_createClass(Context, [{
key: "walk",
value: function walk() {
this._flags = FLAGS.walk;
}
/**
* Remove current node, any children won't be visited and walk will visit
* the next siblings correctly.
*/
remove() {
this._flags = FLAGS.siblings | FLAGS.remove;
}
/**
* Break the walk, any further nodes won't be visited.
*/
/**
* Replace current node with given one, walk will only visit the new node
* children.
*
* @param {Object} node Replacement node.
*/
replace(node) {
this._replace = node;
this._flags = FLAGS.walk | FLAGS.replace;
}
}, {
key: "break",
value: function _break() {
this._flags = FLAGS.break;
}
/**
* Set a flag, keeping other flags already set.
*
* @private
* @param {FLAGS} flag Flag to set.
*/
set(flag) {
this._flags |= FLAGS[flag];
}
/**
* Skip current node, any children won't be visited.
*/
/**
* Unset a flag, keeping other flags already set.
*
* @private
* @param {FLAGS} flag Flag to unset.
*/
unset(flag) {
this._flags &= ~FLAGS[flag];
}
}, {
key: "skip",
value: function skip() {
this._flags = FLAGS.siblings;
}
/**
* Check if context has the given flag set.
*
* @private
* @param {FLAGS} flag Flag to check.
* @return {boolean} `true` if it has the flag, otherwize `false`.
*/
has(flag) {
return 0 !== (this._flags & FLAGS[flag]);
}
/**
* Remove current node, any children won't be visited and walk will visit
* the next siblings correctly.
*/
/**
* Check if context only has the given flag set.
*
* @private
* @param {FLAGS} flag Flag to check.
* @return {boolean} `true` if it is the only flag set, otherwize `false`.
*/
is(flag) {
return this._flags === FLAGS[flag];
}
}, {
key: "remove",
value: function remove() {
this._flags = FLAGS.siblings | FLAGS.remove;
}
/**
* Get the **path** of the current node. The path is an array of nodes to
* traverse from the root included to the current node.
*
* @return {Array} Array of nodes.
*/
get path() {
return this._path;
}
/**
* Replace current node with given one, walk will only visit the new node
* children.
*
* @param {Object} node Replacement node.
*/
/**
* Get the parent of the current node.
*
* @return {Object} Parent of the current node.
*/
get parent() {
return this._path[this._path.length - 1];
}
}, {
key: "replace",
value: function replace(node) {
this._replace = node;
this._flags = FLAGS.walk | FLAGS.replace;
}
/**
* Get the index of the current node.
*
* @return {number} Index of the current node.
*/
get index() {
return this._index;
}
/**
* Set a flag, keeping other flags already set.
*
* @private
* @param {FLAGS} flag Flag to set.
*/
/**
* Get the **depth** of the current node. The depth is the number of
* ancestors the current node has.
*
* @return {number} Depth of current node.
*/
get depth() {
return this._path.length;
}
}, {
key: "set",
value: function set(flag) {
this._flags |= FLAGS[flag];
}
/**
* Get the **level** of current node. The level is the number of ancestors+1
* the current node has.
*
* @return {number} Level of current node.
*/
get level() {
return this._path.length + 1;
}
}
/**
* Unset a flag, keeping other flags already set.
*
* @private
* @param {FLAGS} flag Flag to unset.
*/
}, {
key: "unset",
value: function unset(flag) {
this._flags &= ~FLAGS[flag];
}
/**
* Check if context has the given flag set.
*
* @private
* @param {FLAGS} flag Flag to check.
* @return {boolean} `true` if it has the flag, otherwize `false`.
*/
}, {
key: "has",
value: function has(flag) {
return 0 !== (this._flags & FLAGS[flag]);
}
/**
* Check if context only has the given flag set.
*
* @private
* @param {FLAGS} flag Flag to check.
* @return {boolean} `true` if it is the only flag set, otherwize `false`.
*/
}, {
key: "is",
value: function is(flag) {
return this._flags === FLAGS[flag];
}
/**
* Get the **path** of the current node. The path is an array of nodes to
* traverse from the root included to the current node.
*
* @return {Array} Array of nodes.
*/
}, {
key: "path",
get: function get() {
return this._path;
}
/**
* Get the parent of the current node.
*
* @return {Object} Parent of the current node.
*/
}, {
key: "parent",
get: function get() {
return this._path[this._path.length - 1];
}
/**
* Get the index of the current node.
*
* @return {number} Index of the current node.
*/
}, {
key: "index",
get: function get() {
return this._index;
}
/**
* Get the **depth** of the current node. The depth is the number of
* ancestors the current node has.
*
* @return {number} Depth of current node.
*/
}, {
key: "depth",
get: function get() {
return this._path.length;
}
/**
* Get the **level** of current node. The level is the number of ancestors+1
* the current node has.
*
* @return {number} Level of current node.
*/
}, {
key: "level",
get: function get() {
return this._path.length + 1;
}
}]);
return Context;
}();
/**

@@ -188,3 +241,3 @@ * Iterate over children of a given node.

function eachChild(node, iteratee, options, context, walker) {
const children = node[options.childrenKey];
var children = node[options.childrenKey];

@@ -197,4 +250,4 @@ // early return if no children

for (let i = 0; i < children.length; i++) {
const child = children[i];
for (var i = 0; i < children.length; i++) {
var child = children[i];
context._index = i;

@@ -267,3 +320,3 @@ walker(child, iteratee, options, context);

// save current index
const index = context.index;
var index = context.index;

@@ -314,3 +367,3 @@ // iterate over children

// create a context for this walk
const context = new Context();
var context = new Context();

@@ -327,2 +380,2 @@ // walk in `pre`/`post` order

})));
})));

@@ -314,2 +314,2 @@ 'use strict';

module.exports = crawl;
module.exports = crawl;
{
"name": "tree-crawl",
"version": "0.5.0",
"version": "0.6.1",
"description": "n-ary tree traversal library.",

@@ -13,3 +13,3 @@ "author": "Nicolas Gryman <ngryman@gmail.com> (http://ngryman.sh/)",

"engines": {
"node": ">=4"
"node": ">=5"
},

@@ -66,7 +66,9 @@ "files": [

"env": {
"development": {
"test": {
"presets": [
"node5"
],
"plugins": [
"transform-es2015-modules-commonjs"
],
"sourceMaps": "inline"
"istanbul"
]
}

@@ -78,8 +80,15 @@ }

},
"nyc": {
"require": [
"babel-register"
],
"sourceMap": false,
"instrument": false
},
"dependencies": {},
"devDependencies": {
"clone": "^2.0.0",
"meta-dev": "^0.3.3",
"meta-dev": "^0.4.2",
"pre-commit": "^1.1.3"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc