UNPKG

data-validator-js

Version:
76 lines (75 loc) 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var HashMap = /** @class */ (function () { function HashMap() { this.data = {}; } HashMap.prototype.add = function (key, value) { if (!this.containsKey(key)) { this.data[key] = value; return true; } return false; }; HashMap.prototype.upsert = function (key, value) { this.data[key] = value; }; HashMap.prototype.clear = function () { this.data = {}; }; HashMap.prototype.containsKey = function (key) { return this.data.hasOwnProperty(key); }; HashMap.prototype.containsValue = function (value) { for (var k in this.data) { if (this.data[k] === value) { return true; } } return false; }; HashMap.prototype.count = function () { return Object.keys(this.data).length; }; HashMap.prototype.getValue = function (key) { if (this.containsKey(key)) { return this.data[key]; } return false; }; HashMap.prototype.getKeys = function () { return Object.keys(this.data); }; HashMap.prototype.getValues = function () { var values = []; for (var k in this.data) { if (this.data.hasOwnProperty(k)) { values.push(this.data[k]); } } return values; }; HashMap.prototype.remove = function (key) { if (!this.containsKey(key)) { return false; } return delete this.data[key]; }; HashMap.prototype.update = function (key, value) { if (this.containsKey(key)) { this.data[key] = value; return true; } return false; }; /** * Returns the internal object. * The current implementation returns data: { the actual key value pairs} as hashmap. * Wherever there is a need to pass only the key value pairs without data being appended along with it, return this.data. */ HashMap.prototype.getInternalObject = function () { return this.data; }; return HashMap; }()); exports.default = HashMap;