Comparing version 2.4.0 to 2.4.1
{ | ||
"name": "enmap", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -219,3 +219,3 @@ /** | ||
if (typeof data !== 'object') { | ||
throw 'Method can only be used when the value is an object'; | ||
throw 'Method can only be used when the value is an object or array'; | ||
} | ||
@@ -231,2 +231,57 @@ if (data[prop].constructor.name !== 'Array') { | ||
/** | ||
* Remove a value in an Array or Object element in Enmap. Note that this only works for | ||
* values, not keys. Complex values such as objects and arrays will not be removed this way. | ||
* @param {string|number} key Required. The key of the element to remove from in Enmap. | ||
* This value MUST be a string or number. | ||
* @param {*} val Required. The value to remove from the array or object. | ||
* @param {boolean} allowDupes Allow duplicate values in the array (default: false). | ||
* @return {Map} The EnMap. | ||
*/ | ||
remove(key, val) { | ||
if (!this.has(key)) { | ||
throw 'This key does not exist'; | ||
} | ||
const data = super.get(key); | ||
if (typeof data !== 'object') { | ||
throw 'Method can only be used when the value is an object or array'; | ||
} | ||
if (data.constructor.name === 'Array') { | ||
const index = data.indexOf(val); | ||
return super.set(key, data.slice(index, 1)); | ||
} else { | ||
delete data[key]; | ||
return super.set(key, data); | ||
} | ||
} | ||
/** | ||
* Remove a value from an Array or Object property inside an Array or Object element in Enmap. | ||
* Confusing? Sure is. | ||
* @param {string|number} key Required. The key of the element. | ||
* This value MUST be a string or number. | ||
* @param {*} prop Required. The name of the array property to remove from. | ||
* @param {*} val Required. The value to remove from the array property. | ||
* @return {Map} The EnMap. | ||
*/ | ||
removeFrom(key, prop, val) { | ||
if (!this.has(key)) { | ||
throw 'This key does not exist'; | ||
} | ||
const data = super.get(key); | ||
if (typeof data !== 'object') { | ||
throw 'Method can only be used when the value is an object or array'; | ||
} | ||
if (data[prop].constructor.name === 'Array') { | ||
let propdata = data[prop]; | ||
const index = propdata.indexOf(val); | ||
propdata = propdata.slice(index, 1); | ||
data[prop] = propdata; | ||
return super.set(key, data); | ||
} else { | ||
delete data[prop][key]; | ||
return super.set(key, data); | ||
} | ||
} | ||
/** | ||
* Modify the property of a value inside the enmap, if the value is an object or array. | ||
@@ -233,0 +288,0 @@ * This is a shortcut to loading the key, changing the value, and setting it back. |
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
95531
1320