Class Storage
Source: storage.ts
A wrapper for localStorage with additional functionality like compression and a size limit.
Extended by
Constructors
Constructor
new Storage():
Storage
Returns
Storage
Properties
MAX_BYTES
readonlystaticMAX_BYTES:5000000=5_000_000
The maximum amount of bytes of a value in this storage.
COMPRESSED_PREFIX
readonlystaticCOMPRESSED_PREFIX:""="\uE000"
UNCOMPRESSED_PREFIX
readonlystaticUNCOMPRESSED_PREFIX:""="\uE001"
enableCompression
enableCompression:
boolean=false
Enables compression of values stored in this storage.
Default
falseprefix
prefix:
string|undefined
The prefix to prepend to keys.
Default
undefinedMethods
getByteSize()
staticgetByteSize(string:string|null):number
Parameters
string
string | null
Returns
number
byteToKilobyte()
staticbyteToKilobyte(bytes:number):number
Parameters
bytes
number
Returns
number
store()
store(
key:string,value:string):void
Stores a key and value pair in this storage.
Parameters
key
string
The key to store.
value
string
The value to store.
Returns
void
load()
load(
key:string):string|null
Loads a value associated with the given key.
Parameters
key
string
The key of the item.
Returns
string | null
The value of the item.
rename()
rename(
oldKey:string,newKey:string):this
Replaces the key of an item if it exists.
Parameters
oldKey
string
The key to replace.
newKey
string
The new key.
Returns
this
remove()
remove(
key:string):this
Removes the item with the given key from this storage.
Parameters
key
string
The key of the item.
Returns
this
clear()
clear():
this
Clears all items stored in this storage.
Returns
this
getItemByteSize()
getItemByteSize(
key:string,value:string):number
Returns the byte size of a key and value pair.
Parameters
key
string
The key of the item.
value
string
The value of the item.
Returns
number
getEncodedByteSize()
getEncodedByteSize(
string:string|null):number
Parameters
string
string | null
Returns
number
encode()
encode(
string:string): {result:string;size:number; }
Parameters
string
string
Returns
{ result: string; size: number; }
result
result:
string
size
size:
number
decode()
decode(
string:string):string
Parameters
string
string
Returns
string
setPrefix()
setPrefix(
prefix?:string):this
Parameters
prefix?
string
Returns
this