Coder Social home page Coder Social logo

ambry's Introduction

Ambry Build Status

Ambry is WebStorage wrapper that makes your life easier. It's target is to improve developer experience and to cover inconsistency in browser implemetations. Using Ambry you can create storages with namespaces, control scheme version and subscribe to particular storage.

Tests are powered by BrowserStack โ€” cool cross browser testing tool.

Installation

npm install --save ambry

Creating storage

import { createStorage } from 'ambry';

const storage = createStorage(config);

config consists of:

  • type โ€” should be 'localStorage' or 'sessionStorage' (Default value: 'localStorage')
  • namespace - prefix for your storage in storage key field (Default value: null)
  • schemeVersion - your scheme version which is useful in cases your storage structure could change over time (Default value: null)
  • clearOnError - if true clears field when parsing for getItem() fails or when setItem() is impossible because of storage quota has exceeded (Default value: true)
  • doNotThrow - if true then creates dummy storage instead of throwing error. Dummy storage has all methods that standard storage has (Default value: true)

Setting new value or updating value

storage.setItem(field, value);

If quota is exceeded and you have clearOnError set to true then storage will be cleared, then scheme version will be set if needed and then setItem() will be called another time

Getting value

storage.getItem(field);

If value for that field can't be parsed and clearOnError is set to true then that value will be removed from storage

Removing value

storage.removeItem(field);

Clearing storage

storage.clear();

Changing scheme version

storage.setSchemeVersion(version);

This will clear storage if previous version is not strictly equal to new version

Subscribing to storage changes

const unsubscribe = storage.subscribe(handler);

This will subscribe to that particular storage changes only. It returns new function which when called will unsubscribe your handler.

The handler is callback function which has such parameters:

  • key - the field name inside of storage
  • oldValue - previous value for that key
  • newValue - new value for that key

Converting existing localStorage or sessionStorage data to Ambry storage

If you have Web Storage in your app you can just createStorage() to work with it as with Ambry storage. You can even split your storage data to multiple Ambry storages using namespace

Contributing

Your contributions are always welcome! Please feel free to create issues.

ambry's People

Contributors

chicoxyzzy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

vyorkin-forks

ambry's Issues

Tests

Ambry should be covered by tests running them in real browsers. Please recommend free services for opensource projects which can do it.

A couple of typos in README

There are a couple of typos in README:

your scheme version wich is useful
because of storage quota has exceede

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.