0.5.0 • Published 3 years ago

storage-helpers v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

storage-helpers npm version GitHub license bundle size on npm type-coverage

Description

A set of tools to manage localStorage, sessionStorage and more that run on browsers, node and deno.

Main features

  • tiny, less than 1kB, and tree-shakable.

  • optional storage key versioning and namespace.

  • optional custom serialization and hydration logic.

  • optional validation of hydrated data.

Simple example

const storageConfig = {
  version: "v2",
  namespace: "user-conf"
};

// persists on localStorage `[user-conf]i18n@v2` -> `{"locale":"es-ES","floatingPoint":"dot","unit":"metric"}`
setStorageItem("i18n", { locale: 'es-ES', floatingPoint: 'dot', unit: 'metric' }, storageConfig);

// returns `{"locale":"es-ES","floatingPoint":"dot","unit":"metric"}` hydrated
getStorageItem("i18n", storageConfig);

Installation

node

Add storage-helpers to package.json

  npm i storage-helpers --save

deno

Import directly in your typescript files

import { setStorageItem }  "https://deno.land/x/storage_helpers@v0.4.2/mod.ts";

UMD build

html files

  <script src="https://unpkg.com/storage-helpers@0.4.2/dist/storage_helpers.umd.production.min.js"></script>

Documentation

License

MIT

0.5.0

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago