prototypes
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -11,3 +11,3 @@ 'use strict'; | ||
require('./lib/string.js'); | ||
require('./lib/math.js'); | ||
var mathLib = require('./lib/math.js'); | ||
var objectLib = require('./lib/object.js'); | ||
@@ -17,2 +17,4 @@ | ||
exports.overwriteWith(objectLib); | ||
exports.overwriteWith(mathLib); | ||
@@ -55,2 +55,28 @@ 'use strict'; | ||
/** | ||
* Find out if the argument is a number. | ||
* http://stackoverflow.com/a/1830844/978796 | ||
*/ | ||
exports.isNumber = function(value) | ||
{ | ||
return !isNaN(parseFloat(value)) && isFinite(value); | ||
}; | ||
/** | ||
* Test the function isNumber(). | ||
*/ | ||
function testIsNumber(callback) | ||
{ | ||
testing.assert(exports.isNumber(5), '5 should be number', callback); | ||
testing.assert(exports.isNumber(0), '0 should be number', callback); | ||
testing.assert(exports.isNumber(-1), '-1 should be number', callback); | ||
testing.assert(exports.isNumber(1.1), '1.1 should be number', callback); | ||
testing.assert(exports.isNumber(8e5), '8e5 should be number', callback); | ||
testing.assert(!exports.isNumber(NaN), 'NaN should not be number', callback); | ||
testing.assert(!exports.isNumber('a'), 'a should not be number', callback); | ||
testing.assert(!exports.isNumber(' '), 'space should not be number', callback); | ||
testing.assert(!exports.isNumber('\t\t'), 'tabs should not be number', callback); | ||
testing.success(callback); | ||
} | ||
/** | ||
* Compute the logarithm in base 10. | ||
@@ -98,7 +124,8 @@ */ | ||
{ | ||
testing.run({ | ||
parseInt: testParseInt, | ||
log10: testLog10, | ||
toRad: testToRad, | ||
}, callback); | ||
testing.run([ | ||
testParseInt, | ||
testIsNumber, | ||
testLog10, | ||
testToRad, | ||
], callback); | ||
}; | ||
@@ -105,0 +132,0 @@ |
{ | ||
"name": "prototypes", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Some common prototypes for node.js: string.startsWith(), object.countProperties() and more. Functions are added using Object.defineProperty() to avoid polluting new objects.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/alexfernandez/prototypes", |
@@ -165,4 +165,4 @@ [![Build Status](https://secure.travis-ci.org/alexfernandez/prototypes.png)](http://travis-ci.org/alexfernandez/prototypes) | ||
There are math functions in `Math`, in `Number.prototype` and even as globals, | ||
e.g. `parseInt()`. | ||
There are math functions in `Math`, in `Number.prototype`, exported `isNumber` | ||
and even as globals, e.g. `parseInt()`. | ||
@@ -188,2 +188,15 @@ ### parseInt(string) | ||
### isNumber(value) | ||
The function isNumber() is based on | ||
[this StackOverflow answer](http://stackoverflow.com/a/1830844/978796): | ||
it checks if the parameter is a number. | ||
Examples: | ||
var prototypes = require('prototypes'); | ||
prototypes.isNumber(5); | ||
\=> true | ||
prototypes.isNumber('hi'); | ||
\=> false | ||
### Math.log10(number) | ||
@@ -190,0 +203,0 @@ |
23571
614
235