node-kv-storage
Advanced tools
Comparing version 1.1.1 to 2.0.0
const path = require('path'); | ||
const crypto = require('crypto'); | ||
const storage = require('node-persist'); | ||
const md5 = key => crypto.createHash('md5').update(key).digest('hex'); | ||
function coerceKey (key) { | ||
@@ -71,3 +74,3 @@ const coercedKey = coerceKeyInner(key); | ||
const baseDir = process.env.NODE_KV_STORAGE_DIR || global.NODE_KV_STORAGE_DIR || process.cwd(); | ||
const dirName = name === DEFAULT_STORAGE_AREA_NAME ? 'storage' : name; | ||
const dirName = name === DEFAULT_STORAGE_AREA_NAME ? 'storage' : md5(name); | ||
const db = storage.create({ | ||
@@ -74,0 +77,0 @@ dir: path.resolve(baseDir, '.node-persist', dirName), |
{ | ||
"name": "node-kv-storage", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "Wrapper around node-persist that conforms to the std:kv-storage interface", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,7 +21,9 @@ # Node KV Storage | ||
// Compatible with node-persist for string and binary keys | ||
await require('node-persist').init() | ||
await require('node-persist').setItem('foo', { b: 4 }) | ||
// Note that this only works for the default storage area | ||
const nodePersist = require('node-persist') | ||
await nodePersist.init() | ||
await nodePersist.setItem('foo', { b: 4 }) | ||
console.log(await storage.get('foo')) | ||
await require('node-persist').setItem(Buffer.from([0x1, 0x2]), { d: 6 }) | ||
await nodePersist.setItem(Buffer.from([0x1, 0x2]), { d: 6 }) | ||
console.log(await storage.get(Buffer.from([0x1, 0x2]))) | ||
@@ -55,3 +57,2 @@ | ||
* Using typed arrays as keys works, but when using `keys()` or `entries()` they will be returned in the form `JSON.parse(JSON.stringify(yourTypedArray))`. Typically this will look like `{ '0': 255, '1': 255, ... }`. | ||
* Storage areas with the name `default` and `storage` will both map to the directory `storage`. | ||
@@ -58,0 +59,0 @@ ## Questions |
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
18909
133
64