node-persist
Advanced tools
Comparing version 4.0.2 to 4.0.3
{ | ||
"name": "node-persist", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"description": "Super-easy (and fast) persistent data structures in Node.js, modeled after HTML5 localStorage", | ||
@@ -5,0 +5,0 @@ "main": "./src/node-persist.js", |
@@ -23,9 +23,21 @@ /* | ||
*/ | ||
nodePersist.init = async function (userOptions) { | ||
const localStorage = nodePersist.defaultInstance = nodePersist.create(userOptions); | ||
let ret = await localStorage.init(userOptions); | ||
mixin(nodePersist, localStorage, {skip: ['init', 'create']}); | ||
mixin(nodePersist, localStorage, {skip: ['init', 'initSync', 'create']}); | ||
return ret; | ||
}; | ||
/* | ||
* This function, (or initSync) must be called before the library can be used. | ||
* An options hash can be optionally passed. | ||
*/ | ||
nodePersist.initSync = function (userOptions) { | ||
const localStorage = nodePersist.defaultInstance = nodePersist.create(userOptions); | ||
let ret = localStorage.initSync(userOptions); | ||
mixin(nodePersist, localStorage, {skip: ['init', 'initSync', 'create']}); | ||
return ret; | ||
}; | ||
// expose all the API methods on the main module using a default instance | ||
@@ -32,0 +44,0 @@ function mixin (target, source, options) { |
@@ -89,3 +89,3 @@ | ||
it('should create the default instance of LocalStorage sync and use it', async function() { | ||
it('should create the default instance of LocalStorage async and use it', async function() { | ||
await nodePersist.init({dir: randDir()}); | ||
@@ -97,2 +97,9 @@ assert.ok(nodePersist.defaultInstance instanceof LocalStorage); | ||
it('should create the default instance of LocalStorage sync and use it', async function() { | ||
nodePersist.initSync({dir: randDir()}); | ||
assert.ok(nodePersist.defaultInstance instanceof LocalStorage); | ||
await nodePersist.setItem('item8887', 'hello'); | ||
assert.equal(await nodePersist.getItem('item8887'), 'hello', `write/read didn't work`); | ||
}); | ||
it('should create a default instance', async function() { | ||
@@ -103,2 +110,8 @@ let dir = randDir(); | ||
}); | ||
it('should create a default instance but initSync', async function() { | ||
let dir = randDir(); | ||
let options = nodePersist.initSync({dir: dir}); | ||
assert.equal(options.dir, dir, `Options don't match`); | ||
}); | ||
}); | ||
@@ -105,0 +118,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39139
905