Coder Social home page Coder Social logo

lspi's Introduction

Local Storage Programming Interface

Basic ORM for local storage that can save you time!

Super easy to use!

Store and retrieve valid JSON objects/arrays or simple strings ๐Ÿ˜„

Make sure to use polyfills for Array.from and Object.assign when bundling your application code! ๐ŸŽ‰

Install

npm install lspi --save

Basics

const lspi = require('lspi');

//= set string ->
lspi.set('testOne', 'testing');
// Returns: undefined
// Stores: "testing"

//= get string ->
lspi.get('testOne');
// Returns: "testOne"

//= set object literal ->
lspi.set('testOne', {});
// Returns: undefined
// Stores: "{}"

//= get object literal ->
lspi.get('testOne');
// Returns: {}

//= set array ->
lspi.set('testTwo', []);
// Returns: undefined
// Stores: "[]"

//= get array ->
lspi.get('testTwo');
// Returns: []

//= set array of objects ->
lspi.set('testOne', [{ name: 'test' }, { name: 'test2' }]);
// Returns: undefined
// Stores: "{"name": "test2"}"

//= where query on array of objects ->
lspi.where('testOne', 'name', 'test2');
// Returns: [{ name: 'test2' }]

//= update state ->
lspi.set('test42', { hey: 'hi' });

lspi.update('test42', { ok: 'new stuff' });
// Returns: undefined
// Adds ok key and 'new stuff' value to the 'testOne' record

lspi.update('test42', { hey: 'hello' });
// Returns: undefined
// Updates hey value to 'hello' instead of 'hi'

//= remove data (singular) ->
lspi.drop('testOne');
// Returns: undefined
// This will delete the 'testOne' record from localStorage

//= remove all data ->
lspi.dropAll();
// Returns: undefined
// Drops ALL localStorage associated to your domain

//= Mutiple set ->
lspi.sets(['test', { wow: 'wow1' }], ['test2', { wow: 'wow2' }]);
// Returns: undefined
// Stores: {wow: 'wow1'} in mthe 'test' key
// Stores: {wow: 'wow2'} in the 'test2' key

const testDataOne = lspi.get('test');
const testDataTwo = lspi.get('test2');

testDataOne; // => {wow: 'wow1'}
testDataTwo; // => {wow: 'wow2'}

//= Multiple get ->\
lspi.sets(['test', { wow: 'wow' }], ['test2', { wow: 'wow' }]);

const testData = lspi.gets('test', 'test2');

testData; // => ['test', {wow: 'wow'}], ['test2', {wow: 'wow'}]

//= Multiple drop ->
lspi.sets(
  ['test', { wow: 'wow1' }],
  ['test2', { wow: 'wow2' }],
  ['test3', { wow: 'wow3' }],
);

lspi.drops('test', 'test2');
// Returns: undefined
// 'test3' -> {wow: 'wow3'} remains

lspi's People

Contributors

selfup avatar dependabot[bot] avatar

Stargazers

pdina avatar Mohammad Bagher Ehtemam avatar Guido avatar Porramate Lim avatar Andrejs Agejevs avatar Sam Rose avatar

Watchers

James Cloos avatar  avatar  avatar

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.