Options
All
  • Public
  • Public/Protected
  • All
Menu

LocalStorageLRU Copyright 2022 SageMath, Inc. Licensed under the Apache License, Version 2.0

Hierarchy

  • LocalStorageLRU

Index

Constructors

Properties

delimiter: string
deserializer: ((ser: string) => any)

Type declaration

    • (ser: string): any
    • Parameters

      • ser: string

      Returns any

isCandidate?: ((key: string, recent: string[]) => boolean)

Type declaration

    • (key: string, recent: string[]): boolean
    • Parameters

      • key: string
      • recent: string[]

      Returns boolean

ls: Storage
maxSize: number
parseExistingJSON: boolean
recentKey: string
serializer: ((data: any) => string)

Type declaration

    • (data: any): string
    • Parameters

      • data: any

      Returns string

typePrefixDelimiter: string
typePrefixes: TypePrefixes

Methods

  • [iterator](): IterableIterator<[string, string | object]>
  • Usage:

    const entries: [string, any][] = [];
    for (const [k, v] of storage) {
    entries.push([k, v]);
    }
    entries; // equals: [[ 'key1', '1' ], [ 'key2', '2' ], ... ]

    Returns IterableIterator<[string, string | object]>

    iterator over key/value pairs

  • checkPrefixes(): void
  • clear(): boolean
  • calls localStorage.clear() and returns true if it worked – otherwise false.

    Returns boolean

  • delete(key: string): void
  • Deletes key from local storage

    Throws an error only if you try to delete the reserved key to record recent entries.

    Parameters

    • key: string

    Returns void

  • deleteData(key: string, pathParam: string | string[]): any
  • Delete a value or nested object from within a nested object at the given path. It returns the deleted object.

    Parameters

    • key: string
    • pathParam: string | string[]

    Returns any

  • deletePrefix(prefix: string): void
  • deleteUsage(key: string): void
  • deserialize(ser: null | string): any
  • Each value in localStorage is a string. For specific prefixes, this deserializes the value. As a fallback, it optionally tries to use JSON.parse. If everything fails, the plain string value is returned.

    Parameters

    • ser: null | string

    Returns any

  • get(key: string): null | string | object
  • getData(key: string, pathParam: string | string[]): any
  • Get data from a nested object

    Parameters

    • key: string
    • pathParam: string | string[]

    Returns any

  • getLocalStorage(): Storage
  • getMaxSize(): number
  • getRecent(): string[]
  • Keys of last recently used entries. The most recent one comes first!

    Returns string[]

  • getRecentKey(): string
  • has(key: string): boolean
  • initLocalStorage(props?: Props): Storage
  • keys(sorted?: boolean): string[]
  • Return all keys in local storage, optionally sorted.

    Parameters

    • sorted: boolean = false

    Returns string[]

  • localStorageIsAvailable(): boolean
  • recordUsage(key: string): void
  • avoid trimming more useful entries, we keep an array of recently modified keys

    Parameters

    • key: string

    Returns void

  • serialize(val: unknown): string
  • specific types are serialized with a prefix, while plain strings are stored as they are.

    Parameters

    • val: unknown

    Returns string

  • set(key: string, val: unknown): void
  • Wrapper around localStorage, so we can safely touch it without raising an exception if it is banned (like in some browser modes) or doesn't exist.

    Parameters

    • key: string
    • val: unknown

    Returns void

  • setData(key: string, pathParam: string | string[], value: any): void
  • Set data in nested objects and merge with existing values

    Parameters

    • key: string
    • pathParam: string | string[]
    • value: any

    Returns void

  • size(): number
  • number of items stored in the local storage – not counting the "recent key" itself

    Returns number

  • trim(key: string, val: string): boolean
  • Trim the local storage in case it is too big. In case there is an error upon storing a value, we assume we hit the quota limit. Try a couple of times to delete some entries and saving the key/value pair.

    Parameters

    • key: string
    • val: string

    Returns boolean

  • trimOldEntries(): void
  • testLocalStorage(ls: { getItem: any; removeItem: any; setItem: any }): boolean
  • Returns true, if we can store something in local storage at all. This is used for testing and during initialization.

    static

    Parameters

    • ls: { getItem: any; removeItem: any; setItem: any }
      • getItem:function
        • getItem(key: string): null | string
      • removeItem:function
        • removeItem(k: string): void
      • setItem:function
        • setItem(k: string, v: string): void

    Returns boolean

Generated using TypeDoc