Skip to content

A simple and easy to use TypeScript/JavaScript API for browser storage control with some additional features

License

Notifications You must be signed in to change notification settings

KBeDevel/browdb

Repository files navigation

Browdb

A simple JavaScript/TypeScript library to handle browser cookies and storage

Note: this library is not compatible for server-side use

CircleCI GitHub code size in bytes Codacy Badge Codacy Badge

How to use

Installation

npm install browdb

or

yarn add browdb

Using browser storage

import { BrowserStorage } from 'browdb'

const dataToSave = {
  key: 'username',
  value: 'John Doe'
}

const saveInLocalStorage = () => {
  const browdbLocalStorage = new BrowserStorage({ context: 'local' })
  browdbLocalStorage.setItem(dataToSave)
}

const saveInSessionStorage = () => {
  const browdbLocalStorage = new BrowserStorage({ context: 'session' })
  browdbLocalStorage.setItem(dataToSave)
}

Using browser cookies

import { Cookies, CookieSet } from 'browdb'

const cookieConfig: CookieSet = {
  keySet: {
    keyName: 'username',
    assignValue: 'John Doe'
  },
  encodeValues: true,
}

const saveCookie = () => {
  const cookie = new Cookie(cookieConfig)
  cookie.save()
}