tree-helper
Advanced tools
Comparing version 1.0.0 to 1.0.1
/*! | ||
* tree-helper v1.0.0 | ||
* tree-helper v1.0.1 | ||
* phphe <phphe@outlook.com> (https://github.com/phphe) | ||
@@ -71,2 +71,13 @@ * https://github.com/phphe/tree-helper.git | ||
} | ||
function getTreeDataFromFlat(data, idKey, parentIdKey) { | ||
data.forEach(function (item) { | ||
return item.children = data.filter(function (v) { | ||
return v[parentIdKey] === item[idKey]; | ||
}); | ||
}); | ||
return data.filter(function (item) { | ||
return item[parentIdKey] == null; | ||
}); | ||
} | ||
function insertBefore(item, target) { | ||
@@ -119,2 +130,3 @@ var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
exports.forIn = forIn; | ||
exports.getTreeDataFromFlat = getTreeDataFromFlat; | ||
exports.insertBefore = insertBefore; | ||
@@ -121,0 +133,0 @@ exports.insertAfter = insertAfter; |
/*! | ||
* tree-helper v1.0.0 | ||
* tree-helper v1.0.1 | ||
* phphe <phphe@outlook.com> (https://github.com/phphe) | ||
@@ -67,2 +67,13 @@ * https://github.com/phphe/tree-helper.git | ||
} | ||
function getTreeDataFromFlat(data, idKey, parentIdKey) { | ||
data.forEach(function (item) { | ||
return item.children = data.filter(function (v) { | ||
return v[parentIdKey] === item[idKey]; | ||
}); | ||
}); | ||
return data.filter(function (item) { | ||
return item[parentIdKey] == null; | ||
}); | ||
} | ||
function insertBefore(item, target) { | ||
@@ -113,2 +124,2 @@ var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
export { clone, forIn, insertBefore, insertAfter, prependTo, appendTo }; | ||
export { clone, forIn, getTreeDataFromFlat, insertBefore, insertAfter, prependTo, appendTo }; |
/*! | ||
* tree-helper v1.0.0 | ||
* tree-helper v1.0.1 | ||
* phphe <phphe@outlook.com> (https://github.com/phphe) | ||
@@ -175,2 +175,13 @@ * https://github.com/phphe/tree-helper.git | ||
} | ||
function getTreeDataFromFlat(data, idKey, parentIdKey) { | ||
data.forEach(function (item) { | ||
return item.children = data.filter(function (v) { | ||
return v[parentIdKey] === item[idKey]; | ||
}); | ||
}); | ||
return data.filter(function (item) { | ||
return item[parentIdKey] == null; | ||
}); | ||
} | ||
function insertBefore(item, target) { | ||
@@ -223,2 +234,3 @@ var childrenKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children'; | ||
exports.forIn = forIn; | ||
exports.getTreeDataFromFlat = getTreeDataFromFlat; | ||
exports.insertBefore = insertBefore; | ||
@@ -225,0 +237,0 @@ exports.insertAfter = insertAfter; |
/*! | ||
* tree-helper v1.0.0 | ||
* tree-helper v1.0.1 | ||
* phphe <phphe@outlook.com> (https://github.com/phphe) | ||
@@ -8,3 +8,3 @@ * https://github.com/phphe/tree-helper.git | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.treeHelper=e.treeHelper||{})}(this,function(e){"use strict";function n(e){return"[object Array]"===Object.prototype.toString.call(e)}function t(e,n){var t=e.indexOf(n);return t>-1&&e.splice(t,1),e}function r(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"children",i=void 0;return n(e)?i=e.map(function(e){return r(e)}):(i=Object.assign({},e),i[t]&&(i[t]=r(i[t]))),i}function i(e,t){var r,i,o,l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children";return n(e)?(r=e,i=null):(r=[e],i=null),r&&(o=function(e,n){for(var r in e){var i=e[r];if(!1===t(i,r,n))return!1;if(null!=i[l]&&!1===o(i[l],i))return!1}return!0})(r,i),e}function o(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent";e[i]&&t(e[i][r],e),e[i]=n}function l(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent",i=n[r][t],l=i.indexOf(n);i[l-1]!==e&&(o(e,n[r]),i.splice(l,0,e))}function d(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent",i=n[r],l=i[t],d=l.indexOf(n);l[d+1]!==e&&(o(e,n[r]),l.splice(d+1,0,e))}function c(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",r=(arguments.length>3&&void 0!==arguments[3]&&arguments[3],n[t]);r[0]!==e&&(o(e,n),r.splice(0,0,e))}function f(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",r=(arguments.length>3&&void 0!==arguments[3]&&arguments[3],n[t]);r[r.length-1]!==e&&(o(e,n),r.push(e))}e.clone=r,e.forIn=i,e.insertBefore=l,e.insertAfter=d,e.prependTo=c,e.appendTo=f,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(n.treeHelper=n.treeHelper||{})}(this,function(n){"use strict";function e(n){return"[object Array]"===Object.prototype.toString.call(n)}function t(n,e){var t=n.indexOf(e);return t>-1&&n.splice(t,1),n}function r(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"children",i=void 0;return e(n)?i=n.map(function(n){return r(n)}):(i=Object.assign({},n),i[t]&&(i[t]=r(i[t]))),i}function i(n,t){var r,i,o,l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children";return e(n)?(r=n,i=null):(r=[n],i=null),r&&(o=function(n,e){for(var r in n){var i=n[r];if(!1===t(i,r,e))return!1;if(null!=i[l]&&!1===o(i[l],i))return!1}return!0})(r,i),n}function o(n,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent";n[i]&&t(n[i][r],n),n[i]=e}function l(n,e,t){return n.forEach(function(r){return r.children=n.filter(function(n){return n[t]===r[e]})}),n.filter(function(n){return null==n[t]})}function u(n,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent",i=e[r][t],l=i.indexOf(e);i[l-1]!==n&&(o(n,e[r]),i.splice(l,0,n))}function c(n,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"parent",i=e[r],l=i[t],u=l.indexOf(e);l[u+1]!==n&&(o(n,e[r]),l.splice(u+1,0,n))}function f(n,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",r=(arguments.length>3&&void 0!==arguments[3]&&arguments[3],e[t]);r[0]!==n&&(o(n,e),r.splice(0,0,n))}function d(n,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"children",r=(arguments.length>3&&void 0!==arguments[3]&&arguments[3],e[t]);r[r.length-1]!==n&&(o(n,e),r.push(n))}n.clone=r,n.forIn=i,n.getTreeDataFromFlat=l,n.insertBefore=u,n.insertAfter=c,n.prependTo=f,n.appendTo=d,Object.defineProperty(n,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=tree-helper.min.js.map |
{ | ||
"name": "tree-helper", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/tree-helper.common.js", |
@@ -51,2 +51,7 @@ import { isArray, arrayRemove } from 'helper-js' | ||
} | ||
export function getTreeDataFromFlat(data, idKey, parentIdKey) { | ||
data.forEach(item => (item.children = data.filter(v => v[parentIdKey] === item[idKey]))) | ||
return data.filter(item => item[parentIdKey] == null) | ||
} | ||
export function insertBefore(item, target, childrenKey = 'children', parentKey = 'parent') { | ||
@@ -53,0 +58,0 @@ const sibilings = target[parentKey][childrenKey] |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25180
556