with-storage
A package that auto binds object or class properties to local-storage for persistance and easy manipulation.
Installation Instructions
$ yarn add with-storage
Example
; ; user.email = "somemail@gmail.com"; // <-- cookie created console.loguser.email; // <-- 'somemail@gmail.com'// RESTART application and remove setting your email above - try logging the same propertyconsole.loguser.email; // <-- 'somemail@gmail.com' is still there // DESTROY cookie simply just re-assign the value to "", undefined, or delete obj.key.// setting value to undefined reverts to static defaults upon reloaduser.email = "";
class example
; ; user.email = "somemail@gmail.com"; // check to see if cookie exist with cookie util.// cookies are stored formatted `${constructor.name || config.name}_{$key}`console.loggetStorageItem"User_email"; // <-- 'somemail@gmail.com'
Available Configuration
param | default | type | description |
---|---|---|---|
name | constructor.name | string | Optional: A keyname for cookie storage if anonymous object. |
Example adjusting configuration. Simply pass in the object as the second param.
; ;