File

projects/wms-framework/src/lib/baseframework/KeyValue.ts

Description

Stores a Key-Value pair in an array-like object.

Extends

Array

Index

Methods
Accessors

Constructor

constructor(key?: K, value?: V)

Creates an instance of KeyValue.

Parameters :
Name Type Optional
key K Yes
value V Yes

Methods

Static pair
pair(key?: TKey, value?: TValue)
Type parameters :
  • TKey
  • TValue

Returns a new instance of KeyValue, ready to be used as a regular array.

Parameters :
Name Type Optional
key TKey Yes
value TValue Yes

Accessors

Key
getKey()

Gets the key of this KeyValue pair.

Returns : K
Value
getValue()

Gets the value of this KeyValue pair.

Returns : V
export class KeyValue<K, V> extends Array {
  /**
   * Creates an instance of `KeyValue`.
   *
   * @param {K} [key]
   * @param {V} [value]
   * @memberof KeyValue
   */
  constructor(key?: K, value?: V) {
    super();
    this[0] = key;
    this[1] = value;
  }

  /**
   * Gets the key of this `KeyValue` pair.
   *
   * @readonly
   * @type {K}
   * @memberof KeyValue
   * @wIgnore
   */
  // eslint-disable-next-line @typescript-eslint/naming-convention
  get Key(): K {
    return this[0];
  }

  /**
   * Gets the value of this `KeyValue` pair.
   *
   * @readonly
   * @type {V}
   * @memberof KeyValue
   * @wIgnore
   */
  // eslint-disable-next-line @typescript-eslint/naming-convention
  get Value(): V {
    return this[1];
  }

  /**
   * Returns a new instance of `KeyValue`, ready to be used as a regular array.
   *
   * @static
   * @template TKey
   * @template TValue
   * @param {TKey} [key]
   * @param {TValue} [value]
   * @return {*}  {[TKey, TValue]}
   * @memberof KeyValue
   */
  static pair<TKey, TValue>(key?: TKey, value?: TValue): [TKey, TValue] {
    return new KeyValue(key, value) as any;
  }
}

result-matching ""

    No results matching ""