Local Storage Helpers
- Description:
Local Storage Helpers
Methods
(static) getCookie(name) → {string|undefined}
Get a cookie value by name.
- Description:
Get a cookie value by name.
Example
// If document.cookie = "token=abc123; user=phane"
getCookie('token') => 'abc123'
getCookie('user') => 'phane'
getCookie('missing') => undefined
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Cookie name |
Returns:
The cookie value, or undefined if not found or invalid input
- Type
- string | undefined
(static) getLocalStorageItem(name) → {*|undefined}
Get and parse a value from localStorage by key name.
- Description:
Get and parse a value from localStorage by key name.
Example
getLocalStorageItem('user') => { name: 'Phane' }
getLocalStorageItem('unknown') => undefined
getLocalStorageItem(null) => undefined
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The localStorage key name |
Returns:
Parsed value from localStorage, undefined if invalid or not found
- Type
- * | undefined
(static) getSessionStorageItem(name) → {*|undefined}
Get and parse a value from sessionStorage by key name.
- Description:
Get and parse a value from sessionStorage by key name.
Example
getSessionStorageItem('user') => { name: 'Phane' }
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The sessionStorage key name |
Returns:
Parsed value, undefined if invalid or not found
- Type
- * | undefined
(static) removeCookie(name, optionsopt) → {undefined}
Remove a cookie by name.
- Description:
Remove a cookie by name.
Example
removeCookie('token');
removeCookie('user', { path: '/admin', domain: '.example.com' });
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
string | Cookie name |
|||||||||||||
options |
object |
<optional> |
Optional attributes to match scope Properties
|
Returns:
Returns undefined for invalid input
- Type
- undefined
(static) removeLocalStorage() → {undefined}
Clear all items from localStorage.
- Description:
Clear all items from localStorage.
Example
removeLocalStorage()
Returns:
Clears localStorage
- Type
- undefined
(static) removeLocalStorageItem(name) → {undefined}
Remove a specific item from localStorage.
- Description:
Remove a specific item from localStorage.
Example
removeLocalStorageItem('user')
removeLocalStorageItem(null) => undefined
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The localStorage key name |
Returns:
Returns undefined for invalid input
- Type
- undefined
(static) removeSessionStorage() → {undefined}
Clear all items from sessionStorage.
- Description:
Clear all items from sessionStorage.
Example
removeSessionStorage()
Returns:
Clears sessionStorage
- Type
- undefined
(static) removeSessionStorageItem(name) → {undefined}
Remove a specific item from sessionStorage.
- Description:
Remove a specific item from sessionStorage.
Example
removeSessionStorageItem('user')
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The sessionStorage key name |
Returns:
Returns undefined for invalid input
- Type
- undefined
(static) setCookie(properties) → {undefined}
Set a cookie using an object for properties.
- Description:
Set a cookie using an object for properties.
Example
setCookie({ name: 'token', value: 'abc123', days: 7, secure: true })
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
properties |
object | Cookie properties Properties
|
Returns:
Returns undefined if invalid input
- Type
- undefined
(static) setLocalStorageItem(name, data) → {undefined}
Store a value in localStorage after stringifying it.
- Description:
Store a value in localStorage after stringifying it.
Example
setLocalStorageItem('user', { name: 'Phane' })
setLocalStorageItem(null, {}) => undefined
setLocalStorageItem('user') => undefined
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The localStorage key name |
data |
* | Data to store in localStorage |
Returns:
Returns undefined for invalid input
- Type
- undefined
(static) setSessionStorageItem(name, data) → {undefined}
Store a value in sessionStorage after stringifying it.
- Description:
Store a value in sessionStorage after stringifying it.
Example
setSessionStorageItem('user', { name: 'Phane' })
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The sessionStorage key name |
data |
* | Data to store |
Returns:
Returns undefined for invalid input
- Type
- undefined