From fe5b55a32f4cf95e23a888df76b613a5bd2966f6 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Fri, 11 Aug 2017 13:01:38 +0200 Subject: [PATCH] feat: add Object.isFiniteNumber util --- object/index.js | 1 + object/is-finite-number.js | 7 +++++++ test/object/is-finite-number.js | 15 +++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 object/is-finite-number.js create mode 100644 test/object/is-finite-number.js diff --git a/object/index.js b/object/index.js index a27652d6..480757f4 100644 --- a/object/index.js +++ b/object/index.js @@ -27,6 +27,7 @@ module.exports = { isCopy: require("./is-copy"), isCopyDeep: require("./is-copy-deep"), isEmpty: require("./is-empty"), + isFiniteNumber: require("./is-finite-number"), isNumberValue: require("./is-number-value"), isObject: require("./is-object"), isPlainObject: require("./is-plain-object"), diff --git a/object/is-finite-number.js b/object/is-finite-number.js new file mode 100644 index 00000000..78ed6692 --- /dev/null +++ b/object/is-finite-number.js @@ -0,0 +1,7 @@ +"use strict"; + +var isNumber = require("./is-number-value"); + +module.exports = function (value) { + return isNumber(value) && isFinite(value); +}; diff --git a/test/object/is-finite-number.js b/test/object/is-finite-number.js new file mode 100644 index 00000000..91434391 --- /dev/null +++ b/test/object/is-finite-number.js @@ -0,0 +1,15 @@ +"use strict"; + +module.exports = function (t, a) { + a(t(undefined), false, "Undefined"); + a(t(null), false, "Null"); + a(t(0), true, "Zero"); + a(t(NaN), false, "NaN"); + a(t(Infinity), false, "Infinity"); + a(t(12), true, "Number"); + a(t(false), true, "Boolean"); + a(t(new Date()), true, "Date"); + a(t(new Number(2)), true, "Number object"); + a(t("asdfaf"), false, "String"); + a(t(""), true, "Empty String"); +};