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

easy-tree

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-tree - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

24

index.js

@@ -182,17 +182,21 @@ function Tree(obj) {

if (typeof p != 'number') {
self._throwPathError(path, i, 'not a number');
self._throwPathError(path, i, 'is not a number');
}
if (p % 1) {
self._throwPathError(path, i, 'not an integer');
self._throwPathError(path, i, 'is not an integer');
}
var min = 0 - nRelaxMin,
max = treeCurrent.children.length - 1 + nRelaxMax;
var skip = (i >= path.length - nSkip),
min = 0 - (skip ? nRelaxMin : 0),
max = treeCurrent.children.length - 1 + (skip ? nRelaxMax : 0);
if (max < min) {
self._throwPathError(path, i, 'refers to a non-existent element');
}
if (p < min) {
self._throwPathError(path, i, 'below minimum value of ' + min);
self._throwPathError(path, i, 'is below minimum value of ' + min);
}
if (p > max) {
self._throwPathError(path, i, 'above maximum value of ' + max);
self._throwPathError(path, i, 'is above maximum value of ' + max);
}
treeCurrent = treeCurrent.children[p];
if (i < path.length - nSkip) {
if (!skip) {
treeFinal = treeCurrent;

@@ -213,9 +217,9 @@ }

return p.toString();
}).join(', ') + ' ]:';
}).join(', ') + ' ]: ';
if (typeof i == 'number') {
msg += ' ' + path[i] + ' (index ' + i + ') is';
msg += path[i] + ' (index ' + i + ') ';
}
throw new Error(msg + ' ' + problem + '.');
throw new Error(msg + problem + '.');
};

@@ -222,0 +226,0 @@

@@ -5,3 +5,3 @@ {

"description" : "Simple library to manipulate tree data structures.",
"version" : "0.0.1",
"version" : "0.0.2",
"repository" : {

@@ -8,0 +8,0 @@ "type" : "git",

@@ -200,2 +200,14 @@ var fs = require('fs'),

it('cannot insert nodes before a non-existent subtree 1', function() {
(function() {
tree.insertBefore([0, 1, 0, 0], { z : 26 });
}).must.throw('Bad tree path [ 0, 1, 0, 0 ]: 0 (index 2) refers to a non-existent element.');
});
it('cannot insert nodes before a non-existent subtree 2', function() {
(function() {
tree.insertBefore([1, 3, 0], { z : 26 });
}).must.throw('Bad tree path [ 1, 3, 0 ]: 3 (index 1) is above maximum value of 2.');
});
it('inserts nodes in the middle of a subtree', function() {

@@ -271,2 +283,14 @@ tree.insertBefore([0, 2], { z : 26 }).must.equal(4);

it('cannot insert nodes after a non-existent subtree 1', function() {
(function() {
tree.insertAfter([0, 1, -1, 0], { z : 26 });
}).must.throw('Bad tree path [ 0, 1, -1, 0 ]: -1 (index 2) refers to a non-existent element.');
});
it('cannot insert nodes after a non-existent subtree 2', function() {
(function() {
tree.insertAfter([1, -1, 0], { z : 26 });
}).must.throw('Bad tree path [ 1, -1, 0 ]: -1 (index 1) is below minimum value of 0.');
});
it('inserts nodes in the middle of a subtree', function() {

@@ -273,0 +297,0 @@ tree.insertAfter([0, 1], { z : 26 }).must.equal(4);

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