Skip to content

Getting Started

W. "Mac" McMeans edited this page Aug 12, 2022 · 44 revisions

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--

  1. bring the code into your page (via <script> tags, direct copy, etc.)
  2. 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.

localStorage Keys

The usual suspects:

set / get      clear      key      remove

The esoteric ones:

Array Keys:
push / pull, pullall      poke      contains      where

Broadcasting:
broadcast

Bypass:
forceset / forceget

Data Transfer:
import / export

Duplicates:
countdupes, showdupes, listdupes

Internals:
cancrunch      crunch / uncrunch

shufflestring / unshufflestring

xorstring

Management:
keys

Memory Consumption:

Memory Quota:
showquota

Query:
haskey, hasval, hastype

Security:
safeset / safeget

setscramblekey / getscramblekey

Type Check:
isarray      isbigint      isboolean      iscrunch

isdate      isfloat      isinteger      isnull

isnumber      isobject      isstring

showtype

Utility:
chopget      copy      softset      rename

Properties:

channel      length      quota      version

Settings:

verbosity

Memory Keys

Standard:

_set / _get      _clear      _key      _remove

Unconventional:

Data Sync:
_backup / _restore

Management:
_keys

Security:
_safeset / _safeget

Type Check:
_isarray      _isbigint      _isboolean      _iscrunch

_isdate      _isfloat      _isinteger      _isnull

_isnumber      _isobject      _isstring

_showtype

Utility:
_chopget      _copy      _softset      _rename

Clone this wiki locally