Skip to content

leofcoin/storage

Repository files navigation

LeofcoinStorage

CodeQL

install

npm i @leofcoin/storage

breaking changes

checkout

Usage

import LeofcoinStorage from '@leofcoin/storage'

const storage = new LeofcoinStorage(name, root)
await storage.init()
// stores/returns a value as uint8Array

await storage.put('hello', 'world')
(await storage.get('hello')).toString() // world
await storage.get() // [{ key: 'hello', value: 'world'}]
await storage.has('hello') // true
await storage.size() // 4
await storage.delete('hello') // bye world

API

options

name: store name
root: root directory

new LeofcoinStorage(name, root)

methods

get

key: path/filename
returns: Promise()<uint8Array>

storage.get(key)

const all = storage.get()
console.log(all) // [{key,value}]

put

key: path/filename
value: path/filename
returns: Promise()

storage.put(key, value)

has

key: path/filename
returns: Promise()<Boolean>

storage.has(key)

keys

returns: Promise()<Array>

storage.keys()

values

returns: Promise()<Array>

storage.values(limit)

build for browser

rollup

import resolve from '@rollup/plugin-node-resolve'
export default [{
  input: './node_modules/@leofcoin/src/storage.js',
  output: {
    file: 'dist/storage.js',
    format: 'es'
  }
}, {
  input: './node_modules/@leofcoin/src/browser-store.js',
  output: {
    file: 'dist/browser-store.js',
    format: 'es'
  },
  plugins: [
    resolve()
  ]
}]