diff options
Diffstat (limited to 'lib/utils.js')
-rw-r--r-- | lib/utils.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/utils.js b/lib/utils.js index 4d3d60f6..27b79753 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -244,3 +244,23 @@ function makePredicate(words) { } return new Function("str", f); }; + +function Dictionary() { + this._values = Object.create(null); +}; +Dictionary.prototype = { + set: function(key, val) { return this._values["$" + key] = val, this }, + get: function(key) { return this._values["$" + key] }, + del: function(key) { return delete this._values["$" + key], this }, + has: function(key) { return ("$" + key) in this._values }, + each: function(f) { + for (var i in this._values) + f(this._values[i], i.substr(1)); + }, + map: function(f) { + var ret = []; + for (var i in this._values) + ret.push(f(this._values[i], i.substr(1))); + return ret; + } +}; |