storage-modifiers
This is curated set of modifiers that can be used with the storage-engine
library.
Installation
This package is released in the public npm registery and should be used
inconjuction with the storage-engine
library:
npm install --save storage-modifiersnpm install --save storage-engine
Modifiers
The following modifiers are available in this package:
- json Automatically JSON encode / decode payloads.
- emit Emit events when keys are modified.
- expire Expire data.
- encrypt Encrypt the contents of your AsyncStorage
json
Adds automatic JSON encoding and decoding. The mergeItem
and multiMerge
API's
of the AsyncStorage API already promote the usage of JSON for your values. This
plugin does it automatically for you.
;; storage; await storage; const value = await storage // { would: "not", ...}
emit
Allows you to emit an event every time when a given key is accessed, this allows you for example to track changes to values.
;; storage; storage; storage; await storage; //// console output://// - setItem accessed "key" which is now has value: "value"// - what is up from `setItem` is called on key: "key"//
The emit
plugin understands the following options:
key
Emit the events with the key as event name.operation
Emit the operation as event name.
expire
Allows you to automatically expire keys and remove it from your AsyncStorage.
;; storage; await storage; // expires in 10 minutes
The expire
plugin understands the following options:
duration
The TTL of the values that get stored in these keys.
encrypt
Provides an additional layer of security for AsyncStorage by encrypting the
values using crypto-js
. This ensures that when the AsyncStorage is flushed
to disk, the contents will still be encoded.
;; storage;
The encrypt
plugin understands the following options:
secret
, required, The secret key/passcode to use to encode/decode contents.encryption
, required, The encryption algorithm to use. Can be any of the supported encryption libraries; https://github.com/brix/crypto-js#list-of-modules Please note that casing is important heresha3
is invalid, whileSHA3
is accepted.
License
(MIT)[LICENSE]