Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface StoreObjectConfig<O>

Configuration for StoreObjectConfig

Type parameters

  • O: Record<string, any>

    The stored object

Hierarchy

  • CommonConfig
    • StoreObjectConfig

Index

Properties

checkDefaults?: boolean

Whether or not to look for existing values before using the defaults passed

default

true

checkGets?: boolean

Whether or not to check localStorage when an object key is retrieved

default

true

mutateProxiedObject?: boolean

Whether to modify values on the proxied object or leave it as-is. Doesn't do anything if passed with partial for storeObject

default

true

partial?: boolean

Whether the stored object only contains/stores some of the keys on the serialized object. This is useful if you want an object to look at only some keys of a localStorage object without overwriting the other ones.

It's important to note that passing this option effectively enables key validation: any keys that were not passed are ignored and not passed to validate or modify

default

false

Methods

  • get(key: string): null | string
  • Called whenever a key should be retrieved

    Parameters

    • key: string

    Returns null | string

    The key's value

  • modify(value: O, action: "get" | "set"): O
  • Modify an object before setting it in localStorage or reading it. Called after validate. Any valiation should be done in validate and not here

    Parameters

    • value: O
    • action: "get" | "set"

    Returns O

    A potentially modified version of the object originally passed

  • parse(value: string): any
  • Function to parse object. Defaults to JSON.parse. Any validation should NOT be done here, but in the validate method

    default

    JSON.parse

    Parameters

    • value: string

    Returns any

  • set(key: string, value: string): void
  • Called whenever a key should be set

    default

    localStorage.setItem

    Parameters

    • key: string
    • value: string

      The value being set

    Returns void

  • stringify(value: any): string
  • Function to stringify object. Defaults to JSON.stringify. Any validation should NOT be done here, but in the validate method

    default

    JSON.stringify

    Parameters

    • value: any

    Returns string

  • validate(value: Readonly<any>, action: "get" | "set"): boolean | readonly [boolean] | readonly [false, Error]
  • Validate an object before setting it in localStorage or reading it. Can confirm/deny if the object is valid, along with an optional error message if it is invalid

    Parameters

    • value: Readonly<any>
    • action: "get" | "set"

    Returns boolean | readonly [boolean] | readonly [false, Error]

    A boolean to confirm validity or false and optionally an Error instance to deny validity

Generated using TypeDoc