Comparing version 4.6.6 to 4.7.0
{ | ||
"name": "enmap", | ||
"version": "4.6.6", | ||
"version": "4.7.0", | ||
"description": "A simple database wrapper to make sqlite database interactions much easier for beginners, with additional array helper methods.", | ||
@@ -5,0 +5,0 @@ "types": "index.d.ts", |
@@ -551,3 +551,2 @@ // Lodash should probably be a core lib but hey, it's useful! | ||
if (_.isNil(defaultValue)) throw new Err(`No default value provided on ensure method for "${key}" in "${this.name}"`, 'EnmapArgumentError'); | ||
const clonedValue = this[_clone](defaultValue); | ||
if (!_.isNil(path)) { | ||
@@ -561,4 +560,4 @@ this[_check](key, ['Object'], path); | ||
if (this.ensureProps && _.isObject(super.get(key))) { | ||
if (!_.isObject(clonedValue)) throw new Err(`Default value for "${key}" in enmap "${this.name}" must be an object when merging with an object value.`, 'EnmapArgumentError'); | ||
const merged = Object.assign(clonedValue, super.get(key)); | ||
if (!_.isObject(defaultValue)) throw new Err(`Default value for "${key}" in enmap "${this.name}" must be an object when merging with an object value.`, 'EnmapArgumentError'); | ||
const merged = Object.assign(defaultValue, super.get(key)); | ||
super.set(key, merged); | ||
@@ -568,4 +567,4 @@ return merged; | ||
if (super.has(key)) return super.get(key); | ||
this.set(key, clonedValue); | ||
return clonedValue; | ||
this.set(key, defaultValue); | ||
return defaultValue; | ||
} | ||
@@ -615,2 +614,28 @@ | ||
/** | ||
* Performs Array.includes() on a certain enmap value. Works similar to | ||
* [Array.includes()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes). | ||
* @param {string|number} key Required. The key of the array to check the value of. | ||
* @param {string|number} val Required. The value to check whether it's in the array. | ||
* @param {*} path Required. The property to access the array inside the value object or array. | ||
* Can be a path with dot notation, such as "prop1.subprop2.subprop3" | ||
* @return {boolean} Whether the array contains the value. | ||
*/ | ||
includes(key, val, path = null) { | ||
this[_readyCheck](); | ||
this[_fetchCheck](key); | ||
this[_check](key, ['Array', 'Object']); | ||
const data = super.get(key); | ||
if (!_.isNil(path)) { | ||
const propValue = _.get(data, path); | ||
if (_.isArray(propValue)) { | ||
return propValue.includes(val); | ||
} | ||
throw new Err(`The property "${path}" in key "${key}" is not an Array in the enmap "${this.name}" (property was of type "${propValue && propValue.constructor.name}")`, 'EnmapTypeError'); | ||
} else if (_.isArray(data)) { | ||
return data.includes(val); | ||
} | ||
throw new Err(`The value of key "${key}" is not an Array in the enmap "${this.name}" (value was of type "${data && data.constructor.name}")`, 'EnmapTypeError'); | ||
} | ||
/** | ||
* Deletes a key in the Enmap. | ||
@@ -685,2 +710,6 @@ * @param {string|number} key Required. The key of the element to delete from The Enmap. | ||
/** | ||
* Deletes everything from the enmap. If persistent, clears the database of all its data for this table. | ||
* @returns {null} | ||
*/ | ||
clear() { return this.deleteAll(); } | ||
@@ -687,0 +716,0 @@ |
156594
2326