Skip to content

Commit

Permalink
Implement the [es-shim API](es-shims/api).
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 16, 2015
1 parent e477e0e commit b1a52cc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
7 changes: 7 additions & 0 deletions implementation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

/* http://www.ecma-international.org/ecma-262/6.0/#sec-number.isnan */

module.exports = function isNaN(value) {
return value !== value;
};
21 changes: 9 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

var define = require('define-properties');

/* http://www.ecma-international.org/ecma-262/6.0/#sec-number.isnan */
var implementation = require('./implementation');
var getPolyfill = require('./polyfill');
var shim = require('./shim');

var numberIsNaN = function isNaN(value) {
return value !== value;
};
/* http://www.ecma-international.org/ecma-262/6.0/#sec-number.isnan */

define(numberIsNaN, {
shim: function shimNumberIsNaN() {
if (!Number.isNaN) {
define(Number, { isNaN: numberIsNaN });
}
return Number.isNaN || numberIsNaN;
}
define(implementation, {
getPolyfill: getPolyfill,
implementation: implementation,
shim: shim
});

module.exports = numberIsNaN;
module.exports = implementation;
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"license": "MIT",
"main": "index.js",
"scripts": {
"test": "npm run lint && npm run test:function && npm run test:shimmed",
"test": "npm run lint && es-shim-api && npm run tests-only",
"tests-only": "npm run test:function && npm run test:shimmed",
"test:function": "node test/index.js",
"test:shimmed": "node test/shimmed.js",
"coverage": "covert test/*.js",
Expand Down Expand Up @@ -42,7 +43,8 @@
"jscs": "^2.1.0",
"eslint": "^1.1.0",
"@ljharb/eslint-config": "^1.0.4",
"es5-shim": "^4.1.10"
"es5-shim": "^4.1.10",
"@es-shims/api": "^1.0.0"
},
"testling": {
"files": "test.js",
Expand Down
10 changes: 10 additions & 0 deletions polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

var implementation = require('./implementation');

module.exports = function getPolyfill() {
if (Number.isNaN && Number.isNaN(NaN) && !Number.isNaN('a')) {
return Number.isNaN;
}
return implementation;
};
12 changes: 12 additions & 0 deletions shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var define = require('define-properties');
var getPolyfill = require('./polyfill');

/* http://www.ecma-international.org/ecma-262/6.0/#sec-number.isnan */

module.exports = function shimNumberIsNaN() {
var polyfill = getPolyfill();
define(Number, { isNaN: polyfill }, { isNaN: function () { return Number.isNaN !== polyfill; } });
return polyfill;
};

0 comments on commit b1a52cc

Please sign in to comment.