Const
Clear options
Optional
exclude?: string[]Cookie names to exclude from clearing
Optional
path?: stringCookie path
Optional
domain?: stringCookie domain
// Clear all cookies
StorageUtils.clearCookies();
// Clear cookies except 'session'
StorageUtils.clearCookies({ exclude: ['session'] });
Clears all values from localStorage.
Clear options
Optional
exclude?: string[]Keys to exclude from clearing
// Clear all localStorage
StorageUtils.clearLocal();
// Clear localStorage except 'settings'
StorageUtils.clearLocal({ exclude: ['settings'] });
Clears all values from sessionStorage.
Clear options
Optional
exclude?: string[]Keys to exclude from clearing
// Clear all sessionStorage
StorageUtils.clearSession();
// Clear sessionStorage except 'temp'
StorageUtils.clearSession({ exclude: ['temp'] });
Decrypts an encrypted string value.
Value to decrypt
Optional
key: stringOptional encryption key (defaults to a secure key)
Promise resolving to decrypted value
Error if decryption fails
const decrypted = await StorageUtils.decrypt(encryptedValue);
Encrypts a string value.
Value to encrypt
Optional
key: stringOptional encryption key (defaults to a secure key)
Promise resolving to encrypted value
Error if encryption fails
const encrypted = await StorageUtils.encrypt('sensitive-data');
Gets all cookies.
Cookie options
Optional
decrypt?: booleanWhether to decrypt the values
Object containing all cookies
// Get all cookies
const cookies = StorageUtils.getAllCookies();
// Get all cookies with decryption
const decryptedCookies = await StorageUtils.getAllCookies({ decrypt: true });
Gets a cookie value.
Cookie name
Cookie options
Optional
decrypt?: booleanWhether to decrypt the value
Cookie value or null if not found
// Get a cookie
const value = StorageUtils.getCookie('theme');
// Get and decrypt a cookie
const decryptedValue = await StorageUtils.getCookie('token', { decrypt: true });
Gets a value from localStorage.
Stored value or null if not found/expired
// Get a value
const value = StorageUtils.getLocal<string>('name');
// Get and decrypt a value with default
const decryptedValue = await StorageUtils.getLocal<string>('token', {
decrypt: true,
defaultValue: 'default-token'
});
Gets a value from sessionStorage.
Stored value or null if not found/expired
// Get a value
const value = StorageUtils.getSession<string>('temp');
// Get and decrypt a value with default
const decryptedValue = await StorageUtils.getSession<string>('token', {
decrypt: true,
defaultValue: 'default-token'
});
Gets the storage quota and usage.
Promise resolving to object containing quota and usage information
const quota = await StorageUtils.getStorageQuota();
console.log(`Usage: ${quota?.usage} / ${quota?.quota}`);
Gets the total size of all stored values.
Storage type ('localStorage' or 'sessionStorage')
Total size in bytes
const totalSize = StorageUtils.getTotalStorageSize('localStorage');
console.log(`Total size: ${totalSize} bytes`);
Checks if storage is available.
Storage type ('localStorage', 'sessionStorage', or 'cookie')
True if storage is available
if (StorageUtils.isStorageAvailable('localStorage')) {
// Use localStorage
}
Sets a cookie.
Cookie name
Cookie value
Cookie options
Optional
expires?: number | DateExpiration time in milliseconds or Date
Optional
path?: stringCookie path
Optional
domain?: stringCookie domain
Optional
secure?: booleanWhether the cookie requires HTTPS
Optional
sameSameSite attribute
Optional
encrypt?: booleanWhether to encrypt the value
// Set a basic cookie
StorageUtils.setCookie('theme', 'dark');
// Set a secure cookie with expiration
StorageUtils.setCookie('token', 'secret', {
expires: 86400000,
secure: true,
sameSite: 'Strict'
});
Sets a value in localStorage.
Storage key
Value to store
Storage options
Optional
expires?: numberExpiration time in milliseconds
Optional
encrypt?: booleanWhether to encrypt the value
// Set a basic value
StorageUtils.setLocal('user', { id: 1, name: 'John' });
// Set an encrypted value with expiration
StorageUtils.setLocal('token', 'secret', {
expires: 3600000,
encrypt: true
});
Sets a value in sessionStorage.
Storage key
Value to store
Storage options
Optional
expires?: numberExpiration time in milliseconds
Optional
encrypt?: booleanWhether to encrypt the value
// Set a basic value
StorageUtils.setSession('temp', { id: 1 });
// Set an encrypted value with expiration
StorageUtils.setSession('token', 'secret', {
expires: 3600000,
encrypt: true
});
Clears all cookies.