0.0.3 • Published 5 years ago

instore v0.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

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:

  1. You can easily manipulate your localStorage with multiples inStore objects to save your app state.
  2. You have a set of methods to easily manipulate the localStorage.
  3. You can attach event listeners to your inStore object.
  4. Integrate very well with javascript frameworks like Svelte, Angular, Vue, React and etc.
  5. Simulate requests to a database with the inStore.async to test how your UI handle promises and asynchronous code.
  6. 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.

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago