Skip to content

Commit

Permalink
Number method checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanth committed Nov 10, 2014
1 parent b714773 commit a636c69
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Expand Up @@ -98,6 +98,34 @@ if (enable.String.prototype.contains) {
console.log('supports `String.prototype.contains`');
}

if (Number.isFinite) {
console.log('supports `Number.isFinite`');
}

if (Number.isInteger) {
console.log('supports `Number.isInteger`');
}

if (Number.isSafeInteger) {
console.log('supports `Number.isSafeInteger`');
}

if (Number.isNaN) {
console.log('supports `Number.isNaN`');
}

if (Number.EPSILON) {
console.log('supports `Number.EPSILON`');
}

if (Number.MIN_SAFE_INTEGER) {
console.log('supports `Number.MIN_SAFE_INTEGER`');
}

if (Number.MAX_SAFE_INTEGER) {
console.log('supports `Number.MAX_SAFE_INTEGER`');
}

```

## Test
Expand Down
14 changes: 14 additions & 0 deletions index.js
Expand Up @@ -20,6 +20,10 @@ function isFunction(attr) {
return typeof attr === 'function';
}

function isNumber(attr) {
return typeof attr === 'number';
}

/**
* Module dependencies.
*/
Expand Down Expand Up @@ -71,3 +75,13 @@ exports.String = {
contains: isFunction(String.prototype.contains)
}
};

exports.Number = {
isFinite: isFunction(Number.isFinite),
isInteger: isFunction(Number.isInteger),
isSafeInteger: isFunction(Number.isSafeInteger),
isNaN: isFunction(Number.isNaN),
EPSILON: isNumber(Number.EPSILON),
MIN_SAFE_INTEGER: isNumber(Number.MIN_SAFE_INTEGER),
MAX_SAFE_INTEGER: isNumber(Number.MAX_SAFE_INTEGER)
};
70 changes: 70 additions & 0 deletions test/enable.test.js
Expand Up @@ -157,4 +157,74 @@ describe('enable.test.js', function () {
}
});

it("should detect Number.isFinite", function(){
enable.Number.isFinite.should.be.a.Boolean;
if (process.version.indexOf('v0.10.') === 0) {
enable.Number.isFinite.should.equal(true);
}
if (process.version.indexOf('v0.11.') === 0) {
enable.Number.isFinite.should.equal(true);
}
});

it("should detect Number.isInteger", function(){
enable.Number.isInteger.should.be.a.Boolean;
if (process.version.indexOf('v0.10.') === 0) {
enable.Number.isInteger.should.equal(false);
}
if (process.version.indexOf('v0.11.') === 0) {
enable.Number.isInteger.should.equal(true);
}
});

it("should detect Number.isSafeInteger", function(){
enable.Number.isSafeInteger.should.be.a.Boolean;
if (process.version.indexOf('v0.10.') === 0) {
enable.Number.isSafeInteger.should.equal(false);
}
if (process.version.indexOf('v0.11.') === 0) {
enable.Number.isSafeInteger.should.equal(true);
}
});

it("should detect Number.isNaN", function(){
enable.Number.isNaN.should.be.a.Boolean;
if (process.version.indexOf('v0.10.') === 0) {
enable.Number.isNaN.should.equal(true);
}
if (process.version.indexOf('v0.11.') === 0) {
enable.Number.isNaN.should.equal(true);
}
});

it("should detect Number.EPSILON", function(){
enable.Number.EPSILON.should.be.a.Boolean;
if (process.version.indexOf('v0.10.') === 0) {
enable.Number.EPSILON.should.equal(false);
}
if (process.version.indexOf('v0.11.') === 0) {
enable.Number.EPSILON.should.equal(true);
}
});

it("should detect Number.MIN_SAFE_INTEGER", function(){
enable.Number.MIN_SAFE_INTEGER.should.be.a.Boolean;
if (process.version.indexOf('v0.10.') === 0) {
enable.Number.MIN_SAFE_INTEGER.should.equal(false);
}
if (process.version.indexOf('v0.11.') === 0) {
enable.Number.MIN_SAFE_INTEGER.should.equal(true);
}
});

it("should detect Number.MAX_SAFE_INTEGER", function(){
enable.Number.MAX_SAFE_INTEGER.should.be.a.Boolean;
if (process.version.indexOf('v0.10.') === 0) {
enable.Number.MAX_SAFE_INTEGER.should.equal(false);
}
if (process.version.indexOf('v0.11.') === 0) {
enable.Number.MAX_SAFE_INTEGER.should.equal(true);
}
});

});

0 comments on commit a636c69

Please sign in to comment.