Comparing version 3.0.3 to 3.0.4
{ | ||
"name": "enmap", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
176
README.md
@@ -22,4 +22,2 @@ # Enmap - Enhanced Maps | ||
Future versions will have ways to load partial or temporary values, etc. | ||
## Installation | ||
@@ -156,4 +154,26 @@ | ||
## UPDATING TO ENMAP 3.0 | ||
Enmap version 3.0 has some breaking changes that are important to consider when updating. These changes are: | ||
- setProp, hasProp, getProp, removeFrom, pushIn have all been removed. These methods are now merged into their regular counterpart, | ||
which now have a new argument: "path". The path is previously what prop methods called "prop" and is the direct path to the property you want to change. | ||
Please see examples in the docs for more details on these methods. Usually you only have to remove the `Prop` word from the method. For `setProp` to `set`, however, | ||
pay more attention to the order of the arguments: `set(key, value, path)` instead of `setProp(key, path, value)`. | ||
- setAsync, deleteAsync were removed from Enmap. I didn't honestly see a use for them, the only time I've ever had to use them was in testing, I will figure out a | ||
different way to "wait for all changes to be written before <insert action here>". | ||
- math(), inc() and dec() were added to 2.7.3 but I didn't really advertise them. Now they're here and they're documented. | ||
## API Documentation | ||
<<<<<<< HEAD | ||
## Enmap ⇐ <code>Map</code> | ||
A enhanced Map structure with additional utility methods. | ||
Can be made persistent | ||
**Kind**: global class | ||
**Extends**: <code>Map</code> | ||
======= | ||
>>>>>>> v3 | ||
* [Enmap](#Enmap) ⇐ <code>Map</code> | ||
@@ -166,5 +186,9 @@ * _instance_ | ||
* [.set(key, val, path)](#Enmap+set) ⇒ <code>Map</code> | ||
<<<<<<< HEAD | ||
* [.push(key, val, path, allowDupes)](#Enmap+push) ⇒ <code>Map</code> | ||
======= | ||
* [.setProp(key, path, val)](#Enmap+setProp) ⇒ <code>Map</code> | ||
* [.push(key, val, path, allowDupes)](#Enmap+push) ⇒ <code>Map</code> | ||
* [.pushIn(key, path, val, allowDupes)](#Enmap+pushIn) ⇒ <code>Map</code> | ||
>>>>>>> v3 | ||
* [.math(key, operation, operand, path)](#Enmap+math) ⇒ <code>Map</code> | ||
@@ -174,2 +198,8 @@ * [.inc(key, path)](#Enmap+inc) ⇒ <code>Map</code> | ||
* [.get(key, path)](#Enmap+get) ⇒ <code>\*</code> | ||
<<<<<<< HEAD | ||
* [.has(key, path)](#Enmap+has) ⇒ <code>boolean</code> | ||
* [.delete(key, path)](#Enmap+delete) | ||
* [.deleteAll(bulk)](#Enmap+deleteAll) | ||
* [.remove(key, val, path)](#Enmap+remove) ⇒ <code>Map</code> | ||
======= | ||
* [.getProp(key, path)](#Enmap+getProp) ⇒ <code>\*</code> | ||
@@ -183,2 +213,3 @@ * [.has(key, path)](#Enmap+has) ⇒ <code>boolean</code> | ||
* [.removeFrom(key, path, val)](#Enmap+removeFrom) ⇒ <code>Map</code> | ||
>>>>>>> v3 | ||
* [.array()](#Enmap+array) ⇒ <code>Array</code> | ||
@@ -273,2 +304,4 @@ * [.keyArray()](#Enmap+keyArray) ⇒ <code>Array</code> | ||
enmap.set('ArraysToo', [1, "two", "tree", "foor"]) | ||
<<<<<<< HEAD | ||
======= | ||
@@ -293,3 +326,8 @@ // Settings Properties | ||
| val | <code>\*</code> | Required. The value to apply to the specified property. | | ||
>>>>>>> v3 | ||
// Settings Properties | ||
enmap.set('IhazObjects', 'color', 'blue'); //modified previous object | ||
enmap.set('ArraysToo', 2, 'three'); // changes "tree" to "three" in array. | ||
``` | ||
<a name="Enmap+push"></a> | ||
@@ -309,2 +347,3 @@ | ||
| allowDupes | <code>boolean</code> | <code>false</code> | Optional. Allow duplicate values in the array (default: false). | | ||
<<<<<<< HEAD | ||
@@ -320,2 +359,17 @@ **Example** | ||
``` | ||
<a name="Enmap+math"></a> | ||
### enmap.math(key, operation, operand, path) ⇒ <code>Map</code> | ||
Executes a mathematical operation on a value and saves it in the enmap. | ||
======= | ||
**Example** | ||
```js | ||
// Assuming | ||
enmap.set("simpleArray", [1, 2, 3, 4]); | ||
enmap.set("arrayInObject", {sub: [1, 2, 3, 4]}); | ||
enmap.push("simpleArray", 5); // adds 5 at the end of the array | ||
enmap.push("arrayInObject", "five", "sub"); adds "five" at the end of the sub array | ||
``` | ||
<a name="Enmap+pushIn"></a> | ||
@@ -325,2 +379,3 @@ | ||
Push to an array element inside an Object or Array element in Enmap. | ||
>>>>>>> v3 | ||
@@ -332,2 +387,9 @@ **Kind**: instance method of [<code>Enmap</code>](#Enmap) | ||
| --- | --- | --- | --- | | ||
<<<<<<< HEAD | ||
| key | <code>string</code> \| <code>number</code> | | The enmap key on which to execute the math operation. | | ||
| operation | <code>string</code> | | Which mathematical operation to execute. Supports most math ops: =, -, *, /, %, ^, and english spelling of those operations. | | ||
| operand | <code>number</code> | | The right operand of the operation. | | ||
| path | <code>string</code> | <code>null</code> | Optional. The property path to execute the operation on, if the value is an object or array. | | ||
======= | ||
| key | <code>string</code> \| <code>number</code> | | Required. The key of the element. This value MUST be a string or number. | | ||
@@ -353,2 +415,3 @@ | path | <code>\*</code> | | Required. The name of the array property to push to. Can be a path with dot notation, such as "prop1.subprop2.subprop3" | | ||
>>>>>>> v3 | ||
**Example** | ||
@@ -366,2 +429,3 @@ ```js | ||
<a name="Enmap+inc"></a> | ||
<<<<<<< HEAD | ||
@@ -387,2 +451,23 @@ ### enmap.inc(key, path) ⇒ <code>Map</code> | ||
points.inc("numberInObject", "sub.anInt"); // {sub: { anInt: 6 }} | ||
======= | ||
### enmap.inc(key, path) ⇒ <code>Map</code> | ||
Increments a key's value or property by 1. Value must be a number, or a path to a number. | ||
**Kind**: instance method of [<code>Enmap</code>](#Enmap) | ||
**Returns**: <code>Map</code> - The EnMap. | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| key | <code>string</code> \| <code>number</code> | | The enmap key where the value to increment is stored. | | ||
| path | <code>string</code> | <code>null</code> | Optional. The property path to increment, if the value is an object or array. | | ||
**Example** | ||
```js | ||
// Assuming | ||
points.set("number", 42); | ||
points.set("numberInObject", {sub: { anInt: 5 }}); | ||
points.inc("number"); // 43 | ||
points.inc("numberInObject", "sub.anInt"); // {sub: { anInt: 6 }} | ||
``` | ||
@@ -430,11 +515,70 @@ <a name="Enmap+dec"></a> | ||
const someSubValue = enmap.get("anObjectKey", "someprop.someOtherSubProp"); | ||
>>>>>>> v3 | ||
``` | ||
<a name="Enmap+getProp"></a> | ||
<a name="Enmap+dec"></a> | ||
<<<<<<< HEAD | ||
### enmap.dec(key, path) ⇒ <code>Map</code> | ||
Decrements a key's value or property by 1. Value must be a number, or a path to a number. | ||
======= | ||
### enmap.getProp(key, path) ⇒ <code>\*</code> | ||
Returns the specific property within a stored value. If the key does not exist or the value is not an object, throws an error. | ||
>>>>>>> v3 | ||
**Kind**: instance method of [<code>Enmap</code>](#Enmap) | ||
**Returns**: <code>\*</code> - The value of the property obtained. | ||
**Returns**: <code>Map</code> - The EnMap. | ||
<<<<<<< HEAD | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| key | <code>string</code> \| <code>number</code> | | The enmap key where the value to decrement is stored. | | ||
| path | <code>string</code> | <code>null</code> | Optional. The property path to decrement, if the value is an object or array. | | ||
**Example** | ||
```js | ||
// Assuming | ||
points.set("number", 42); | ||
points.set("numberInObject", {sub: { anInt: 5 }}); | ||
points.dec("number"); // 41 | ||
points.dec("numberInObject", "sub.anInt"); // {sub: { anInt: 4 }} | ||
``` | ||
<a name="Enmap+get"></a> | ||
### enmap.get(key, path) ⇒ <code>\*</code> | ||
Retrieves a key from the enmap. If fetchAll is false, returns a promise. | ||
**Kind**: instance method of [<code>Enmap</code>](#Enmap) | ||
**Returns**: <code>\*</code> - The value for this key. | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| key | <code>string</code> \| <code>number</code> | | The key to retrieve from the enmap. | | ||
| path | <code>string</code> | <code>null</code> | Optional. The property to retrieve from the object or array. Can be a path with dot notation, such as "prop1.subprop2.subprop3" | | ||
**Example** | ||
```js | ||
const myKeyValue = enmap.get("myKey"); | ||
console.log(myKeyValue); | ||
const someSubValue = enmap.get("anObjectKey", "someprop.someOtherSubProp"); | ||
``` | ||
<a name="Enmap+has"></a> | ||
### enmap.has(key, path) ⇒ <code>boolean</code> | ||
Returns whether or not the key exists in the Enmap. | ||
**Kind**: instance method of [<code>Enmap</code>](#Enmap) | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| key | <code>string</code> \| <code>number</code> | | Required. The key of the element to add to The Enmap or array. This value MUST be a string or number. | | ||
| path | <code>string</code> | <code>null</code> | Optional. The property to verify inside the value object or array. Can be a path with dot notation, such as "prop1.subprop2.subprop3" | | ||
**Example** | ||
```js | ||
if(enmap.has("myKey")) { | ||
// key is there | ||
} | ||
======= | ||
| Param | Type | Description | | ||
@@ -477,3 +621,6 @@ | --- | --- | --- | | ||
| path | <code>\*</code> | Required. The property to verify inside the value object or array. Can be a path with dot notation, such as "prop1.subprop2.subprop3" | | ||
>>>>>>> v3 | ||
if(!enmap.has("myOtherKey", "oneProp.otherProp.SubProp")) return false; | ||
``` | ||
<a name="Enmap+delete"></a> | ||
@@ -486,2 +633,4 @@ | ||
<<<<<<< HEAD | ||
======= | ||
| Param | Type | Default | Description | | ||
@@ -511,6 +660,22 @@ | --- | --- | --- | --- | | ||
>>>>>>> v3 | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| key | <code>string</code> \| <code>number</code> | | Required. The key of the element to delete from The Enmap. | | ||
| path | <code>string</code> | <code>null</code> | Optional. The name of the property to remove from the object. Can be a path with dot notation, such as "prop1.subprop2.subprop3" | | ||
<<<<<<< HEAD | ||
<a name="Enmap+deleteAll"></a> | ||
### enmap.deleteAll(bulk) | ||
Calls the `delete()` method on all items that have it. | ||
**Kind**: instance method of [<code>Enmap</code>](#Enmap) | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| bulk | <code>boolean</code> | <code>true</code> | Optional. Defaults to True. whether to use the provider's "bulk" delete feature if it has one. | | ||
======= | ||
>>>>>>> v3 | ||
<a name="Enmap+remove"></a> | ||
@@ -531,2 +696,4 @@ | ||
<<<<<<< HEAD | ||
======= | ||
<a name="Enmap+removeFrom"></a> | ||
@@ -547,2 +714,3 @@ | ||
>>>>>>> v3 | ||
<a name="Enmap+array"></a> | ||
@@ -549,0 +717,0 @@ |
@@ -10,3 +10,3 @@ const _ = require('lodash'); | ||
* A enhanced Map structure with additional utility methods. | ||
* Can be made persistent | ||
* Can be made persistent | ||
* @extends {Map} | ||
@@ -49,3 +49,3 @@ */ | ||
* const { settings, tags, blacklist } = Enmap.multi(['settings', 'tags', 'blacklist'], Provider, { url: "some connection URL here" }); | ||
* | ||
* | ||
* // Attaching to an existing object (for instance some API's client) | ||
@@ -55,3 +55,3 @@ * const Enmap = require("enmap"); | ||
* Object.assign(client, Enmap.multi(["settings", "tags", "blacklist"], Provider, { url: "some connection URL here" })); | ||
* | ||
* | ||
* @returns {Array<Map>} An array of initialized Enmaps. | ||
@@ -129,5 +129,5 @@ */ | ||
* Set the value in Enmap. | ||
* @param {string|number} key Required. The key of the element to add to The Enmap. | ||
* @param {string|number} key Required. The key of the element to add to The Enmap. | ||
* If the Enmap is persistent this value MUST be a string or number. | ||
* @param {*} val Required. The value of the element to add to The Enmap. | ||
* @param {*} val Required. The value of the element to add to The Enmap. | ||
* If the Enmap is persistent this value MUST be stringifiable as JSON. | ||
@@ -143,6 +143,6 @@ * @param {string} path Optional. The path to the property to modify inside the value object or array. | ||
* enmap.set('ArraysToo', [1, "two", "tree", "foor"]) | ||
* | ||
* | ||
* // Settings Properties | ||
* enmap.set('IhazObjects', 'color', 'blue'); //modified previous object | ||
* enmap.set('ArraysToo', 2, 'three'); // changes "tree" to "three" in array. | ||
* enmap.set('ArraysToo', 2, 'three'); // changes "tree" to "three" in array. | ||
* @return {Map} The Enmap. | ||
@@ -159,10 +159,9 @@ */ | ||
} | ||
const insert = JSON.parse(JSON.stringify(data)); | ||
if (typeof this.changedCB === 'function') { | ||
this.changedCB(key, oldValue, insert); | ||
this.changedCB(key, oldValue, data); | ||
} | ||
if (this.persistent) { | ||
this.db.set(key, insert); | ||
this.db.set(key, data); | ||
} | ||
return super.set(key, _.cloneDeep(insert)); | ||
return super.set(key, _.cloneDeep(data)); | ||
} | ||
@@ -173,3 +172,3 @@ | ||
* This is a shortcut to loading the key, changing the value, and setting it back. | ||
* @param {string|number} key Required. The key of the element to add to The Enmap or array. | ||
* @param {string|number} key Required. The key of the element to add to The Enmap or array. | ||
* This value MUST be a string or number. | ||
@@ -187,3 +186,3 @@ * @param {*} path Required. The property to modify inside the value object or array. | ||
* Push to an array value in Enmap. | ||
* @param {string|number} key Required. The key of the array element to push to 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. | ||
@@ -198,3 +197,3 @@ * @param {*} val Required. The value to push to the array. | ||
* enmap.set("arrayInObject", {sub: [1, 2, 3, 4]}); | ||
* | ||
* | ||
* enmap.push("simpleArray", 5); // adds 5 at the end of the array | ||
@@ -220,4 +219,4 @@ * enmap.push("arrayInObject", "five", "sub"); adds "five" at the end of the sub array | ||
/** | ||
* Push to an array element inside an Object or Array element in Enmap. | ||
* @param {string|number} key Required. The key of the element. | ||
* 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. | ||
@@ -247,3 +246,3 @@ * @param {*} path Required. The name of the array property to push to. | ||
* points.set("numberInObject", {sub: { anInt: 5 }}); | ||
* | ||
* | ||
* points.math("number", "/", 2); // 21 | ||
@@ -253,3 +252,3 @@ * points.math("number", "add", 5); // 26 | ||
* points.math("numberInObject", "+", 10, "sub.anInt"); | ||
* | ||
* | ||
* @return {Map} The EnMap. | ||
@@ -282,3 +281,3 @@ */ | ||
* points.set("numberInObject", {sub: { anInt: 5 }}); | ||
* | ||
* | ||
* points.inc("number"); // 43 | ||
@@ -309,3 +308,3 @@ * points.inc("numberInObject", "sub.anInt"); // {sub: { anInt: 6 }} | ||
* points.set("numberInObject", {sub: { anInt: 5 }}); | ||
* | ||
* | ||
* points.dec("number"); // 41 | ||
@@ -338,3 +337,3 @@ * points.dec("numberInObject", "sub.anInt"); // {sub: { anInt: 4 }} | ||
* console.log(myKeyValue); | ||
* | ||
* | ||
* const someSubValue = enmap.get("anObjectKey", "someprop.someOtherSubProp"); | ||
@@ -354,3 +353,3 @@ * @return {*} The value for this key. | ||
* Returns the specific property within a stored value. If the key does not exist or the value is not an object, throws an error. | ||
* @param {string|number} key Required. The key of the element to get from The Enmap. | ||
* @param {string|number} key Required. The key of the element to get from The Enmap. | ||
* @param {*} path Required. The property to retrieve from the object or array. | ||
@@ -368,3 +367,3 @@ * Can be a path with dot notation, such as "prop1.subprop2.subprop3" | ||
* Returns whether or not the key exists in the Enmap. | ||
* @param {string|number} key Required. The key of the element to add to The Enmap or array. | ||
* @param {string|number} key Required. The key of the element to add to The Enmap or array. | ||
* This value MUST be a string or number. | ||
@@ -377,3 +376,3 @@ * @param {string} path Optional. The property to verify inside the value object or array. | ||
* } | ||
* | ||
* | ||
* if(!enmap.has("myOtherKey", "oneProp.otherProp.SubProp")) return false; | ||
@@ -393,3 +392,3 @@ * @returns {boolean} | ||
* Returns whether or not the property exists within an object or array value in enmap. | ||
* @param {string|number} key Required. The key of the element to check in the Enmap or array. | ||
* @param {string|number} key Required. The key of the element to check in the Enmap or array. | ||
* @param {*} path Required. The property to verify inside the value object or array. | ||
@@ -442,3 +441,3 @@ * Can be a path with dot notation, such as "prop1.subprop2.subprop3" | ||
* Delete a property from an object or array value in Enmap. | ||
* @param {string|number} key Required. The key of the element to delete the property from in Enmap. | ||
* @param {string|number} key Required. The key of the element to delete the property from in Enmap. | ||
* @param {*} path Required. The name of the property to remove from the object. | ||
@@ -473,3 +472,3 @@ * Can be a path with dot notation, such as "prop1.subprop2.subprop3" | ||
* 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. | ||
* @param {string|number} key Required. The key of the element to remove from in Enmap. | ||
* This value MUST be a string or number. | ||
@@ -504,4 +503,4 @@ * @param {*} val Required. The value to remove from the array or object. | ||
* 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. | ||
* Confusing? Sure is. | ||
* @param {string|number} key Required. The key of the element. | ||
* This value MUST be a string or number. | ||
@@ -523,3 +522,3 @@ * @param {*} path Required. The name of the array property to remove from. | ||
* Loops on incremental numerical values until it finds a free key | ||
* of that value in the Enamp. | ||
* of that value in the Enamp. | ||
* @param {Integer} start The starting value to look for. | ||
@@ -562,3 +561,3 @@ * @return {Integer} The first non-existant value found. | ||
/* | ||
* INTERNAL method to execute a mathematical operation. Cuz... javascript. | ||
* INTERNAL method to execute a mathematical operation. Cuz... javascript. | ||
* And I didn't want to import mathjs! | ||
@@ -605,3 +604,3 @@ * @param {number} base the lefthand operand. | ||
Per notes in the LICENSE file, this project contains code from Amish Shah's Discord.js | ||
library. The code is from the Collections object, in discord.js version 11. | ||
library. The code is from the Collections object, in discord.js version 11. | ||
@@ -615,3 +614,3 @@ All below code is sourced from Collections. | ||
* The array will only be reconstructed if an item is added to or removed from the Enmap, | ||
* or if you change the length of the array itself. If you don't want this caching behaviour, | ||
* or if you change the length of the array itself. If you don't want this caching behaviour, | ||
* use `Array.from(enmap.values())` instead. | ||
@@ -626,4 +625,4 @@ * @returns {Array} | ||
* Creates an ordered array of the keys of this Enmap | ||
* The array will only be reconstructed if an item is added to or removed from the Enmap, | ||
* or if you change the length of the array itself. If you don't want this caching behaviour, | ||
* The array will only be reconstructed if an item is added to or removed from the Enmap, | ||
* or if you change the length of the array itself. If you don't want this caching behaviour, | ||
* use `Array.from(enmap.keys())` instead. | ||
@@ -659,3 +658,3 @@ * @returns {Array} | ||
* @param {number} [count] Number of keys to obtain randomly | ||
* @returns {*|Array<*>} The single key if `count` is undefined, | ||
* @returns {*|Array<*>} The single key if `count` is undefined, | ||
* or an array of keys of `count` length | ||
@@ -662,0 +661,0 @@ */ |
113213
947
1432