projects/wms-framework/src/lib/baseframework/KeyValue.ts
Stores a Key-Value pair in an array-like object.
Array
Methods |
|
Accessors |
constructor(key?: K, value?: V)
|
|||||||||
Creates an instance of
Parameters :
|
Static pair | |||||||||
pair(key?: TKey, value?: TValue)
|
|||||||||
Type parameters :
|
|||||||||
Returns a new instance of
Parameters :
|
Key |
getKey()
|
Gets the key of this
Returns :
K
|
Value |
getValue()
|
Gets the value of this
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;
}
}