npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ambry

v1.1.0

Published

WebStorage wrapper that makes your life easier

Downloads

26

Readme

Ambry

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 wich 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 exceede (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.