Skip to content
This repository has been archived by the owner on May 22, 2019. It is now read-only.

Commit

Permalink
tightest version so far
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDarcyMurphy committed Sep 24, 2013
1 parent 70abb36 commit 9849f29
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/is.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@

// OBJECTS

/**
* Is the subject a plain Object?
*
* @method plainObject
* @param {Object} subject, required
*/
plainObject: function(x) {
if (!x || is.array(x) || is.bool(x) || is.date(x) || is.func(x) || is.number(x) || is.str(x))
return false
return !(typeof x == 'number' && isNaN(x))
},

/**
* Is the subject an array?
*
Expand Down
37 changes: 37 additions & 0 deletions test/plainObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var assert = require('assert')
var is = require('../lib/is')
var fn = function(){}

var future = new Date('04/16/9999')
var today = new Date()
var past = new Date('04/16/1982')

describe('plainObject', function(){

it('works', function(){
assert.equal(false, is.plainObject(fn), 'fn is wrong')
assert.equal(false, is.plainObject(new Date()), 'new Date() is wrong')
assert.equal(false, is.plainObject(undefined), 'undefined is wrong')
assert.equal(false, is.plainObject(NaN), 'NaN is wrong')
assert.equal(false, is.plainObject(null), 'null is wrong')
assert.equal(false, is.plainObject(true), 'true is wrong')
assert.equal(false, is.plainObject(false), 'false is wrong')
assert.equal(true , is.plainObject({}), '{} is wrong')
assert.equal(false, is.plainObject([]), '[] is wrong')
assert.equal(false, is.plainObject(""), '"" is wrong')
assert.equal(false, is.plainObject(" "), '" " is wrong')
assert.equal(false, is.plainObject("asdf"), '"asdf" is wrong')
assert.equal(false, is.plainObject("1.23"), '"1.23" is wrong')
assert.equal(false, is.plainObject("-42"), '"-42" is wrong')
assert.equal(false, is.plainObject("-42.01"), '"-42.01" is wrong')
assert.equal(false, is.plainObject("-1"), '"-1" is wrong')
assert.equal(false, is.plainObject("0"), '"0" is wrong')
assert.equal(false, is.plainObject("666"), '"666" is wrong')
assert.equal(false, is.plainObject(1.23), '1.23 is wrong')
assert.equal(false, is.plainObject(-42), '-42 is wrong')
assert.equal(false, is.plainObject(-1), '-1 is wrong')
assert.equal(false, is.plainObject(0), '0 is wrong')
assert.equal(false, is.plainObject(666), '666 is wrong')
})

})

0 comments on commit 9849f29

Please sign in to comment.