gis-tools-ts - v0.6.0
    Preparing search index...

    Class KV<V>

    Key-Value Store

    A local key-value store

    import { KV } from 'gis-tools-ts';

    interface Data { name: string };

    const kv = new KV<Data>();
    // set a key
    kv.set(1n, { name: 'test' });
    // get a key
    const { name } = kv.get(1n); // { name: 'test' }
    // check if a key exists
    kv.has(1n); // true
    // get length of the store
    console.log(kv.length); // 1

    // iterate over the store
    for await (const value of kv) console.log(value);

    // clear the store
    kv.close();

    Type Parameters

    • V = Properties | Value

    Implements

    Index

    Accessors

    • get length(): number

      Returns number

      • the length of the map

    Methods

    • iterate through the values

      Returns AsyncGenerator<V>

      an iterator

    • Closes the store

      Returns void

    • Gets the list of values associated with a key

      Parameters

      • key: number | bigint

        the key

      Returns undefined | V

      the list of values if the map contains values for the key

    • Check if the key exists

      Parameters

      • key: number | bigint

        the key

      Returns boolean

      true if the key exists

    • Adds a value to the list of values associated with a key

      Parameters

      • key: number | bigint

        the key

      • value: V

        the value to store

      Returns void

    • iterate through the values

      Returns AsyncGenerator<V>

      an iterator