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

enmap

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enmap - npm Package Compare versions

Comparing version 2.4.0 to 2.4.1

2

package.json
{
"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.

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