Session

Class for dealing with session storage.

Constructor

new Session()

Example
Session.getAll();

Methods

(static) clear() → {void}

Delete all data saved in the Session storage

Returns:
Type: 
void
Example
Session.clear();

(static) getAll(jsonopt) → {any}

Get all data saved in the Session storage

Parameters:
NameTypeAttributesDefaultDescription
jsonboolean<optional>
false

if true, return the data in json format

Returns:

the data saved in the local storage

Type: 
any
Example
Session.getAll();

(static) getData(key) → {any}

Get a specific data saved in the Session storage

Parameters:
NameTypeDescription
keystring

key of the data to get

Returns:

the data saved in the Session storage

Type: 
any
Example
Session.getData("myKey");

(static) has(key) → {boolean}

Check if the given key is stored

Parameters:
NameTypeDescription
keystring

key to check

Returns:

true if the key is stored

Type: 
boolean
Example
Session.has("myKey");

(static) isEmpty() → {boolean}

Check if the Session storage is empty

Returns:
  • true if the Session storage is empty
Type: 
boolean
Example
Session.isEmpty();

(static) keys() → {Array.<string>}

Get keys of the stored items

Returns:

return all keys

Type: 
Array.<string>
Example
Session.keys();

(static) removeData(key) → {void}

Delete a specific data by name

Parameters:
NameTypeDescription
keysting

the name of the data to delete

Returns:
Type: 
void
Example
Session.removeData("myKey");

(static) setData(key, value) → {void}

Save/change a specific data by key

Parameters:
NameTypeDescription
keystring

name of the key

valueany

value of the item

Returns:
Type: 
void
Examples
Session.setData("myKeyString", "myString");
Session.setData("myKeyBool", true);
Session.setData("myKeyNumber", 1234567890);
Session.setData("myKeyObject", {name: "Dog", age: 3,});
Session.setData("myKeyArr", [1, 2, 3, 4, 5]);

(static) setName(name) → {void}

Change the name of data saved in the Session storage

Parameters:
NameTypeDescription
namestring

the name to save the data in the Session storage

Returns:
Type: 
void
Example
Session.setName("mySessionStorage");

(static) size() → {number}

Get number of stored items

Returns:

number of stored items

Type: 
number
Example
Session.size();

(static) updateAll(data) → {void}

Save/change all data

Parameters:
NameTypeDescription
dataany

data to save

Returns:
Type: 
void
Example
Session.updateAll({ otherNewData: "Hello World" });