un-flatten-tree
Advanced tools
Comparing version
{ | ||
"name": "un-flatten-tree", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "Functions for converting trees to lists and vice versa.", | ||
@@ -37,7 +37,3 @@ "main": "un-flatten-tree.js", | ||
}, | ||
"dependencies": { | ||
"lodash.find": "^4.2.0", | ||
"lodash.map": "^4.2.1", | ||
"lodash.transform": "^4.2.1" | ||
} | ||
"dependencies": {} | ||
} |
(function(root) { | ||
'use strict'; | ||
var transform = (root._ && root._.transform) || require('lodash.transform'); | ||
var map = (root._ && root._.map) || require('lodash.map'); | ||
var find = (root._ && root._.find) || require('lodash.find'); | ||
var map = Array.prototype.map; | ||
var reduce = Array.prototype.reduce; | ||
function find(list, predicate) { | ||
for (var i = 0, len = list.length; i < len; i++) { | ||
if (predicate(list[i])) { | ||
return list[i]; | ||
} | ||
} | ||
return undefined; | ||
} | ||
@@ -47,4 +56,6 @@ function identity(x) { | ||
function unflattenTree(list, isChildNode, addChildNode, convertNode) { | ||
list = list || []; | ||
if (convertNode === undefined) { | ||
return transform(list, function (tree, node) { | ||
return reduce.call(list, function (tree, node) { | ||
@@ -61,6 +72,8 @@ var parentNode = find(list, function (parentNode) { | ||
} | ||
return tree; | ||
}, []); | ||
} else { | ||
list = map(list, function (node) { | ||
list = map.call(list, function (node) { | ||
return { | ||
@@ -72,3 +85,3 @@ in: node, | ||
return transform(list, function (tree, node) { | ||
return reduce.call(list, function (tree, node) { | ||
@@ -90,2 +103,4 @@ var parentNode = find(list, function (parentNode) { | ||
} | ||
return tree; | ||
}, []); | ||
@@ -92,0 +107,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(n){"use strict";function o(n){return n}function t(n,t,e,r){e=void 0===e?o:e;for(var u,i=n&&n.length?[{pointer:n,offset:0}]:[],f=[];i.length;)for(u=i.pop();u.offset<u.pointer.length;){var d=u.pointer[u.offset],s=void 0===r?void 0:r(d),p=t(d);f.push(e(d,u.node,s,u.nodeId)),u.offset++,p&&(i.push(u),u={pointer:p,offset:0,node:d,nodeId:s})}return f}function e(n,o,t,e){return void 0===e?r(n,function(e,r){var u=i(n,function(n){return o(r,n)});void 0===u?e.push(r):t(r,u)},[]):(n=u(n,function(n){return{"in":n,out:e(n)}}),r(n,function(e,r){var u=i(n,function(n){return o(r["in"],n["in"])});void 0===u?e.push(r.out):t(r.out,i(n,function(n){return n["in"]===u["in"]}).out)},[]))}var r=n._&&n._.transform||require("lodash.transform"),u=n._&&n._.map||require("lodash.map"),i=n._&&n._.find||require("lodash.find"),f={flatten:t,unflatten:e};"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=f:n.uft=f}(this); | ||
!function(n){"use strict";function t(n,t){for(var o=0,e=n.length;e>o;o++)if(t(n[o]))return n[o]}function o(n){return n}function e(n,t,e,r){e=void 0===e?o:e;for(var u,f=n&&n.length?[{pointer:n,offset:0}]:[],i=[];f.length;)for(u=f.pop();u.offset<u.pointer.length;){var d=u.pointer[u.offset],p=void 0===r?void 0:r(d),c=t(d);i.push(e(d,u.node,p,u.nodeId)),u.offset++,c&&(f.push(u),u={pointer:c,offset:0,node:d,nodeId:p})}return i}function r(n,o,e,r){return n=n||[],void 0===r?f.call(n,function(r,u){var f=t(n,function(n){return o(u,n)});return void 0===f?r.push(u):e(u,f),r},[]):(n=u.call(n,function(n){return{"in":n,out:r(n)}}),f.call(n,function(r,u){var f=t(n,function(n){return o(u["in"],n["in"])});return void 0===f?r.push(u.out):e(u.out,t(n,function(n){return n["in"]===f["in"]}).out),r},[]))}var u=Array.prototype.map,f=Array.prototype.reduce,i={flatten:e,unflatten:r};"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=i:n.uft=i}(this); |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
23006
0.54%0
-100%520
1.96%0
-100%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed