Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding branch for NaN, along with tests

  • Loading branch information...
commit 1963751b1b6b7adfc7489c05e295e9cdf7c0d7ad 1 parent d927409
Dominic Barnes dominicbarnes authored
Showing with 21 additions and 0 deletions.
  1. +14 −0 index.js
  2. +7 −0 test/tests.js
14 index.js
View
@@ -22,7 +22,21 @@ module.exports = function(val){
if (val === null) return 'null';
if (val === undefined) return 'undefined';
+ if (isNaN(val)) return 'nan';
if (val && val.nodeType === 1) return 'element';
return typeof val.valueOf();
};
+
+
+/**
+ * Tests whether the input `val` is `NaN`
+ *
+ * @param {Mixed} val
+ * @return {Boolean}
+ * @api private
+ */
+
+function isNaN(val) {
+ return typeof val === "number" && val !== +val;
+}
7 test/tests.js
View
@@ -10,7 +10,14 @@ describe('type', function(){
it('should match numbers', function(){
assert('number' === type(12));
+ assert('number' === type(1.0));
+ assert('number' === type(-5));
assert('number' === type(new Number(123)));
+ assert('number' === type(Infinity));
+ });
+
+ it('should match NaN', function () {
+ assert('nan' === type(NaN));
});
it('should match strings', function(){
Please sign in to comment.
Something went wrong with that request. Please try again.