Comparing version 1.0.2 to 1.1.0
74
dict.js
"use strict"; | ||
function mangle(key) { | ||
return "~" + key; | ||
return "~" + key; | ||
} | ||
function methods(obj, methodHash) { | ||
for (var methodName in methodHash) { | ||
Object.defineProperty(obj, methodName, { | ||
value: methodHash[methodName], | ||
configurable: true, | ||
writable: true | ||
}); | ||
} | ||
for (var methodName in methodHash) { | ||
Object.defineProperty(obj, methodName, { | ||
value: methodHash[methodName], | ||
configurable: true, | ||
writable: true | ||
}); | ||
} | ||
} | ||
function assertString(key) { | ||
if (typeof key !== "string") { | ||
throw new TypeError("key must be a string."); | ||
} | ||
if (typeof key !== "string") { | ||
throw new TypeError("key must be a string."); | ||
} | ||
} | ||
module.exports = function () { | ||
var store = Object.create(null); | ||
module.exports = function (initializer) { | ||
var store = Object.create(null); | ||
var dict = {}; | ||
methods(dict, { | ||
get: function (key, defaultValue) { | ||
assertString(key); | ||
var mangled = mangle(key); | ||
return mangled in store ? store[mangled] : defaultValue; | ||
}, | ||
set: function (key, value) { | ||
assertString(key); | ||
store[mangle(key)] = value; | ||
}, | ||
has: function (key) { | ||
assertString(key); | ||
return mangle(key) in store; | ||
}, | ||
delete: function (key) { | ||
assertString(key); | ||
delete store[mangle(key)]; | ||
} | ||
}); | ||
var dict = {}; | ||
methods(dict, { | ||
get: function (key, defaultValue) { | ||
assertString(key); | ||
var mangled = mangle(key); | ||
return mangled in store ? store[mangled] : defaultValue; | ||
}, | ||
set: function (key, value) { | ||
assertString(key); | ||
store[mangle(key)] = value; | ||
}, | ||
has: function (key) { | ||
assertString(key); | ||
return mangle(key) in store; | ||
}, | ||
delete: function (key) { | ||
assertString(key); | ||
delete store[mangle(key)]; | ||
} | ||
}); | ||
return dict; | ||
if (typeof initializer === "object" && initializer !== null) { | ||
Object.keys(initializer).forEach(function (key) { | ||
dict.set(key, initializer[key]); | ||
}); | ||
} | ||
return dict; | ||
}; |
@@ -0,0 +0,0 @@ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"author": "Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com)", | ||
@@ -17,3 +17,3 @@ "license": "WTFPL", | ||
"type": "git", | ||
"url": "https://github.com/domenic/dict" | ||
"url": "git://github.com/domenic/dict.git" | ||
}, | ||
@@ -26,14 +26,10 @@ "bugs": { | ||
"test": "mocha", | ||
"lint": "jshint --show-non-errors dict.js" | ||
"lint": "jshint dict.js" | ||
}, | ||
"engines": { | ||
"node": "*" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"coffee-script": "1", | ||
"mocha": "1", | ||
"chai": "1", | ||
"jshint": "~0.7.1" | ||
"chai": ">= 1.3.0", | ||
"coffee-script": ">= 1.4.0", | ||
"jshint": ">= 0.9.1", | ||
"mocha": ">= 1.6.0" | ||
} | ||
} |
@@ -0,0 +0,0 @@ An easy but safe string-keyed store |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5301
47
1