-
-
Notifications
You must be signed in to change notification settings - Fork 15
Getting Started
The code is contained in one JavaScript file, designed against Christian Heilmann’s Revealing Module pattern. It returns an Immediately Invoked Function Expression (IIFE) to create a local scope for all methods and variables in order to avoid polluting the global scope.
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-2.0.0.min.js"
integrity="sha512-LWDNA967l6GIvNL3geN+hC7OMAfLDDUN1RdXUb8lLABMAbmOlbO6HUPJx84rzFH7wEqnJq9AEM59cLzRElv9QQ=="
crossorigin="anonymous"
></script>
<script>
> const lds = localDataStorage( 'passphrase.life' );
> lds.version;
'2.0.0'
// 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.
Array Keys:
push / pull, pullall poke contains where
Broadcasting:
broadcast
Data Transfer:
import / export
Duplicates:
countdupes, showdupes, listdupes
Internals:
cancrunch crunch / uncrunch
shufflestring / unshufflestring
Management:
keys
Memory Consumption:
Memory Quota:
showquota
Query:
haskey, hasval, hastype
setscramblekey / getscramblekey
Type Check:
isarray isbigint isboolean iscrunch
isdate isfloat isinteger isnull
Utility:
chopget copy softset rename
_set / _get _clear _key _remove
Management:
_keys
Type Check:
_isarray _isbigint _isboolean _iscrunch