yourstorage v1.2.1
Storage: yourstorage
npm install yourstorage --save
.Add
"moduleResolution": "node"
to your tsconfig file to allow build-in types to be used. This will not affect any other types.Commonjs
import * as storage from 'yourstorage'
or amdconst storage = require('storage')
.
Using storage
storage.set
assign the variabel to a function to get or set value.
const username = storage.set('username', prompt('Username please: ') || 'Bill Gates', options);
Get or set storage value
// set the username to 'Donald Trump'
username('Donald Trump');
username();
// Expected output: 'Donald Trump'
Readonly storages
const options = {
readonly: true
}
Cookie storage
Storage is default set to LocalStorage but you can change it to cookie so the server can access it.
const options = {
storage: 'cookie'
}
Secure cookie connection
Storage option secure is default set to 'http' (unsecure) but you can set it to 'https' (secure) by changing the secure option to true (or false for unsecure connection).
const options = {
secure: true
}
storage
'cookie' | 'local'
Which storage the key should be stored in. local will not share data to the server. Cookie will share data to the server
expires
number | Date
Define when the cookie will be removed. Value can be a Number which will be interpreted as days from time of creation or a Date instance. If omitted, the cookie becomes a session cookie.
path
string
Define the path where the cookie is available. Defaults to '/'.
domain
string
Define the domain where the cookie is available. Defaults to the domain of the page where the cookie was created.
secure
boolean
A Boolean indicating if the cookie transmission requires a secure protocol (https). Defaults to false.
Please sponsor me by giving this repo a !