1.0.8 • Published 5 years ago

store5 v1.0.8

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

store5

An easier way to store data in the browser. LocalStorage, sessionStorage, cookie supported.

1. Including store5

(1) Script tag

<script src="dist/store5.min.js"></script>
<script>
  // set/get string
  store5.set('name', 'Terry Chan', new Date().getTime() + 5000); // expired after 5 second
  store5.get('name'); //=> 'Terry Chan'
</script>

(2) cmd/amd

define(['store5'], function(store5) {
  // set/get array
  store5.set('book', ['HarryPotter', 'magic', 'J. K. Rowling']);
  store5.get('book')[0]; //=> 'HarryPotter'
});

(3) webpack

Run npm install --save store5 or yarn add store5 to install store5.

import { set, get, remove } from 'store5';
//or `import store5 from 'store5';`

// set/get json
set('book', {
  name: 'Harry Potter',
  author: 'J. K. Rowling',
  keyword: ['HarryPotter', 'magic', 'J. K. Rowling'],
});
get('book').author; //=> 'J. K. Rowling'
remove('book');

2 Using store5

(1) set

  • set( key, value, expire, type )
    • key:Key.
    • value:Value. Number, string, array, json... supported.
    • expire:Expired timestamp(millisecond). 0(not expired) as default.
    • type0(default), 1 or 2.
      • 0 => Use localStorage to store data.
      • 1 => sessionStorage.
      • 2 => cookie.
  • setLocalStorage( key, value, expire )
  • setSessionStorage( key, value, expire )
  • setCookie( key, value, expire )

(2) get

  • get(key, type) Get a piece of data.
  • getLocalStorage(key)
  • getSessionStorage(key)
  • getCookie(key)

(3) remove

  • remove( key, type ) Remove the data of specified key and type.
  • removeLocalStorage( key )
  • removeSessionStorage( key )
  • removeCookie( key )

(4) clear

  • clear( type ) Empty the specified type of data.
  • clearLocalStorage()
  • clearSessionStorage()
  • clearCookie()
1.0.8

5 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

8 years ago