Home Manual Reference Source Test Repository
import {Storage} from '@cedx/ngx-webstorage/src/storage.js'
public class | source

Storage

Provides access to the Web storage. See: https://developer.mozilla.org/en-US/docs/Web/API/Storage

Test:

Constructor Summary

Public Constructor
public

constructor(backend: Storage)

Initializes a new instance of the class.

Member Summary

Public Members
public get

The keys of this storage.

public get

The number of entries in this storage.

public get

onChanges: Observable<KeyValueChangeRecord[]>

The stream of "changes" events.

Method Summary

Public Methods
public

Returns a new iterator that allows iterating the entries of this storage.

public

clear()

Removes all entries from this storage.

public

get(key: string, defaultValue: *): string

Gets the value associated to the specified key.

public

getObject(key: string, defaultValue: *): *

Gets the deserialized value associated to the specified key.

public

has(key: string): boolean

Gets a value indicating whether this storage contains the specified key.

public

remove(key: string)

Removes the value associated to the specified key.

public

set(key: string, value: string)

Associates a given value to the specified key.

public

setObject(key: string, value: *)

Serializes and associates a given value to the specified key.

Public Constructors

public constructor(backend: Storage) source

Initializes a new instance of the class.

Params:

NameTypeAttributeDescription
backend Storage

The underlying data store.

Public Members

public get keys: string[] source

The keys of this storage.

Test:

public get length: number source

The number of entries in this storage.

Test:

public get onChanges: Observable<KeyValueChangeRecord[]> source

The stream of "changes" events.

Test:

Public Methods

public * [Symbol.iterator]() source

Returns a new iterator that allows iterating the entries of this storage.

public clear() source

Removes all entries from this storage.

Test:

public get(key: string, defaultValue: *): string source

Gets the value associated to the specified key.

Params:

NameTypeAttributeDescription
key string

The key to seek for.

defaultValue *

The default item value if it does not exist.

Return:

string

The value of the storage item, or the default value if the item is not found.

Test:

public getObject(key: string, defaultValue: *): * source

Gets the deserialized value associated to the specified key.

Params:

NameTypeAttributeDescription
key string

The key to seek for.

defaultValue *

The default item value if it does not exist.

Return:

*

The deserialized value of the storage item, or the default value if the item is not found.

Test:

public has(key: string): boolean source

Gets a value indicating whether this storage contains the specified key.

Params:

NameTypeAttributeDescription
key string

The key to seek for.

Return:

boolean

true if this storage contains the specified key, otherwise false.

Test:

public remove(key: string) source

Removes the value associated to the specified key.

Params:

NameTypeAttributeDescription
key string

The key to seek for.

Test:

public set(key: string, value: string) source

Associates a given value to the specified key.

Params:

NameTypeAttributeDescription
key string

The key to seek for.

value string

The item value.

Test:

public setObject(key: string, value: *) source

Serializes and associates a given value to the specified key.

Params:

NameTypeAttributeDescription
key string

The key to seek for.

value *

The item value.

Test: