missing-keys
Advanced tools
Comparing version 0.1.3 to 0.1.4
64
index.js
/*global require, module*/ | ||
/*! | ||
* key-validator <https://github.com/tobiasoberrauch/key-validator> | ||
* missing-keys <https://github.com/tobiasoberrauch/missing-keys> | ||
* | ||
@@ -11,30 +11,40 @@ * Copyright (c) 2015, Tobias Oberrauch. | ||
/** | ||
* | ||
* @param object | ||
* @param expectedKeys | ||
* @returns {Array.<T>|*} | ||
*/ | ||
function missingKeys(object, expectedKeys) { | ||
var actualKeys = Object.keys(object); | ||
return expectedKeys.filter(function (expectedKey) { | ||
return actualKeys.indexOf(expectedKey) === -1; | ||
}); | ||
} | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
module.exports = factory(); | ||
} | ||
else if (typeof window === "object") { | ||
window.missingKeys = factory(); | ||
} | ||
}(function () { | ||
/** | ||
* | ||
* @param {object} object | ||
* @param {string|object} expectedKeys | ||
* @returns {Array.<T>|*} | ||
*/ | ||
function missingKeys(object, expectedKeys) { | ||
expectedKeys = Object.prototype.toString.call(expectedKeys) === '[object Array]' ? expectedKeys : [expectedKeys]; | ||
var actualKeys = Object.keys(object); | ||
return expectedKeys.filter(function (expectedKey) { | ||
return actualKeys.indexOf(expectedKey) === -1; | ||
}); | ||
} | ||
/** | ||
* @type {missingKeys} | ||
*/ | ||
missingKeys.get = missingKeys; | ||
/** | ||
* @type {missingKeys} | ||
*/ | ||
missingKeys.get = missingKeys; | ||
/** | ||
* | ||
* @param object | ||
* @param expectedKeys | ||
* @returns {boolean} | ||
*/ | ||
missingKeys.has = function (object, expectedKeys) { | ||
return missingKeys(object, expectedKeys).length > 0; | ||
}; | ||
/** | ||
* | ||
* @param {object} object | ||
* @param {string|object} expectedKeys | ||
* @returns {boolean} | ||
*/ | ||
missingKeys.has = function (object, expectedKeys) { | ||
return missingKeys(object, expectedKeys).length > 0; | ||
}; | ||
module.exports = missingKeys; | ||
return missingKeys; | ||
})); |
{ | ||
"name": "missing-keys", | ||
"description": "Return missing keys if the given object hasn't all required keys.", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"homepage": "https://github.com/tobiasoberrauch/missing-keys", | ||
@@ -20,3 +20,5 @@ "author": "Tobias Oberrauch <tobias.oberrauch@grolba.com> (https://github.com/tobiasoberrauch)", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha", | ||
"publish": "npm publish", | ||
"browserify": "browserify index.js -o browser.js" | ||
}, | ||
@@ -23,0 +25,0 @@ "devDependencies": { |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality 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
43
3026
3
2
0