New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

lis-db

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lis-db

LIS (Local Interface for Storage). A "key-value" frontend database build on indexedDB

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
4
100%
Maintainers
1
Weekly downloads
 
Created
Source

lis-db

LIS (Local Interface for Storage), is a "key-value" frontend database build on indexedDB and with typescript support[1].

API

The library offers three functions (write, read and erase)

write

write( key:string, value:any ): Promise<void>[2] Can save persistent data with "key-value" structure, similar to localStorage API.

import { write } from 'lis-db'

write( 'hello', 'Hello World!' ).then( () => {
  console.log( 'Data Saved' )
} )

read

read<T>( ...keys:string[] ): Promise<T[]>[2] is used to read data from the database. It takes as many keys as you want and its promise is resolved with an array of the saved values. You can set the array elements type with the generic type T[3]

import { read } from 'lis-db'

read<string>( 'hello' ).then( values:string[] => {
  const [ hello ] = values  // Using Desestucturing (recommended)
  console.log( hello ) // 'Hello World!'
} )

Also you can use as operator with a tupla to get values with a different type

import { read, write } from 'lis-db'

write( 'num', 7 ).then( () => {
  // Waiting for save data to read it
  read( 'num', 'hello' ).then( values => {
    type tupla = [ number, string ]
    const [ num, hello ] = values as tupla
    console.log( typeof num, typeof hello )  // 'number', 'string'
  } )
} )

Warning: Undeclared values will be null

import { read } from 'lis-db'

// "x" was not written
read( 'x' ).then( values => {
  const [ x ] = values
  console.log( x )  // null
} )

erase

erase( key:string ): Promise<void>[2] is used to erase data from the database

import { erase, read } from 'lis-db'

read<string>( 'hello' ).then( values => {
  const [ hello ] = values
  console.log( hello )  // 'Hello World!'
  erase( 'hello' ).then( () => {
    // Waiting for erase data to read it
    read<string>( 'hello' ).then( values => {
      const [ hello ] = values
      console.log( hello )  // null
    } )
  } )
} )
  • If do you use this library with javascript, types features will be incompatible.
  • This async function will resolve its promise when finish its task.
  • If you don't use it, the promise will be resolved with unknown[] type

Keywords

database

FAQs

Package last updated on 06 Jul 2023

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