Home

Awesome

Simple Web Storage

GitHub Codacy Badge Build Status npm npm npm David GitHub issues Website

Lightweight utilities that can make easier to write and read application storage in client browser.

Support :


HOW TO USE

1. Use Package with NPM or YARN

# with npm
$ npm i simple-webstorage --save

# or with yarn
$ yarn add simple-webstorage

All API import

import SimpleWebStorage from 'simple-webstorage'

const storage = SimpleWebStorage()

storage.local.set('key', 'value') // empty the third parameter to store data permanently (only affected in local)
storage.cookie.set('key', 'value', 5)
storage.session.set('key', 'value', 5)

Partial API import

// # for local storage
import { get as getLocalStorage, set as setLocalStorage } from 'simple-webstorage/lib/local'

// # for session storage
// import { get, set } from 'simple-webstorage/lib/session'

// # for cookie storage
// import { get, set } from 'simple-webstorage/lib/cookie'

setLocalStorage('key', {
  name: 'you',
  skill: [
    'angry',
    'crying'
  ]
}) 

console.log(getLocalStorage('key')) // { name: 'you', skill: ['angry', 'crying'] }
or you can import partial API like this :
// # for cookie storage
import CookieStorage from 'simple-webstorage/lib/cookie'

// # for local storage
// import LocalStorage from 'simple-webstorage/lib/local'

// # for session storage
// import SessionStorage from 'simple-webstorage/lib/session'

const cookie = CookieStorage()

cookie.set('remembered', true)
cookie.set('forgotten', true)

console.log(cookie.get('remembered')) // true # get values from key. returns any
console.log(cookie.keys()) // ['remembered', 'forgotten'] # list all keys. returns array

2. All in minified js

<script type="text/javascript" src="https://unpkg.com/simple-webstorage/lib/bundle/simple-webstorage.min.js"></script>
<script type="text/javascript">
  var storage = SimpleWebStorage();

  storage.local.set('key', 'value');
  storage.cookie.set('key', 'value', 5);
  storage.session.set('key', 'value', 5);
</script>

API Details

StorageMethodParameters
localsetkey (type: String), value (type: any, default: 0), expiryInMinutes (type: Number, default: null)
cookie or sessionsetkey (type: String), value (type: any, default: 0), expiryInMinutes (type: Number, default: 5)
local or cookie or sessiongetkey (type: String)
local or cookie or sessionremovekey (type: String)
local or cookie or sessionkeysnone
local or cookie or sessionclearnone

Support Me

Global

ko-fi

Indonesia


Feel free to contribute simple-webstorage 🙂

Copyright © 2019 by Sutan Gading Fadhillah Nasution