Comparing version 1.4.1 to 1.4.2
@@ -0,0 +0,0 @@ # Contributor Covenant Code of Conduct |
@@ -120,2 +120,3 @@ # Introduction | ||
3. Slack | ||
4. Terminal Chat | ||
4. Terminal Chat | ||
66
index.js
@@ -6,2 +6,54 @@ /** | ||
/** | ||
* Performs deep search on object tree, removes all properties with matching key, returns a new identity without the specified property | ||
* @param {Any} identity | ||
* @param {string} keyName | ||
* @param {string} newKeyName | ||
* @param {Optional Number} maxDepth | ||
* @return {Any} identity | ||
*/ | ||
function deepRemoveAll_Key(identity,keyName,maxDepth){ | ||
if(getType(keyName)!=='string') return undefined; | ||
if(keyName==='') return undefined; | ||
let clonedIdentity = deepClone(identity); | ||
var paths = locateAll_Key(clonedIdentity,keyName,maxDepth); | ||
if(paths===[]||paths===false) return clonedIdentity; | ||
paths.forEach( path => { | ||
if(path === '') path = keyName; else path += ('.' + keyName); | ||
path = path.split('.'); | ||
var ref = clonedIdentity; | ||
if(!Array.isArray(path)) delete ref[path]; | ||
for(var i = 0; i < path.length; i++){ | ||
var key = path[i]; | ||
if(key in ref){ | ||
if(i<path.length-1) ref = ref[key]; else delete ref[key]; | ||
} | ||
else break; | ||
} | ||
}); | ||
return clonedIdentity; | ||
} | ||
/** | ||
* Performs deep search on object tree, removes the first property with matching key, returns a new identity without the specified property | ||
* @param {Any} identity | ||
* @param {string} keyName | ||
* @param {string} newKeyName | ||
* @param {Optional Number} maxDepth | ||
* @return {Any} identity | ||
*/ | ||
function deepRemove_Key(identity,keyName,maxDepth){ | ||
if(getType(keyName)!=='string') return undefined; | ||
if(keyName==='') return undefined; | ||
let clonedIdentity = deepClone(identity); | ||
var path = locate_Key(clonedIdentity,keyName,maxDepth); | ||
if(path === false) return clonedIdentity; | ||
if(path === '') path = keyName; else path += ('.' + keyName); | ||
path = path.split('.'); | ||
var ref = clonedIdentity; | ||
if(!Array.isArray(path)) delete ref[path]; | ||
path.forEach( (key,i) => { if(i<path.length-1) ref = ref[key]; else delete ref[key]; }); | ||
return clonedIdentity; | ||
} | ||
/** | ||
* Performs deep search on object tree, and renames the all matching keys | ||
@@ -12,2 +64,3 @@ * @param {Any} identity | ||
* @param {Optional Number} maxDepth | ||
* @return {Any} identity | ||
*/ | ||
@@ -17,2 +70,4 @@ function renameKeys(identity,keyName,newKeyName,maxDepth=null){ | ||
if(getType(newKeyName)!=='string') return undefined; | ||
if(keyName==='') return undefined; | ||
if(newKeyName==='') return undefined; | ||
function _renameKeys(identity,keyName,newKeyName,maxDepth,currentDepth=0){ | ||
@@ -59,2 +114,3 @@ let keys; | ||
* @param {Optional Number} maxDepth | ||
* @return {Any} identity | ||
*/ | ||
@@ -64,2 +120,4 @@ function renameKey(identity,keyName,newKeyName,maxDepth=null){ | ||
if(getType(newKeyName)!=='string') return undefined; | ||
if(keyName==='') return undefined; | ||
if(newKeyName==='') return undefined; | ||
var applied=false; | ||
@@ -168,2 +226,3 @@ function _renameKey(identity,keyName,newKeyName,maxDepth,currentDepth=0){ | ||
if(getType(keyName)!=='string') return undefined; | ||
if(keyName==='') return undefined; | ||
var paths = locateAll_Key(collection,keyName,maxDepth); | ||
@@ -192,2 +251,3 @@ if(paths === false) return undefined; | ||
if(getType(keyName)!=='string') return undefined; | ||
if(keyName==='') return undefined; | ||
var R = []; | ||
@@ -225,2 +285,3 @@ function _locateAll_Key(collection,keyName,xKey='',path='',maxDepth=null,currentDepth=0){ | ||
if(getType(keyName)!=='string') return undefined; | ||
if(keyName==='') return undefined; | ||
var path = locate_Key(collection,keyName,maxDepth); | ||
@@ -245,2 +306,3 @@ if(path === false) return undefined; | ||
if(getType(keyName)!=='string') return undefined; | ||
if(keyName==='') return undefined; | ||
function _locate_Key(collection,keyName,path='',maxDepth,currentDepth=0){ | ||
@@ -828,5 +890,7 @@ if(path===keyName) return path; | ||
renameKey : function(identity,keyName,newKeyName,maxDepth) { return renameKey(identity,keyName,newKeyName,maxDepth); }, | ||
renameKeys : function(identity,keyName,newKeyName,maxDepth) { return renameKeys(identity,keyName,newKeyName,maxDepth); } | ||
renameKeys : function(identity,keyName,newKeyName,maxDepth) { return renameKeys(identity,keyName,newKeyName,maxDepth); }, | ||
deepRemove_Key : function(identity,keyName,maxDepth) { return deepRemove_Key(identity,keyName,maxDepth); }, | ||
deepRemoveAll_Key : function(identity,keyName,maxDepth) { return deepRemoveAll_Key(identity,keyName,maxDepth); } | ||
} | ||
module.exports = exports = mitsuketa; |
@@ -5,2 +5,2 @@ 1. What version of Mitsuketa are you using (mitsuketa version)? | ||
4. What did you expect to see? | ||
5. What did you see instead? | ||
5. What did you see instead? |
{ | ||
"name": "mitsuketa", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "A Javascript library that enables you to handle deeply nested objects easily.", | ||
@@ -20,3 +20,8 @@ "main": "index.js", | ||
"deepsearch", | ||
"list filtering" | ||
"list filtering", | ||
"cloning", | ||
"deep comparison", | ||
"nested objects", | ||
"handling nested objects", | ||
"react-json-editor-ajrm" | ||
], | ||
@@ -36,2 +41,2 @@ "author": "Andrew Redican", | ||
} | ||
} | ||
} |
Sorry, the diff of this file is too big to display
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
136202
2581
83
9