Skip to content

Commit

Permalink
feat: Object.ensurePlainFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Mar 16, 2018
1 parent c4e07e6 commit 2682be6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions object/ensure-plain-function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

var safeToString = require("../safe-to-string")
, isPlainFunction = require("./is-plain-function");

module.exports = function (value) {
if (!isPlainFunction(value)) {
throw new TypeError(safeToString(value) + " is not a plain function");
}
return value;
};
1 change: 1 addition & 0 deletions object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
ensureInteger: require("./ensure-integer"),
ensureNaturalNumber: require("./ensure-natural-number"),
ensureNaturalNumberValue: require("./ensure-natural-number-value"),
ensurePlainFunction: require("./ensure-plain-function"),
ensurePromise: require("./ensure-promise"),
eq: require("./eq"),
every: require("./every"),
Expand Down
14 changes: 14 additions & 0 deletions test/object/ensure-plain-function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

module.exports = function (t, a) {
// Just sanity checks, as logic is tested at isPlainFunction
var fn = function () {};
a(t(fn), fn, "Function");
a.throws(
function () {
t({});
},
TypeError,
"Error"
);
};

0 comments on commit 2682be6

Please sign in to comment.