Socket
Socket
Sign inDemoInstall

node-kv-storage

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-kv-storage

Wrapper around node-persist that conforms to the std:kv-storage interface


Version published
Weekly downloads
6
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

Node KV Storage

Wrapper around node-persist that implements the std:kv-storage interface.

Why

  • Standardized API
  • Easier code sharing with frontend
  • No await init()

How

const { default: storage, NodeStorageArea } = require('node-kv-storage')

;(async () => {
  await storage.set('test', { a: 3 })
  assert.deepStrictEqual(await storage.get('test'), { a: 3})

  // Compatible with node-persist for string keys
  await nodePersist.init()
  await nodePersist.setItem('foo', { b: 4 })
  assert.deepStrictEqual(await storage.get('foo'), { b: 4})

  // Also allows Number keys
  await storage.set(3, { f: 8 })
  assert.deepStrictEqual(await storage.get(3), { f: 8 })

  // Also allows Date keys
  const d = new Date(0)
  await storage.set(d, { c: 5 })
  assert.deepStrictEqual(await storage.get(d), { c: 5 })

  // Also allows complex keys
  await storage.set(['foo', 3, d], { c: 6 })
  assert.deepStrictEqual(await storage.get(['foo', 3, d]), { c: 6 })

  // Use multiple storage areas
  const other = new NodeStorageArea('other_area')
  await other.set('test', { i: 11 })
  assert.deepStrictEqual(await other.get('test'), { i: 11 })
})()

API

FAQs

Package last updated on 08 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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