New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kv-storage

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kv-storage

Create data storage that uses a simple key-value method for Node, Browser, Deno, Bun, Cloudflare Workers

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-25%
Maintainers
1
Weekly downloads
 
Created
Source

kv-storage

Create data storage that uses a simple key-value method for Node, Browser, Deno, Bun, Cloudflare Workers

NPM npm version

Features

  • ✅ 0 Dependencies
  • ✅ NoSQL Database
  • ✅ Lightwight

Demo

https://codesandbox.io/p/devbox/simple-kv-storage-pzr9ld

Installation

npm install kv-storage

Initialization

//Node CommonJS import style
const {KVStorage} = require('kv-storage')

//Node & Browser ES Modules import style
import {KVStorage} from 'kv-storage'

//Deno import style
import {KVStorage} from 'npm:kv-storage'

const db = await KVStorage({
	runtime:'node', //node | deno | browser
	storageName:'storage'
})

Example Usage

//Node CommonJS example
const {KVStorage} = require('kv-storage')

void async function main() {
	const db = await KVStorage({
		runtime:'node',
		storageName:'storage'
	})
	
	console.log(await db.put('key','value'))
	console.log(await db.get('key'))
	console.log(await db.list())
	console.log(await db.delete('key'))
	console.log(await db.has('key'))
}()
//Node ES Modules example
import {KVStorage} from 'kv-storage'

void async function main() {
	const db = await KVStorage({
		runtime:'node',
		storageName:'storage'
	})
	
	console.log(await db.put('key','value'))
	console.log(await db.get('key'))
	console.log(await db.list())
	console.log(await db.delete('key'))
	console.log(await db.has('key'))
}()
//Deno example
import {KVStorage} from 'npm:kv-storage'

void async function main() {
	const db = await KVStorage({
		runtime:'deno',
		storageName:'storage'
	})
	
	console.log(await db.put('key','value'))
	console.log(await db.get('key'))
	console.log(await db.list())
	console.log(await db.delete('key'))
	console.log(await db.has('key'))
}()
<script type="module">
//Directly in Browser example
import {KVStorage} from 'https://cdn.jsdelivr.net/npm/kv-storage@0.0.3/dist/mjs/kv-storage.js'

void async function main() {
	const db = await KVStorage({
		runtime:'browser',
		storageName:'storage'
	})
	
	console.log(await db.put('key','value'))
	console.log(await db.get('key'))
	console.log(await db.list())
	console.log(await db.delete('key'))
	console.log(await db.has('key'))
}()
</script>

API Reference

Documentation

https://nuzulul.github.io/kv-storage/

Init Parameters

await init({
	runtime?:string,
	storageName?:string 
})
runtime =  Javascript runtime 
storageName = Alphanumeric name of storage

Supported runtime :

  • node
  • deno need --allow-read --allow-write
  • browser
  • bun
  • cloudflare-workers
  • memory

Write key-value pairs

await put(key:string,value:string)

The put() method returns a Promise that you should await on to verify a successful update, resolve to true or false

Read key-value pairs

await get(key:string)

The get() method returns a promise you can await on to get the value, resolve to the value or false

List keys

await list()

Use a list operation to view all the keys that live in a given storage, return a promise which resolves with an object consist of:

  • keys = Array of keys
  • complete = True if operation complete

Delete key-value pairs

await delete(key:string)

To delete a key-value pair, call the delete() method, resolve to true or false

Has key-value pairs

await has(key:string)

To check for the existence of a key, resolve to true or false

License

MIT

Keywords

FAQs

Package last updated on 01 Feb 2024

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