@omnia/fx-models
Version:
Provide Omnia Fx Models Stuffs.
43 lines (42 loc) • 1.25 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dictionary = void 0;
class Dictionary {
constructor(_bagData) {
this._bagData = _bagData;
this.getValue = (key) => {
let result = null;
if (key && this._bagData) {
result = this._bagData[key.toLowerCase()];
}
return result;
};
this.setValue = (key, value) => {
if (!this._bagData) {
this._bagData = {};
}
const lowerKey = key.toLowerCase();
this._bagData[lowerKey] = value;
};
this.getOrSetInitialValue = (key, initialValueFactory) => {
let value = this.getValue(key);
if (!value &&
initialValueFactory) {
if (!this._bagData) {
this._bagData = {};
}
value = initialValueFactory();
this.setValue(key, value);
}
return value;
};
}
get keys() {
let result = [];
if (this._bagData) {
result = Object.keys(this._bagData);
}
return result;
}
}
exports.Dictionary = Dictionary;