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 0.4.6 to 0.5.0

2

package.json
{
"name": "enmap",
"version": "0.4.6",
"version": "0.5.0",
"description": "",

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

@@ -14,5 +14,3 @@ # Enmap - Enhanced Maps

**A**: With the use of the optional providers modules, any data added to the Enmap
is stored not only in temporary memory but also backed up in a local file
database. This does not require a server. Saving things in memory enables
faster code, but it may take more memory.
is stored not only in temporary memory but also backed up in a local database.

@@ -58,10 +56,8 @@ ### Q: How big can the Enmap be?

* [Enmap-Rethink](https://www.npmjs.com/package/enmap-rethink)
* [Enmap-SQLite](https://www.npmjs.com/package/enmap-sqlite)
* [Enmap-SQLite](https://www.npmjs.com/package/enmap-sqlite) *Note: Against all odds, this provider DOES support sharding!*
* [Enmap-Rethink](https://www.npmjs.com/package/enmap-rethink) *Note: Obviously, supports sharding.*
* [Enmap-PGSQL](https://www.npmjs.com/package/enmap-pgsql) *Note: That's shorthand for "Postgresql". Supports sharding of course.*
* [Enmap-Mongo](https://www.npmjs.com/package/enmap-mongo) *Note: Yay, MongoDB! Supports sharding, duh.*
* [Enmap-Level](https://www.npmjs.com/package/enmap-level) *Note: LevelDB does not support multiple processes or shards!*
Unofficial Providers:
* None! Make your own and let me know!
The following example uses Enmap-SQLite

@@ -100,2 +96,22 @@

## Using Enmap.multi() for multiple enmaps
To account for people that might use a large number of enmaps in the same project, I've created a new `multi()` method that can be used to instanciate multiple peristent enmaps together.
The method takes 3 arguments:
* An `array` of names for the enmaps to be created.
* A Provider (not instanciated), from any of the available ones.
* An `options` object containing any of the options needed to instanciate the provider. Do not add `name` to this, as it will use the names in the array instead.
The method returns an object where each property is a new fully-started Enmap that can be used as you would normally.
Below, an example that uses destructuring to fit all in one nice line:
```js
const Enmap = require('enmap');
const Provider = require('enmap-mongo');
const { settings, tags, blacklist, langs } = Enmap.multi(['settings', 'tags', 'blacklist', 'langs'], Provider, { url: "mongodb://localhost:27017/enmap" });
```
> Note that this uses a static method which means you should NOT call `new Enmap()` yourself, it's done within the method.
## Reading and Writing Data

@@ -102,0 +118,0 @@

@@ -24,2 +24,22 @@ /**

static multi(names, Provider, options) {
if (!names.length || names.length < 1) {
throw new Error('"names" parameter must be an array of string names');
}
if (!Provider) {
throw new Error('Provider must be given and be an enmap provider!');
}
const returnvalue = {};
for (const name of names) {
const enmap = new Enmap({ provider: new Provider(Object.assign(options, { name })) });
returnvalue[name] = enmap;
}
return returnvalue;
}
static test() {
return { blah: 'foo' };
}
/**

@@ -120,3 +140,3 @@ * Shuts down the underlying persistent enmap database.

for (let i = 0; i < count; i++) {
rand[i] = arr.splice(Math.floor(Math.random() * arr.length), 1)[0];
rand[i] = [arr.splice(Math.floor(Math.random() * arr.length), 1)];
}

@@ -142,3 +162,3 @@ return rand;

for (let i = 0; i < count; i++) {
rand[i] = arr.splice(Math.floor(Math.random() * arr.length), 1)[0];
rand[i] = [arr.splice(Math.floor(Math.random() * arr.length), 1)];
}

@@ -145,0 +165,0 @@ return rand;

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