0.0.3 • Published 5 years ago
instore v0.0.3
inStore
Use the localStorage like a boss 🤞.
Table of contents
Getting started
Install with npm
.
npm i --save instore
Usage
Basic examples
import inStore from 'instore';
// Your initial state (default storage value)
const initialState = {
users: [
{ name: "Ellen Waters" , age: 31 },
{ name: "Brandon Park" , age: 26 },
{ name: "Travis Campbell" , age: 28 },
{ name: "Thomas Chavez" , age: 18 },
{ name: "Travis Peters" , age: 19 },
],
color: {
hexa: "#74ADDA",
rgb: "rgb(186,41,90)"
},
configs: {
//... blablabla
}
}
// Pass your default storage,
// but if its already exists, this will be ignored
// and the current storage (in the localStorage) will
// be loaded instead
const storage = new inStore(initialState);
// Acessing storage data
storage.get('/users')
/*
[
{ name: "Ellen Waters" , age: 31 },
{ name: "Travis Campbell" , age: 28 },
{ name: "Thomas Chavez" , age: 18 },
...,
],
*/
storage.get('/color/hexa') // -> "#74ADDA"
// Adding new data
storage.post('/foo', { bar : true });
storage.get('/foo/bar') // -> true
// Removing data
storage.remove('/foo')
storage.get('/foo') // -> undefined
storage.get('/foo/bar') // -> Error
// Transforming the results
storage.get('/users', {
where: user => user.age >= 26,
orderBy: 'age'
})
/*
[
{ name: "Brandon Park" , age: 26 },
{ name: "Travis Campbell" , age: 28 },
{ name: "Ellen Waters" , age: 31 }
]
*/
Features
Why use inStore instead of javascript vanilla localStorage object?
There are some features:
- You can easily manipulate your localStorage with multiples inStore objects to save your app state.
- You have a set of methods to easily manipulate the localStorage.
- You can attach event listeners to your inStore object.
- Integrate very well with javascript frameworks like Svelte, Angular, Vue, React and etc.
- Simulate requests to a database with the inStore.async to test how your UI handle promises and asynchronous code.
- Because you deserve the best :v:.
Documentation
To learn how to use this module, see the Wiki page.
License
This project is under the ISC license.
Author
This project was created by jbpsz.