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.2.1 to 2.3.0

2

package.json
{
"name": "enmap",
"version": "2.2.1",
"version": "2.3.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -184,2 +184,48 @@ /**

/**
* Push to an array value in Enmap.
* @param {string|number} key Required. The key of the array element to push to in Enmap.
* This value MUST be a string or number.
* @param {*} val Required. The value to push to the array.
* @param {boolean} allowDupes Allow duplicate values in the array (default: false).
* @return {Map} The EnMap.
*/
push(key, val, allowDupes = false) {
if (!this.has(key)) {
throw 'This key does not exist';
}
const data = super.get(key);
if (data.constructor.name !== 'Array') {
throw 'Method can only be used when the value is an Array';
}
if (!allowDupes && data.indexOf(val) > -1) return this;
data.push(val);
return super.set(key, data);
}
/**
* Push to an array element inside an Object or Array element in Enmap.
* @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 push to.
* @param {*} val Required. The value push to the array property.
* @param {boolean} allowDupes Allow duplicate values in the array (default: false).
* @return {Map} The EnMap.
*/
pushIn(key, prop, val, allowDupes = false) {
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';
}
if (data[prop].constructor.name !== 'Array') {
throw 'Method can only be used when the property is an Array';
}
if (!allowDupes && data[prop].indexOf(val) > -1) return this;
data[prop].push(val);
return super.set(key, data);
}
/**
* Modify the property of a value inside the enmap, if the value is an object or array.

@@ -186,0 +232,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