Getting Started - macmcmeans/localDataStorage GitHub Wiki
The code is contained in one JavaScript file, designed against Christian Heilmann’s Revealing Module pattern. It returns an Immediately Invoked Function Expression (IIFE) that creates an isolated local scope for all methods and variables to prevent global pollution. This approach lets you call multiple instances of localDataStorage.
To use localDataStorage--
- bring the code into your page (via <script> tags, direct copy, etc.)
- instantiate it with a meaningful prefix (to provide namespacing)
The generic call would look something like localDataStorage( prefix, switch ).
For example:
<script
src="https://cdn.jsdelivr.net/gh/macmcmeans/localDataStorage@master/localDataStorage-3.0.0.min.js"
integrity="sha512-dEhk3bL90qpWkcHCJDErHbZEY7hGc4ozmKss33HSjwMeSBKBtiw/XVIE7tb5u+iOEp6dTIR9sCWW7J3txeTQIw=="
crossorigin="anonymous"
></script><script>
> const lds = localDataStorage( 'prismCipher' );
💼 localDataStorage instantiated. Your specified prefix (prismCipher.) adds 12 bytes to every key name (stored using 24 bytes).
// create a handy Array Key
> lds.set( 'authorName', ['Mac'] );
// check storage requirements for the key's value
> lds.valbytes( 'authorName' );
'6 bytes'
// query the data type
> lds.showtype( 'authorName' );
'array'
// explicitly check the data type
> lds.isarray( 'authorName' );
true
// add another value to the key
> lds.push( 'authorName', 'McMeans' );
// rename the key
> lds.rename( 'authorName', 'author' );
// get the key's value
> lds.get( 'author' );
['Mac', 'McMeans']
// check the Array Key for a certain value
>lds.contains( 'author', 'Mac' );
true
// prepend value to key (at start of array)
> lds.push( 'author', 'Big', 1 );
// get the updated value
> lds.get( 'author' );
['Big', 'Mac', 'McMeans']
// rename an element (at 2nd index)
> lds.poke( 'author', 'William', 2 );
// yank an element (using value literal);
> lds.pull( 'author', 'Big' );
// get the latest value
> lds.get( 'author' );
['William', 'McMeans']
</script>At this point all key names will have the prefix passphrase.life. prepended to them (note the trailing period), so calling set( 'authorName', ['Mac'] ) will store the authorName Array Key as passphrase.life.authorName internally with a value of ['Mac'].
To control how localDataStorage starts up, you may use a few switches. You should specify a prefix to prevent storage contamination.