Git Product home page Git Product logo

simple_localstorage_api's Introduction

Simple LocalStorage API

Better API to for storage data in localStorage, sessionStorage or Memory

Support for an expire date

Support for data collection

Installation

npm install --save simple_localstorage_api

API

import { Store } from 'simple_localstorage_api';
const store = new Store(); // default is window.localStorage

store.set('key', {data,...})

###Use store as session Storage

const store = new Store({type: 'session'}) // use window.sessionStorage

###Use store as Memory Storage

const store = new Store({type: 'memory'})

###Insert a record by key

const store = new Store()
store.insert('mykey', {id:1,name:'test'});

###Insert a record with an expire date

const store = new Store()

store.insert('mykey', {id:1, name:'test', expireAfter: 2}) // Exipre in 2 Miniutes 

store.insert('mykey', {id:1,name:'test', expireAfter: '2.minutes'}); // Expire in 2 miniutes
store.insert('mykey', {id:1,name:'test', expireAfter: '2.hours'}); // Expire in 2 hours
/*
supported key base on moment.js = 
years
quarters
months
weeks
days
hours
minutes
seconds	
milliseconds
*/

###Find a record by key

store.find('mykey') ;
//return json object

###Insert a collection by key

const store = new Store();
store.set('mycollection', {items: [{id:1}, {id:2}], expireAfter: 5});

###Add item into a collection

const store = new Store();
store.addItem('mycollection', {id: 3});

###Find item from a collection

const store = new Store();
store.findItem('mycollection', item => item.id === 1);

###Update item into a collection

const store = new Store();
store.updateItem('mycollection', {name: 'test'}, item => item.id === 1);

###Remove item form a collection

const store = new Store();
store.removeItem('mycollection', item => item.id === 1);

###Remove a record by key

store.clear('mykey');

###Remove all the records from store

store.clear();

License

MIT, see LICENSE.md for more information.

simple_localstorage_api's People

Contributors

khakurel avatar

Stargazers

Roman avatar Suraj Khakurel avatar  avatar

Watchers

 avatar

simple_localstorage_api's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.