1.0.4 • Published 6 years ago

localStorage v1.0.4

Weekly downloads
32,683
License
(MIT OR Apache-2....
Repository
-
Last release
6 years ago

DOMStorage

See https://git.coolaj86.com/coolaj86/dom-storage.js for a slightly better version of the same thing.

localStorage

An inefficient, but as W3C-compliant as possible using only pure JavaScript, localStorage implementation.

Purpose

This is meant for the purpose of being able to run unit-tests and such for browser-y modules in node.

Usage

var localStorage = require('localStorage')
  , myValue = { foo: 'bar', baz: 'quux' }
  ;

localStorage.setItem('myKey', JSON.stringify(myValue));
myValue = localStorage.getItem('myKey');

API

  • getItem(key)
  • setItem(key, value)
  • removeItem(key)
  • clear()
  • key(n)
  • length

Tests

null === localStorage.getItem('key');

0 === localStorage.length;
null === localStorage.getItem('doesn't exist');
undefined === localStorage['doesn't exist'];

localStorage.setItem('myItem');
"undefined" === localStorage.getItem('myItem');
1 === localStorage.length;

localStorage.setItem('myItem', 0);
"0" === localStorage.getItem('myItem');

localStorage.removeItem('myItem', 0);
0 === localStorage.length;

localStorage.clear();
0 === localStorage.length;

TODO / Bugs

  • Does not persist.
    • could use fs.readFileSync at load and an occasional fs.writeFile to write-out localStorage.json
  • Doesn't not emit Storage events
alaexplorerjs-keygenpcs-notif-and-msguc-coreomnb-twittergatewaypcjs-keygengatsby-source-modular-graphqlskill-f3@infinitebrahmanuniverse/nolb-localsresnodepackage@everything-registry/sub-chunk-2092septsegoselenium-webdriver-selectorscraper-enginesinch-rtcenujs-keygeneosjs-keygenstackmob-nodejsstraas-message-sdkredux-toolbox-fetchredux-lbclientreact-svelte-storesrfml-to-coffeespoojseasyoncloudeasyoncloud-sdkecc-test-helpersquality-botdk-designuiedge-ko12sdzsedgebase-frontedgebase-front-aaaaedgebase-front-asdmengqhedgebase-front-ghjasedgebase-front-mengedgebase-front-v2cc-wallet-corecelesjs-keygenclient-side-storagecloudboostcloudboost-tvproductmarveljs2contentstack@connext/store@byorbit/or-ui-jupiter@byorbit/or-ui-kerber@byorbit/or-ui-master-layout@yeutech-lab/test-polyfillbonjs-keygencomsis_jmyrc-antd-pro-libcrehub_node_sdkbashful-fs@anephenix/hubfireauththeme-customizer@rtssaas2022/am_sdk@rtssaas2022/rf_sdk@rtssaas2022/rm_sdkalakeygen1@zalastax/nolb-localsapollo-link-local-cachearisenjs-keygen@yakies/http@sauban/cloudboost@trackingplan/node@snaxfoundation/snaxjs-keygenabaaso@unibiz/uplinkabhnv-testfscjs-keygenjm-intlnextkeigaikarma-jsdomlocalstorage-launcherkeyvaluestorageturris-test-helpersuc-sdkuc-core-jsuc-coresharo-localstoragevexjs-keygenhonk-test-netgeneric_storeunif-uc-sdkhaasts-traversehanxiuhjwt-auth-apizb-eosjs-keygenls-chunk-storemaxleap-js-sdklycamplusnbpeer@maofung/edgebase-frontmarvel-js-corejs-unif-commonjs-unif-corejs-unif-core-newjs-unif-core-v1js-unif-core-v2js-uniframe-core
1.0.4

6 years ago

1.0.3

10 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

13 years ago