UNPKG

@aurigma/design-atoms-model

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

99 lines 2.73 kB
/** * Represents a dictionary which key supports comparison through equals() method */ export class EquatableKeyDictionary { constructor(entries) { this._dictionary = new Map(entries); } /** * Indicates whether an element with the key equal to given {@link keyValue} exists or not. */ hasEqual(keyValue) { const { hasKey } = this.tryGetKeyEqualTo(keyValue); return hasKey; } /** * Tries to find a key in the dictionary that is equal to given {@link keyValue}. * * Returns: * * hasKey - indicates whether such a key was found in the dictionary; * * key - contains key that is equal to {@link keyValue} or null if such key was not found. */ tryGetKeyEqualTo(keyValue) { if (this.has(keyValue)) { return { hasKey: true, key: keyValue }; } for (let key of this.keys()) { if (key.equals(keyValue)) { return { hasKey: true, key: key }; } } return { hasKey: false, key: null }; } /** * Tries to find a value in the dictionary corresponding to the key equal to given {@link keyValue}. * * Returns: * * hasValue - indicates whether the value with such key was found; * * value - contains value with the key equal to {@link keyValue} or null if such key was not found. */ tryGetValueOf(keyValue) { let { hasKey, key } = this.tryGetKeyEqualTo(keyValue); return { hasValue: hasKey, value: key != null ? this.get(key) : null }; } clear() { this._dictionary.clear(); } delete(key) { return this._dictionary.delete(key); } forEach(callbackfn, thisArg) { this._dictionary.forEach(callbackfn, thisArg); } get(key) { return this._dictionary.get(key); } has(key) { return this._dictionary.has(key); } set(key, value) { this._dictionary.set(key, value); return this; } get size() { return this._dictionary.size; } entries() { return this._dictionary.entries(); } keys() { return this._dictionary.keys(); } values() { return this._dictionary.values(); } *[Symbol.iterator]() { for (let item of this._dictionary) { yield item; } } } //# sourceMappingURL=EquatableKeyDictionary.js.map