Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon de Rijke committed May 20, 2014
0 parents commit d56251c
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
node_modules/
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
node_modules/
test/
.travis.yml
testling.html
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: node_js
node_js:
- "0.11"
- "0.10"
- "0.9"
- "0.8"
- "0.6"
- "0.4"
before_install:
- '[ "${TRAVIS_NODE_VERSION}" == "0.6" ] || npm install -g npm@~1.4.6'
matrix:
fast_finish: true
allow_failures:
- node_js: "0.11"
- node_js: "0.9"
- node_js: "0.6"
- node_js: "0.4"
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2014 Leon de Rijke

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Relevant links

* https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isnan
* http://wiki.ecmascript.org/doku.php?id=harmony:number.isnan
* http://ariya.ofilabs.com/2014/05/the-curious-case-of-javascript-nan.html
* http://www.2ality.com/2012/02/nan-infinity.html
30 changes: 30 additions & 0 deletions isnan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if (!Number.isNaN) {
(function(global) {
var defineProperty = (function() {
// IE 8 only supports `Object.defineProperty` on DOM elements
try {
var object = {};
var $defineProperty = Object.defineProperty;
var result = $defineProperty(object, object, object) && $defineProperty;
} catch(error) {}
return result;
}());

var globalIsNaN = global.isNaN;

// Source: http://wiki.ecmascript.org/doku.php?id=harmony:number.isnan
var isNaN = function(value) {
return typeof value === 'number' && globalisNaN(value);
};

if (defineProperty) {
defineProperty(Number, 'isNaN', {
'value': isNaN,
'configurable': true,
'writable': true
});
} else {
Number.isNaN = isNaN;
}
}(this));
}
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "Number.isNaN",
"version": "0.0.0",
"description": "A `Number.isNaN` polyfill, based on the ECMAScript 6 specification.",
"author": "Leon de Rijke",
"license": "MIT",
"keywords": [
"number",
"nan",
"es6",
"ecmascript",
"polyfill"
],
"homepage": "https://github.com/leonderijke/Number.isNaN",
"bugs": {
"url": "https://github.com/leonderijke/Number.isNaN/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/leonderijke/Number.isNaN.git"
},
"main": "isnan.js",
"scripts": {
"test": "mocha test/*.js"
},
"testling": {
"html": "testling.html",
"browsers": [
"iexplore/9.0..latest",
"firefox/10.0",
"firefox/17.0",
"firefox/22.0..latest",
"firefox/nightly",
"chrome/25.0..latest",
"chrome/canary",
"safari/5.0.5..latest",
"ipad/6.0..latest",
"iphone/6.0..latest",
"opera/12.0..latest",
"android-browser/4.2..latest"
]
},
"devDependencies": {
"chai": "^1.9.1",
"es5-shim": "^3.3.2",
"mocha": "^1.19.0"
}
}
42 changes: 42 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var expect = require('chai').expect;

require('../');

// Tests taken from the es6-shim test cases
// Source: https://github.com/paulmillr/es6-shim/blob/master/test/number.js
describe('Number', function() {
var integers = [5295, -5295, -9007199254740991, 9007199254740991, 0, -0];
var nonIntegers = [-9007199254741992, 9007199254741992, 5.9];
var nonNumbers = [undefined, true, null, {}, [], 'str'];
var expectToBeOk = function(item) {
expect(item).to.be.ok;
};
var expectToNotBeOk = function(item) {
expect(item).to.not.be.ok;
};

describe('Number.isNaN()', function() {
it('should be truthy only on NaN', function() {
integers.concat(nonIntegers).map(Number.isNaN).forEach(expectToNotBeOk);
nonNumbers.map(Number.isNaN).forEach(expectToNotBeOk);
expect(Number.isNaN(NaN)).to.be.ok;
expect(Number.isNaN(0/0)).to.be.ok;
expect(Number.isNaN(Number('NaN'))).to.be.ok;
expect(Number.isNaN(4)).to.not.be.ok;
expect(Number.isNaN(4.5)).to.not.be.ok;
expect(Number.isNaN('hi')).to.not.be.ok;
expect(Number.isNaN('1.3')).to.not.be.ok;
expect(Number.isNaN('51')).to.not.be.ok;
expect(Number.isNaN(0)).to.not.be.ok;
expect(Number.isNaN(-0)).to.not.be.ok;
expect(Number.isNaN({valueOf: function() { return 3; }})).to.not.be.ok;
expect(Number.isNaN({valueOf: function() { return 0/0; }})).to.not.be.ok;
expect(Number.isNaN({valueOf: function() { throw 17; } })).to.not.be.ok;
expect(Number.isNaN({toString: function() { throw 17; } })).to.not.be.ok;
expect(Number.isNaN({
valueOf: function() { throw 17; },
toString: function() { throw 42; }
})).to.not.be.ok;
});
});
});
17 changes: 17 additions & 0 deletions testling.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Number.isNaN tests</title>
<script src="node_modules/es5-shim/es5-sham.js"></script>
<script src="node_modules/mocha/mocha.js"></script>
<!-- note that chai uses Object.create() so needs es5-sham to be loaded -->
<script src="node_modules/chai/chai.js"></script>
<script>chai.config.includeStack=true; window.expect=chai.expect; window.assert=chai.assert; mocha.setup({ui:'bdd',reporter:'tap'});</script>
<script src="test/test.js"></script>
<script>mocha.run()</script>
</head>
<body>
<div id="mocha"></div>
</body>
</html>

0 comments on commit d56251c

Please sign in to comment.