<Enmap>.set(key, value);myEnmap.set('boolean', true);
myEnmap.set('integer', 42);
myEnmap.set('someFloat', 73.2345871);
myEnmap.set("Test2", "test2");const floatValue = myEnmap.get('someFloat');
const test = myEnmap.get('Test2');
// you can even use booleans in conditions:
if(myEnmap.get('boolean')) {
// boolean is true!
}// Load Enmap
const Enmap = require('enmap');
// Load EnmapSQLite
const EnmapSQLite = require('enmap-sqlite');
// Initialize the sqlite database with a table named "test"
const provider = new EnmapSQLite({ name: 'test' });
// Initialize the Enmap with the provider instance.
const myColl = new Enmap({ provider: provider });
// Persistent providers load in an **async** fashion
// and provide a handy defer property:
myColl.defer.then(() => {
// all data is loaded now.
console.log(myColl.size + "keys loaded");
});
// You can also await it if your function is async:
(async function() {
await myColl.defer;
console.log(myColl.size + "keys loaded");
// Do stuff here!
}());
// Persistent collections should be **closed** before shutdown:
await myColl.db.close();myEnmap.push("simpleArray", 6);
// now [1,2,3,4,5,6]
myEnmap.push("arrInObj", "Robby", "aliases");
// now ["Bobby", "Robert", "Robby"]myEnmap.remove("simpleArray", 2);
// now [1,3,4,5,6]
myEnmap.remove("arrInObject", "Bobby", "aliases");
// now ["Robert", "Robby"]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" });// Assuming
points.set("number", 42);
points.set("numberInObject", {sub: { anInt: 5 }});
points.math("number", "/", 2); // 21
points.math("number", "add", 5); // 26
points.math("number", "modulo", 3); // 2
points.math("numberInObject", "+", 10, "sub.anInt");// Assuming
points.set("number", 42);
points.set("numberInObject", {sub: { anInt: 5 }});
points.inc("number"); // 43
points.inc("numberInObject", "sub.anInt"); // {sub: { anInt: 6 }}// Assuming
points.set("number", 42);
points.set("numberInObject", {sub: { anInt: 5 }});
points.dec("number"); // 41
points.dec("numberInObject", "sub.anInt"); // {sub: { anInt: 4 }}const myStructure = {
first: "blah",
second: "foo",
changeme: "initial",
isCool: false
sub: {
yay: true,
thing: "amagig"
}
}myEnmap.set("someObject", myStructure);
// Or directly the object
myEnmap.set("someObject", {first: "blah", ...});
// Works with arrays, too!
myEnmap.set("someArray", ["one", "two", "three"]);const second = myEnmap.get("someObject", "second");
// returns "foo"
const thing = myEnmap.get("someObject", "sub.thing");
// returns true
// The path can be dynamic, too:
const propToGet = "thing";
const blah = myEnmap.get("someObject", `sub.${propToGet}`);myEnmap.has("someObject", "sub.thing"); // returns true
myEnmap.has("someObject", "heck"); // returns false.// Set an object property
myEnmap.set("someObject", "sub.blah", "newThing");
// Set an array property
myEnmap.set("someArray", "four", 3);const Enmap = require("enmap");
// Initialize an instance of Enmap
const myCollection = new Enmap();
// Adding data is simply a `set` command:
myCollection.set("myKey", "a value");
// Getting a value is done by key
let result = myCollection.get("myKey");enmap.fetch([array, of, keys]) will fetch each key in the requested array, and return an array of [key, value] pairs for each fetched value.