Full Documentation
The complete and unadultered API documentation for every single method and property accessible in Enmap.
The following is the complete list of methods available in Enmap. As it is auto-generated from the source code and its comments, it's a little more "raw" than the Usage docs. However, it has the benefit of being more complete and usually more up to date than the manually written docs.
If you're doing a PR on the docs github, please do not manually edit the below contents, as it will be overwritten. Check the src/index.js source code and change the comments there instead!
new Enmap(iterable, [options])
Initializes a new Enmap, with options.
Example
enmap.count ⇒ integer
integer
Retrieves the number of rows in the database for this enmap, even if they aren't fetched.
Kind: instance property of Enmap
Returns: integer
- The number of rows in the database.
enmap.indexes ⇒ array.<string>
array.<string>
Retrieves all the indexes (keys) in the database for this enmap, even if they aren't fetched.
Kind: instance property of Enmap
Returns: array.<string>
- Array of all indexes (keys) in the enmap, cached or not.
enmap.autonum ⇒ number
number
Generates an automatic numerical key for inserting a new value. This is a "weak" method, it ensures the value isn't duplicated, but does not guarantee it's sequential (if a value is deleted, another can take its place). Useful for logging, actions, items, etc - anything that doesn't already have a unique ID.
Kind: instance property of Enmap
Returns: number
- The generated key number.
Example
enmap.set(key, val, path) ⇒ Enmap
Enmap
Sets a value in Enmap.
Kind: instance method of Enmap
Returns: Enmap
- The enmap.
Example
enmap.update(key, valueOrFunction) ⇒ *
*
Update an existing object value in Enmap by merging new keys. This only works on objects, any other value will throw an error. Heavily inspired by setState from React's class components. This is very useful if you have many different values to update and don't want to have more than one .set(key, value, prop) lines.
Kind: instance method of Enmap
Returns: *
- The updated, merged value.
Example
enmap.get(key, path) ⇒ *
*
Retrieves a key from the enmap. If fetchAll is false, returns a promise.
Kind: instance method of Enmap
Returns: *
- The value for this key.
Example
enmap.observe(key, path) ⇒ *
*
Returns an observable object. Modifying this object or any of its properties/indexes/children will automatically save those changes into enmap. This only works on objects and arrays, not "basic" values like strings or integers.
Kind: instance method of Enmap
Returns: *
- The value for this key.
enmap.fetchEverything() ⇒ Enmap
Enmap
Fetches every key from the persistent enmap and loads them into the current enmap value.
Kind: instance method of Enmap
Returns: Enmap
- The enmap containing all values.
enmap.fetch(keyOrKeys) ⇒ Enmap
| *
Enmap
| *
Force fetch one or more key values from the enmap. If the database has changed, that new value is used.
Kind: instance method of Enmap
Returns: Enmap
| *
- The Enmap, including the new fetched values, or the value in case the function argument is a single key.
enmap.evict(keyOrArrayOfKeys) ⇒ Enmap
Enmap
Removes a key or keys from the cache - useful when disabling autoFetch.
Kind: instance method of Enmap
Returns: Enmap
- The enmap minus the evicted keys.
enmap.changed(cb)
Function called whenever data changes within Enmap after the initial load. Can be used to detect if another part of your code changed a value in enmap and react on it.
Kind: instance method of Enmap
Example
enmap.close() ⇒ Promise.<*>
Promise.<*>
Shuts down the database. WARNING: USING THIS MAKES THE ENMAP UNUSEABLE. You should only use this method if you are closing your entire application. This is useful if you need to copy the database somewhere else, or if you're somehow losing data on shutdown.
Kind: instance method of Enmap
Returns: Promise.<*>
- The promise of the database closing operation.
enmap.push(key, val, path, allowDupes) ⇒ Enmap
Enmap
Push to an array value in Enmap.
Kind: instance method of Enmap
Returns: Enmap
- The enmap.
Example
enmap.math(key, operation, operand, path) ⇒ Enmap
Enmap
Executes a mathematical operation on a value and saves it in the enmap.
Kind: instance method of Enmap
Returns: Enmap
- The enmap.
Example
enmap.inc(key, path) ⇒ Enmap
Enmap
Increments a key's value or property by 1. Value must be a number, or a path to a number.
Kind: instance method of Enmap
Returns: Enmap
- The enmap.
Example
enmap.dec(key, path) ⇒ Enmap
Enmap
Decrements a key's value or property by 1. Value must be a number, or a path to a number.
Kind: instance method of Enmap
Returns: Enmap
- The enmap.
Example
enmap.ensure(key, defaultValue, path) ⇒ *
*
Returns the key's value, or the default given, ensuring that the data is there. This is a shortcut to "if enmap doesn't have key, set it, then get it" which is a very common pattern.
Kind: instance method of Enmap
Returns: *
- The value from the database for the key, or the default value provided for a new key.
Example
enmap.has(key, path) ⇒ boolean
boolean
Returns whether or not the key exists in the Enmap.
Kind: instance method of Enmap
Example
enmap.includes(key, val, path) ⇒ boolean
boolean
Performs Array.includes() on a certain enmap value. Works similar to Array.includes().
Kind: instance method of Enmap
Returns: boolean
- Whether the array contains the value.
enmap.delete(key, path) ⇒ Enmap
Enmap
Deletes a key in the Enmap.
Kind: instance method of Enmap
Returns: Enmap
- The enmap.
enmap.clear()
Deletes everything from the enmap. If persistent, clears the database of all its data for this table.
Kind: instance method of Enmap
enmap.destroy() ⇒ null
null
Completely destroys the entire enmap. This deletes the database tables entirely. It will not affect other enmap data in the same database, however. THIS ACTION WILL DESTROY YOUR DATA AND CANNOT BE UNDONE.
Kind: instance method of Enmap
enmap.remove(key, val, path) ⇒ Enmap
Enmap
Remove a value in an Array or Object element in Enmap. Note that this only works for values, not keys. Note that only one value is removed, no more. Arrays of objects must use a function to remove, as full object matching is not supported.
Kind: instance method of Enmap
Returns: Enmap
- The enmap.
Example
enmap.export() ⇒ string
string
Exports the enmap data to a JSON file. WARNING: Does not work on memory enmaps containing complex data!
Kind: instance method of Enmap
Returns: string
- The enmap data in a stringified JSON format.
enmap.import(data, overwrite, clear) ⇒ Enmap
Enmap
Import an existing json export from enmap from a string. This data must have been exported from enmap, and must be from a version that's equivalent or lower than where you're importing it.
Kind: instance method of Enmap
Returns: Enmap
- The enmap with the new data.
enmap.array() ⇒ Array
Array
Creates an ordered array of the values 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, use Array.from(enmap.values())
instead.
Kind: instance method of Enmap
enmap.keyArray() ⇒ Array.<(string|number)>
Array.<(string|number)>
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, use Array.from(enmap.keys())
instead.
Kind: instance method of Enmap
enmap.random([count]) ⇒ *
| Array.<*>
*
| Array.<*>
Obtains random value(s) from this Enmap. This relies on array.
Kind: instance method of Enmap
Returns: *
| Array.<*>
- The single value if count
is undefined, or an array of values of count
length
enmap.randomKey([count]) ⇒ *
| Array.<*>
*
| Array.<*>
Obtains random key(s) from this Enmap. This relies on keyArray
Kind: instance method of Enmap
Returns: *
| Array.<*>
- The single key if count
is undefined, or an array of keys of count
length
enmap.findAll(prop, value) ⇒ Array
Array
Searches for all items where their specified property's value is identical to the given value (item[prop] === value
).
Kind: instance method of Enmap
Example
enmap.find(propOrFn, [value]) ⇒ *
*
Searches for a single item where its specified property's value is identical to the given value (item[prop] === value
), or the given function returns a truthy value. In the latter case, this is identical to Array.find().
All Enmap used in Discord.js are mapped using their `id` property, and if you want to find by id you should use the `get` method. See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) for details.
Kind: instance method of Enmap
Example
Example
enmap.findKey(propOrFn, [value]) ⇒ string
| number
string
| number
Searches for the key of a single item where its specified property's value is identical to the given value (item[prop] === value
), or the given function returns a truthy value. In the latter case, this is identical to Array.findIndex().
Kind: instance method of Enmap
Example
Example
enmap.sweep(fn, [thisArg]) ⇒ number
number
Removes entries that satisfy the provided filter function.
Kind: instance method of Enmap
Returns: number
- The number of removed entries
enmap.filter(fn, [thisArg]) ⇒ Enmap
Enmap
Identical to Array.filter(), but returns a Enmap instead of an Array.
Kind: instance method of Enmap
enmap.filterArray(fn, [thisArg]) ⇒ Array
Array
Identical to Array.filter().
Kind: instance method of Enmap
enmap.map(fn, [thisArg]) ⇒ Array
Array
Identical to Array.map().
Kind: instance method of Enmap
enmap.some(fn, [thisArg]) ⇒ boolean
boolean
Identical to Array.some().
Kind: instance method of Enmap
enmap.every(fn, [thisArg]) ⇒ boolean
boolean
Identical to Array.every().
Kind: instance method of Enmap
enmap.reduce(fn, [initialValue]) ⇒ *
*
Identical to Array.reduce().
Kind: instance method of Enmap
enmap.clone() ⇒ Enmap
Enmap
Creates an identical shallow copy of this Enmap.
Kind: instance method of Enmap
Example
enmap.concat(...enmaps) ⇒ Enmap
Enmap
Combines this Enmap with others into a new Enmap. None of the source Enmaps are modified.
Kind: instance method of Enmap
Example
Enmap.multi(names, options) ⇒ Array.<Map>
Array.<Map>
Initialize multiple Enmaps easily.
Kind: static method of Enmap
Returns: Array.<Map>
- An array of initialized Enmaps.
Example
Last updated