pax_global_header 0000666 0000000 0000000 00000000064 13171314227 0014513 g ustar 00root root 0000000 0000000 52 comment=0c6b15a88bc10cd47f67a09506399dfc9ddc075d
is-number-4.0.0/ 0000775 0000000 0000000 00000000000 13171314227 0013415 5 ustar 00root root 0000000 0000000 is-number-4.0.0/.editorconfig 0000664 0000000 0000000 00000000441 13171314227 0016071 0 ustar 00root root 0000000 0000000 # http://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[{**/{actual,fixtures,expected,templates}/**,*.md}]
trim_trailing_whitespace = false
insert_final_newline = false
is-number-4.0.0/.eslintrc.json 0000664 0000000 0000000 00000006775 13171314227 0016230 0 ustar 00root root 0000000 0000000 {
"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},
"globals": {
"document": false,
"navigator": false,
"window": false
},
"rules": {
"accessor-pairs": 2,
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-dangle": [2, "never"],
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"constructor-super": 2,
"curly": [2, "multi-line"],
"dot-location": [2, "property"],
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"indent": [2, 2, { "SwitchCase": 1 }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, { "before": true, "after": true }],
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"new-parens": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [2, "functions"],
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
"no-native-reassign": 0,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-proto": 0,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 0,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unreachable": 2,
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
"no-useless-call": 0,
"no-with": 2,
"one-var": [0, { "initialized": "never" }],
"operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": [0, "never"],
"quotes": [2, "single", "avoid-escape"],
"radix": 2,
"semi": [2, "always"],
"semi-spacing": [2, { "before": false, "after": true }],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, "never"],
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [2, "any"],
"yoda": [2, "never"]
}
}
is-number-4.0.0/.gitattributes 0000664 0000000 0000000 00000000177 13171314227 0016315 0 ustar 00root root 0000000 0000000 # Enforce Unix newlines
* text eol=lf
# binaries
*.ai binary
*.psd binary
*.jpg binary
*.gif binary
*.png binary
*.jpeg binary is-number-4.0.0/.gitignore 0000664 0000000 0000000 00000000446 13171314227 0015411 0 ustar 00root root 0000000 0000000 # always ignore files
*.DS_Store
.idea
*.sublime-*
# test related, or directories generated by tests
test/actual
actual
coverage
.nyc*
# npm
node_modules
npm-debug.log
# yarn
yarn.lock
yarn-error.log
# misc
_gh_pages
_draft
_drafts
bower_components
vendor
temp
tmp
TODO.md
package-lock.json is-number-4.0.0/.travis.yml 0000664 0000000 0000000 00000000204 13171314227 0015522 0 ustar 00root root 0000000 0000000 sudo: false
os:
- linux
- osx
language: node_js
node_js:
- node
- '8'
- '7'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
is-number-4.0.0/.verb.md 0000664 0000000 0000000 00000003161 13171314227 0014754 0 ustar 00root root 0000000 0000000 ## Usage
To understand some of the rationale behind the decisions made in this library (and to learn about some oddities of number evaluation in JavaScript), [see this gist][gist].
```js
var isNumber = require('{%= name %}');
```
### true
See the [tests](./test.js) for more examples.
```js
isNumber(5e3) //=> 'true'
isNumber(0xff) //=> 'true'
isNumber(-1.1) //=> 'true'
isNumber(0) //=> 'true'
isNumber(1) //=> 'true'
isNumber(1.1) //=> 'true'
isNumber(10) //=> 'true'
isNumber(10.10) //=> 'true'
isNumber(100) //=> 'true'
isNumber('-1.1') //=> 'true'
isNumber('0') //=> 'true'
isNumber('012') //=> 'true'
isNumber('0xff') //=> 'true'
isNumber('1') //=> 'true'
isNumber('1.1') //=> 'true'
isNumber('10') //=> 'true'
isNumber('10.10') //=> 'true'
isNumber('100') //=> 'true'
isNumber('5e3') //=> 'true'
isNumber(parseInt('012')) //=> 'true'
isNumber(parseFloat('012')) //=> 'true'
```
### False
See the [tests](./test.js) for more examples.
```js
isNumber('foo') //=> 'false'
isNumber([1]) //=> 'false'
isNumber([]) //=> 'false'
isNumber(function () {}) //=> 'false'
isNumber(Infinity) //=> 'false'
isNumber(NaN) //=> 'false'
isNumber(new Array('abc')) //=> 'false'
isNumber(new Array(2)) //=> 'false'
isNumber(new Buffer('abc')) //=> 'false'
isNumber(null) //=> 'false'
isNumber(undefined) //=> 'false'
isNumber({abc: 'abc'}) //=> 'false'
```
[infinity]: http://en.wikipedia.org/wiki/Infinity
[gist]: https://gist.github.com/jonschlinkert/e30c70c713da325d0e81
is-number-4.0.0/LICENSE 0000664 0000000 0000000 00000002100 13171314227 0014413 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2014-2017, Jon Schlinkert.
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.
is-number-4.0.0/README.md 0000664 0000000 0000000 00000012016 13171314227 0014674 0 ustar 00root root 0000000 0000000 # is-number [](https://www.npmjs.com/package/is-number) [](https://npmjs.org/package/is-number) [](https://npmjs.org/package/is-number) [](https://travis-ci.org/jonschlinkert/is-number)
> Returns true if the value is a number. comprehensive tests.
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save is-number
```
## Usage
To understand some of the rationale behind the decisions made in this library (and to learn about some oddities of number evaluation in JavaScript), [see this gist](https://gist.github.com/jonschlinkert/e30c70c713da325d0e81).
```js
var isNumber = require('is-number');
```
### true
See the [tests](./test.js) for more examples.
```js
isNumber(5e3) //=> 'true'
isNumber(0xff) //=> 'true'
isNumber(-1.1) //=> 'true'
isNumber(0) //=> 'true'
isNumber(1) //=> 'true'
isNumber(1.1) //=> 'true'
isNumber(10) //=> 'true'
isNumber(10.10) //=> 'true'
isNumber(100) //=> 'true'
isNumber('-1.1') //=> 'true'
isNumber('0') //=> 'true'
isNumber('012') //=> 'true'
isNumber('0xff') //=> 'true'
isNumber('1') //=> 'true'
isNumber('1.1') //=> 'true'
isNumber('10') //=> 'true'
isNumber('10.10') //=> 'true'
isNumber('100') //=> 'true'
isNumber('5e3') //=> 'true'
isNumber(parseInt('012')) //=> 'true'
isNumber(parseFloat('012')) //=> 'true'
```
### False
See the [tests](./test.js) for more examples.
```js
isNumber('foo') //=> 'false'
isNumber([1]) //=> 'false'
isNumber([]) //=> 'false'
isNumber(function () {}) //=> 'false'
isNumber(Infinity) //=> 'false'
isNumber(NaN) //=> 'false'
isNumber(new Array('abc')) //=> 'false'
isNumber(new Array(2)) //=> 'false'
isNumber(new Buffer('abc')) //=> 'false'
isNumber(null) //=> 'false'
isNumber(undefined) //=> 'false'
isNumber({abc: 'abc'}) //=> 'false'
```
## About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install && npm test
```
Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
### Related projects
You might also be interested in these projects:
* [even](https://www.npmjs.com/package/even): Get the even numbered items from an array. | [homepage](https://github.com/jonschlinkert/even "Get the even numbered items from an array.")
* [is-even](https://www.npmjs.com/package/is-even): Return true if the given number is even. | [homepage](https://github.com/jonschlinkert/is-even "Return true if the given number is even.")
* [is-odd](https://www.npmjs.com/package/is-odd): Returns true if the given number is odd. | [homepage](https://github.com/jonschlinkert/is-odd "Returns true if the given number is odd.")
* [is-primitive](https://www.npmjs.com/package/is-primitive): Returns `true` if the value is a primitive. | [homepage](https://github.com/jonschlinkert/is-primitive "Returns `true` if the value is a primitive. ")
* [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.")
* [odd](https://www.npmjs.com/package/odd): Get the odd numbered items from an array. | [homepage](https://github.com/jonschlinkert/odd "Get the odd numbered items from an array.")
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 38 | [jonschlinkert](https://github.com/jonschlinkert) |
| 5 | [charlike](https://github.com/charlike) |
### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
### License
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on October 17, 2017._ is-number-4.0.0/benchmark/ 0000775 0000000 0000000 00000000000 13171314227 0015347 5 ustar 00root root 0000000 0000000 is-number-4.0.0/benchmark/check.js 0000664 0000000 0000000 00000001071 13171314227 0016761 0 ustar 00root root 0000000 0000000 'use strict';
var fs = require('fs');
var chalk = require('chalk');
var path = require('path');
fs.readdirSync(__dirname + '/code').forEach(function (fp) {
if (/\.js$/.test(fp)) {
var fn = require(path.resolve(__dirname, 'code', fp));
var name = path.basename(fp, path.extname(fp));
fs.readdirSync(__dirname + '/fixtures').forEach(function (fixture) {
fixture = path.resolve(__dirname, 'fixtures', fixture);
if (/\.js$/.test(fixture)) {
console.log(chalk.bold(name) + ':', fn.apply(null, require(fixture)));
}
});
}
});
is-number-4.0.0/benchmark/code/ 0000775 0000000 0000000 00000000000 13171314227 0016261 5 ustar 00root root 0000000 0000000 is-number-4.0.0/benchmark/code/current.js 0000664 0000000 0000000 00000000304 13171314227 0020276 0 ustar 00root root 0000000 0000000 'use strict';
var isNumber = require('../..');
module.exports = function(arr) {
var len = arr.length;
var res = [];
while (len--) {
res.push(isNumber(arr[len]));
}
return res;
};
is-number-4.0.0/benchmark/code/isFinite.js 0000664 0000000 0000000 00000000412 13171314227 0020366 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function(arr) {
var len = arr.length;
var res = [];
while (len--) {
res.push(isNumber(arr[len]));
}
return res;
};
function isNumber(n) {
return (!!(+n) && !Array.isArray(n)) && isFinite(n) || n === '0'|| n === 0;
}
is-number-4.0.0/benchmark/code/parseFloat.js 0000664 0000000 0000000 00000000370 13171314227 0020717 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function(arr) {
var len = arr.length;
var res = [];
while (len--) {
res.push(isNumber(arr[len]));
}
return res;
};
function isNumber(n) {
return !Array.isArray(n) && (n - parseFloat(n) + 1) >= 0;
}
is-number-4.0.0/benchmark/fixtures/ 0000775 0000000 0000000 00000000000 13171314227 0017220 5 ustar 00root root 0000000 0000000 is-number-4.0.0/benchmark/fixtures/all.js 0000664 0000000 0000000 00000003717 13171314227 0020336 0 ustar 00root root 0000000 0000000 module.exports = [[
0xff,
5e3,
0,
0.1,
-0.1,
-1.1,
37,
3.14,
1,
1.1,
10,
10.10,
100,
-100,
'0.1',
'-0.1',
'-1.1',
'0',
'012',
'0xff',
'1',
'1.1',
'10',
'10.10',
'100',
'5e3',
' 56\r\n ', // issue#3
Math.LN2,
Number(1),
new Number(1),
// 012, Octal literal not allowed in strict mode
parseInt('012'),
parseFloat('012'),
Math.abs(1),
Math.acos(1),
Math.asin(1),
Math.atan(1),
Math.atan2(1, 2),
Math.ceil(1),
Math.cos(1),
Math.E,
Math.exp(1),
Math.floor(1),
Math.LN10,
Math.LN2,
Math.log(1),
Math.LOG10E,
Math.LOG2E,
Math.max(1, 2),
Math.min(1, 2),
Math.PI,
Math.pow(1, 2),
Math.pow(5, 5),
Math.random(1),
Math.round(1),
Math.sin(1),
Math.sqrt(1),
Math.SQRT1_2,
Math.SQRT2,
Math.tan(1),
Number.MAX_VALUE,
Number.MIN_VALUE,
'0.0',
'0x0',
'0e+5',
'000',
'0.0e-5',
'0.0E5',
+'',
+1,
+3.14,
+37,
+5,
+[],
+Boolean(true),
+false,
+Math.LN2,
+String(100),
+true,
+null,
+Number(1),
+new Array(''),
+new Array(0),
+new Boolean(true),
+new Buffer(''),
+new Date,
+new Date(),
+new Number(1),
// should fail
' ', // issue#3
'\r\n\t', // issue#3
'',
'3a',
'abc',
'false',
'null',
'true',
'undefined',
+'abc',
+/foo/,
+[1, 2, 4],
+function () {},
+function() {},
+function(){},
+Infinity,
+Math.sin,
+NaN,
+new Array('abc'),
+new Array(2),
+new RegExp('foo'),
+new String("abc"),
+String('foo'),
+undefined,
+{a:1},
+{},
// Symbol('foo'),
// Symbol(),
// Symbol.iterator,
/foo/,
[1, 2, 3],
[1],
[],
Boolean(true),
false,
function () {},
function() {},
function(){},
Infinity,
Math.sin,
NaN,
new Array(''),
new Array('abc'),
new Array(0),
new Boolean(true),
new Buffer(''),
new Buffer('abc'),
new Date(),
new RegExp('foo'),
new String("abc"),
null,
String("abc"),
true,
undefined,
{a:1},
{abc: 'abc'},
{},
]]
is-number-4.0.0/benchmark/fixtures/infinity.js 0000664 0000000 0000000 00000000037 13171314227 0021407 0 ustar 00root root 0000000 0000000 module.exports = [[Infinity]];
is-number-4.0.0/benchmark/fixtures/null.js 0000664 0000000 0000000 00000000033 13171314227 0020524 0 ustar 00root root 0000000 0000000 module.exports = [[null]];
is-number-4.0.0/benchmark/fixtures/number.js 0000664 0000000 0000000 00000000030 13171314227 0021037 0 ustar 00root root 0000000 0000000 module.exports = [[1]];
is-number-4.0.0/benchmark/fixtures/string-number.js 0000664 0000000 0000000 00000000032 13171314227 0022345 0 ustar 00root root 0000000 0000000 module.exports = [['1']];
is-number-4.0.0/benchmark/fixtures/string.js 0000664 0000000 0000000 00000000034 13171314227 0021061 0 ustar 00root root 0000000 0000000 module.exports = [['foo']];
is-number-4.0.0/benchmark/index.js 0000664 0000000 0000000 00000000262 13171314227 0017014 0 ustar 00root root 0000000 0000000 'use strict';
var Suite = require('benchmarked');
var suite = new Suite({
result: false,
fixtures: 'fixtures/*.js',
code: 'code/*.js',
cwd: __dirname,
});
suite.run();
is-number-4.0.0/benchmark/last.txt 0000664 0000000 0000000 00000000247 13171314227 0017056 0 ustar 00root root 0000000 0000000 current.js x 100,502 ops/sec ±0.80% (94 runs sampled)
isFinite.js x 91,315 ops/sec ±0.92% (89 runs sampled)
parseFloat.js x 72,464 ops/sec ±1.17% (91 runs sampled)
is-number-4.0.0/benchmark/support.js 0000664 0000000 0000000 00000015012 13171314227 0017420 0 ustar 00root root 0000000 0000000 console.log('+new Array() //=> ', +new Array());
console.log('+new Array(0) //=> ', +new Array(0));
console.log('new Array(0) //=> ', new Array(0));
console.log('new Array(0)+1 //=> ', new Array(0)+1);
console.log('+new Array(1) //=> ', +new Array(1));
console.log('new Array(1)+1 //=> ', new Array(1)+1);
console.log('+new Array(1)+1 //=> ', +new Array(1)+1);
console.log('+new Array(2) //=> ', +new Array(2));
console.log('+new Array(2)+1 //=> ', +new Array(2)+1);
console.log('+new Array(100)+1 //=> ', +new Array(100)+1);
console.log('typeof (+new Array(100)+1) === "number" //=> ', typeof (+new Array(100)+1) === 'number');
console.log('isFinite(+new Array()) //=> ', isFinite(+new Array()))
console.log('isFinite(+new Array(0)) //=> ', isFinite(+new Array(0)))
console.log('isFinite(new Array(0)) //=> ', isFinite(new Array(0)))
console.log('isFinite(new Array(0)+1) //=> ', isFinite(new Array(0)+1))
console.log('isFinite(+new Array(1)) //=> ', isFinite(+new Array(1)))
console.log('isFinite(new Array(1)+1) //=> ', isFinite(new Array(1)+1))
console.log('isFinite(+new Array(1)+1) //=> ', isFinite(+new Array(1)+1))
console.log('isFinite(+new Array(2)) //=> ', isFinite(+new Array(2)))
console.log('isFinite(+new Array(2)+1) //=> ', isFinite(+new Array(2)+1))
console.log('isFinite(+new Array(100)+1) //=> ', isFinite(+new Array(100)+1))
console.log('isFinite(typeof (+new Array(100)+1) === "number") //=> ', isFinite(typeof (+new Array(100)+1) === 'number'))
// Numbers
typeof 37 === 'number';
typeof 3.14 === 'number';
typeof Math.LN2 === 'number';
typeof Infinity === 'number';
typeof NaN === 'number'; // Despite being "Not-A-Number"
typeof Number(1) === 'number'; // but never use this form!
// Strings
typeof "" === 'string';
typeof "bla" === 'string';
typeof (typeof 1) === 'string'; // typeof always return a string
typeof String("abc") === 'string'; // but never use this form!
// Booleans
typeof true === 'boolean';
typeof false === 'boolean';
typeof Boolean(true) === 'boolean'; // but never use this form!
// Symbols
typeof Symbol() === 'symbol'
typeof Symbol('foo') === 'symbol'
typeof Symbol.iterator === 'symbol'
// Undefined
typeof undefined === 'undefined';
typeof blabla === 'undefined'; // an undefined variable
// Objects
typeof {a:1} === 'object';
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
typeof [1, 2, 4] === 'object';
typeof new Date() === 'object';
// The following is confusing. Don't use!
typeof new Boolean(true) === 'object';
typeof new Number(1) === 'object';
typeof new String("abc") === 'object';
// Functions
typeof function(){} === 'function';
typeof Math.sin === 'function';
// =======================
// Numbers
console.log(typeof +37)
console.log(typeof +3.14)
console.log(typeof +Math.LN2)
console.log(typeof +Infinity)
console.log(typeof +NaN)
console.log(typeof +Number(1))
// Strings
console.log(typeof +'')
console.log(typeof +'foo')
console.log(typeof +(typeof 1))
console.log(typeof +(typeof 'foo'))
console.log(typeof +String('foo'))
console.log(typeof +String(100))
// Booleans
console.log(typeof +true)
console.log(typeof +false)
console.log(typeof +Boolean(true))
// Undefined
console.log(typeof +undefined)
// console.log(typeof +blabla)
// Objects
console.log(typeof +{a:1})
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays
console.log(typeof +[1, 2, 4])
console.log(typeof +new Date())
// The following is confusing. Don't use!
console.log(typeof +new Boolean(true))
console.log(typeof +new Number(1))
console.log(typeof +new String("abc"))
// Functions
console.log(typeof +function(){})
console.log(typeof +Math.sin)
console.log(typeof +'foo')
console.log(-new Date)
console.log(-new Date())
console.log(1 + null)
console.log(1 + +null)
console.log(1 + null + '2')
console.log(1 + null + 2)
console.log(+null + +null)
console.log(1 + +false)
console.log(1 + false)
console.log(1 + true)
console.log(1 + +true)
console.log(false + false)
console.log(+false + false)
console.log(+false + +false)
console.log(false + null)
console.log(+false + null)
console.log(+false + +null)
console.log(true + true)
console.log(+true + true)
console.log(+true + +true)
console.log(true + false)
console.log(+true + false)
console.log(+true + +false)
console.log(+true + +null)
console.log(1 + 2) // 3
console.log(true + 1)
console.log(false + false)
console.log(5 + 'abc')
console.log('abc' + false)
console.log('abc' + 'bar')
console.log(+1 + 2) // 3
console.log(+true + 1)
console.log(+false + false)
console.log(+5 + 'abc')
console.log(+'abc' + false)
console.log(+'abc' + 'bar')
console.log(typeof (+1 + 2) === 'number')
console.log(typeof (+true + 1) === 'number')
console.log(typeof (+false + false) === 'number')
console.log(typeof (+5 + 'abc') === 'number')
console.log(typeof (+'abc' + false) === 'number')
console.log(typeof (+'abc' + 'bar') === 'number')
console.log(typeof -true) //=> 'number'
console.log(typeof -false) //=> 'number'
console.log(typeof -null) //=> 'number'
console.log(typeof -undefined) //=> 'number'
console.log(typeof -{}) //=> 'number'
console.log(typeof -[]) //=> 'number'
console.log(typeof -function() {}) //=> 'number'
console.log(typeof -'foo') //=> 'number'
console.log(typeof -new Date()) //=> 'number'
console.log(typeof -new Buffer('')) //=> 'number'
console.log(typeof -new Array('')) //=> 'number'
console.log(typeof -NaN) //=> 'number'
console.log(typeof -Infinity) //=> 'number'
console.log(+true) //=> '1'
console.log(+false) //=> '0'
console.log(+null) //=> '0'
console.log(+undefined) //=> 'NaN'
console.log(+{}) //=> 'NaN'
console.log(+[]) //=> '0'
console.log(+function() {}) //=> 'NaN'
console.log(+'foo') //=> 'NaN'
console.log(+new Date()) //=> '1422091853924'
console.log(+new Buffer('')) //=> '0'
console.log(+new Array('')) //=> '0'
console.log(+NaN) //=> 'NaN'
console.log(+Infinity) //=> 'Infinity'
console.log(!!(+true));
console.log(!!(+false));
console.log(!!(+null));
console.log(!!(+undefined));
console.log(!!(+{}));
console.log(!!(+[]));
console.log(!!(+function() {}));
console.log(!!(+'foo'));
console.log(!!(+new Date()));
console.log(!!(+new Buffer('')));
console.log(!!(+new Array('')));
console.log(!!(+NaN));
console.log(!!(+Infinity));
console.log()
console.log(!!(true));
console.log(!!(false));
console.log(!!(null));
console.log(!!(undefined));
console.log(!!({}));
console.log(!!([]));
console.log(!!(function() {}));
console.log(!!('foo'));
console.log(!!(new Date()));
console.log(!!(new Buffer('')));
console.log(!!(new Array('')));
console.log(!!(NaN));
console.log(!!(Infinity));
is-number-4.0.0/index.js 0000664 0000000 0000000 00000000773 13171314227 0015071 0 ustar 00root root 0000000 0000000 /*!
* is-number
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
module.exports = function isNumber(num) {
var type = typeof num;
if (type === 'string' || num instanceof String) {
// an empty string would be coerced to true with the below logic
if (!num.trim()) return false;
} else if (type !== 'number' && !(num instanceof Number)) {
return false;
}
return (num - num + 1) >= 0;
};
is-number-4.0.0/package.json 0000664 0000000 0000000 00000002611 13171314227 0015703 0 ustar 00root root 0000000 0000000 {
"name": "is-number",
"description": "Returns true if the value is a number. comprehensive tests.",
"version": "4.0.0",
"homepage": "https://github.com/jonschlinkert/is-number",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"tunnckoCore (https://i.am.charlike.online)"
],
"repository": "jonschlinkert/is-number",
"bugs": {
"url": "https://github.com/jonschlinkert/is-number/issues"
},
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
},
"devDependencies": {
"benchmarked": "^2.0.0",
"chalk": "^2.1.0",
"gulp-format-md": "^1.0.0",
"mocha": "^3.0.1"
},
"keywords": [
"check",
"coerce",
"coercion",
"integer",
"is",
"is-nan",
"is-num",
"is-number",
"istype",
"kind",
"math",
"nan",
"num",
"number",
"numeric",
"test",
"type",
"typeof",
"value"
],
"verb": {
"related": {
"list": [
"even",
"is-even",
"is-odd",
"is-primitive",
"kind-of",
"odd"
]
},
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"lint": {
"reflinks": true
}
}
}
is-number-4.0.0/test.js 0000664 0000000 0000000 00000005155 13171314227 0014740 0 ustar 00root root 0000000 0000000 /*!
* is-number
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var isNumber = require('./');
var shouldPass = [
0xff,
5e3,
0,
0.1,
-0.1,
-1.1,
37,
3.14,
1,
1.1,
10,
10.10,
100,
-100,
'0.1',
'-0.1',
'-1.1',
'0',
'012',
'0xff',
'1',
'1.1',
'10',
'10.10',
'100',
'5e3',
' 56\r\n ', // issue#3
Math.LN2,
Number(1),
new Number(1),
// 012, Octal literal not allowed in strict mode
parseInt('012'),
parseFloat('012'),
Math.abs(1),
Math.acos(1),
Math.asin(1),
Math.atan(1),
Math.atan2(1, 2),
Math.ceil(1),
Math.cos(1),
Math.E,
Math.exp(1),
Math.floor(1),
Math.LN10,
Math.LN2,
Math.log(1),
Math.LOG10E,
Math.LOG2E,
Math.max(1, 2),
Math.min(1, 2),
Math.PI,
Math.pow(1, 2),
Math.pow(5, 5),
Math.random(1),
Math.round(1),
Math.sin(1),
Math.sqrt(1),
Math.SQRT1_2,
Math.SQRT2,
Math.tan(1),
Number.MAX_VALUE,
Number.MIN_VALUE,
'0.0',
'0x0',
'0e+5',
'000',
'0.0e-5',
'0.0E5',
+'',
+1,
+3.14,
+37,
+5,
+[],
+Boolean(true),
+false,
+Math.LN2,
+String(100),
+true,
+null,
+Number(1),
+new Array(''),
+new Array(0),
+new Boolean(true),
+new Buffer(''),
+new Date,
+new Date(),
+new Number(1),
];
var shouldFail = [
' ', // issue#3
'\r\n\t', // issue#3
'',
'3a',
'abc',
'false',
'null',
'true',
'undefined',
+'abc',
+/foo/,
+[1, 2, 4],
+function() {},
+function() {},
+function() {},
+Infinity,
+Math.sin,
+NaN,
+new Array('abc'),
+new Array(2),
+new RegExp('foo'),
+new String("abc"),
+String('foo'),
+undefined,
+{a:1},
+{},
// Symbol('foo'),
// Symbol(),
// Symbol.iterator,
/foo/,
[1, 2, 3],
[1],
[],
Boolean(true),
false,
function() {},
function() {},
function() {},
Infinity,
Math.sin,
NaN,
new Array(''),
new Array('abc'),
new Array(0),
new Boolean(true),
new Buffer(''),
new Buffer('abc'),
new Date(),
new RegExp('foo'),
new String("abc"),
null,
String("abc"),
true,
undefined,
{a:1},
{abc: 'abc'},
{},
];
describe('is a number', function() {
shouldPass.forEach(function(num) {
it('"' + JSON.stringify(num) + '" should be a number', function() {
assert.equal(isNumber(num), true);
});
});
});
describe('is not a number', function() {
shouldFail.forEach(function(num) {
it('"' + JSON.stringify(num) + '" should not be a number', function() {
assert.equal(isNumber(num), false);
});
});
});