Skip to main content
Version: v3+

TypedStorage

Start from API_LEVEL 3.0 . Please refer to API_LEVEL.

Typed key-value storage backed by system properties. Suitable for primitive values such as booleans, numbers and strings..

Constructor

Create a typed storage instance. The optional scope isolates key names.

constructor(scope?: string)

Methods

getBool

Get a boolean value

getBool(key: string, defaultValue: boolean): boolean

getInt

Get an integer value

getInt(key: string, defaultValue: number): number

getInt64

Get a 64-bit integer value

getInt64(key: string, defaultValue: number): number

getDouble

Get a double value

getDouble(key: string, defaultValue: number): number

getString

Get a string value

getString(key: string, defaultValue: string): string

putBool

Set a boolean value

putBool(key: string, value: boolean): number

putInt

Set an integer value

putInt(key: string, value: number): number

putInt64

Set a 64-bit integer value

putInt64(key: string, value: number): number

putDouble

Set a double value

putDouble(key: string, value: number): number

putString

Set a string value

putString(key: string, value: string): number

has

Check whether a key exists

has(key: string): boolean

clear

Clear all typed storage data

clear(): void

remove

Delete a value by key

remove(key: string): boolean

Example

import { TypedStorage } from '@zos/storage'

const storage = new TypedStorage()
storage.putBool('enabled', true)
storage.putInt('count', 1)

const enabled = storage.getBool('enabled', false)
const count = storage.getInt('count', 0)