pax_global_header 0000666 0000000 0000000 00000000064 13317161403 0014511 g ustar 00root root 0000000 0000000 52 comment=98e8ff1da1a89f93d1397a24d7413ed15421c139
is-number-7.0.0/ 0000775 0000000 0000000 00000000000 13317161403 0013416 5 ustar 00root root 0000000 0000000 is-number-7.0.0/.editorconfig 0000664 0000000 0000000 00000000441 13317161403 0016072 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-7.0.0/.eslintrc.json 0000664 0000000 0000000 00000007325 13317161403 0016221 0 ustar 00root root 0000000 0000000 {
"extends": [
"eslint:recommended"
],
"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},
"parserOptions":{
"ecmaVersion": 9,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": 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-7.0.0/.gitattributes 0000664 0000000 0000000 00000000177 13317161403 0016316 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-7.0.0/.gitignore 0000664 0000000 0000000 00000000456 13317161403 0015413 0 ustar 00root root 0000000 0000000 # always ignore files
*.DS_Store
.idea
.vscode
*.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-7.0.0/.npmrc 0000664 0000000 0000000 00000000023 13317161403 0014531 0 ustar 00root root 0000000 0000000 package-lock=false
is-number-7.0.0/.travis.yml 0000664 0000000 0000000 00000000225 13317161403 0015526 0 ustar 00root root 0000000 0000000 sudo: false
os:
- linux
- osx
language: node_js
node_js:
- node
- '10'
- '9'
- '8'
- '7'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
is-number-7.0.0/.verb.md 0000664 0000000 0000000 00000006014 13317161403 0014755 0 ustar 00root root 0000000 0000000 ## Why is this needed?
In JavaScript, it's not always as straightforward as it should be to reliably check if a value is a number. It's common for devs to use `+`, `-`, or `Number()` to cast a string value to a number (for example, when values are returned from user input, regex matches, parsers, etc). But there are many non-intuitive edge cases that yield unexpected results:
```js
console.log(+[]); //=> 0
console.log(+''); //=> 0
console.log(+' '); //=> 0
console.log(typeof NaN); //=> 'number'
```
This library offers a performant way to smooth out edge cases like these, with minimal code.
## Usage
```js
const isNumber = require('{%= name %}');
```
See the [tests](./test.js) for more examples.
### true
```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
Everything else is false, as you would expect:
```js
isNumber(Infinity); // false
isNumber(NaN); // false
isNumber(null); // false
isNumber(undefined); // false
isNumber(''); // false
isNumber(' '); // false
isNumber('foo'); // false
isNumber([1]); // false
isNumber([]); // false
isNumber(function () {}); // false
isNumber({}); // false
```
## Release history
### 6.1.0
- Refactor to be more performant. No breaking changes.
- Performance is about the same as v6.0 when a string or number is passed, but it's now 3x-4x faster when the value is not a string or number.
### 6.0.0
- Optimizations, thanks to @benaadams.
### 5.0.0
**Breaking changes**
- removed support for `instanceof Number` and `instanceof String`
## Benchmarks
As with all benchmarks, take these with a grain of salt. See the [benchmarks](./benchmark/index.js) for more detail.
```
# all
v7.0 x 413,222 ops/sec ±2.02% (86 runs sampled)
v6.0 x 111,061 ops/sec ±1.29% (85 runs sampled)
parseFloat x 317,596 ops/sec ±1.36% (86 runs sampled)
fastest is 'v7.0'
# string
v7.0 x 3,054,496 ops/sec ±1.05% (89 runs sampled)
v6.0 x 2,957,781 ops/sec ±0.98% (88 runs sampled)
parseFloat x 3,071,060 ops/sec ±1.13% (88 runs sampled)
fastest is 'parseFloat,v7.0'
# number
v7.0 x 3,146,895 ops/sec ±0.89% (89 runs sampled)
v6.0 x 3,214,038 ops/sec ±1.07% (89 runs sampled)
parseFloat x 3,077,588 ops/sec ±1.07% (87 runs sampled)
fastest is 'v6.0'
```
is-number-7.0.0/LICENSE 0000664 0000000 0000000 00000002103 13317161403 0014417 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2014-present, 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-7.0.0/README.md 0000664 0000000 0000000 00000014562 13317161403 0014705 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 finite number.
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
```
## Why is this needed?
In JavaScript, it's not always as straightforward as it should be to reliably check if a value is a number. It's common for devs to use `+`, `-`, or `Number()` to cast a string value to a number (for example, when values are returned from user input, regex matches, parsers, etc). But there are many non-intuitive edge cases that yield unexpected results:
```js
console.log(+[]); //=> 0
console.log(+''); //=> 0
console.log(+' '); //=> 0
console.log(typeof NaN); //=> 'number'
```
This library offers a performant way to smooth out edge cases like these.
## Usage
```js
const isNumber = require('is-number');
```
See the [tests](./test.js) for more examples.
### true
```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
Everything else is false, as you would expect:
```js
isNumber(Infinity); // false
isNumber(NaN); // false
isNumber(null); // false
isNumber(undefined); // false
isNumber(''); // false
isNumber(' '); // false
isNumber('foo'); // false
isNumber([1]); // false
isNumber([]); // false
isNumber(function () {}); // false
isNumber({}); // false
```
## Release history
### 7.0.0
* Refactor. Now uses `.isFinite` if it exists.
* Performance is about the same as v6.0 when the value is a string or number. But it's now 3x-4x faster when the value is not a string or number.
### 6.0.0
* Optimizations, thanks to @benaadams.
### 5.0.0
**Breaking changes**
* removed support for `instanceof Number` and `instanceof String`
## Benchmarks
As with all benchmarks, take these with a grain of salt. See the [benchmarks](./benchmark/index.js) for more detail.
```
# all
v7.0 x 413,222 ops/sec ±2.02% (86 runs sampled)
v6.0 x 111,061 ops/sec ±1.29% (85 runs sampled)
parseFloat x 317,596 ops/sec ±1.36% (86 runs sampled)
fastest is 'v7.0'
# string
v7.0 x 3,054,496 ops/sec ±1.05% (89 runs sampled)
v6.0 x 2,957,781 ops/sec ±0.98% (88 runs sampled)
parseFloat x 3,071,060 ops/sec ±1.13% (88 runs sampled)
fastest is 'parseFloat,v7.0'
# number
v7.0 x 3,146,895 ops/sec ±0.89% (89 runs sampled)
v6.0 x 3,214,038 ops/sec ±1.07% (89 runs sampled)
parseFloat x 3,077,588 ops/sec ±1.07% (87 runs sampled)
fastest is 'v6.0'
```
## 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:
* [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor. | [homepage](https://github.com/jonschlinkert/is-plain-object "Returns true if an object was created by the `Object` constructor.")
* [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. ")
* [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject "Returns true if the value is an object and not an array or null.")
* [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.")
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 49 | [jonschlinkert](https://github.com/jonschlinkert) |
| 5 | [charlike-old](https://github.com/charlike-old) |
| 1 | [benaadams](https://github.com/benaadams) |
| 1 | [realityking](https://github.com/realityking) |
### Author
**Jon Schlinkert**
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
### License
Copyright © 2018, [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 June 15, 2018._ is-number-7.0.0/benchmark/ 0000775 0000000 0000000 00000000000 13317161403 0015350 5 ustar 00root root 0000000 0000000 is-number-7.0.0/benchmark/fixtures.js 0000664 0000000 0000000 00000004547 13317161403 0017571 0 ustar 00root root 0000000 0000000 module.exports = {
string: 'foo',
stringNumber: '1000',
number: 1000,
null: null,
infinity: Infinity,
all: [
0xff,
5e3,
0,
0.1,
-0.1,
-1.1,
37,
3.14,
1,
1.1,
10,
10.1,
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),
+Buffer.from(''),
+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),
Buffer.from(''),
Buffer.from('abc'),
new Date(),
new RegExp('foo'),
new String('abc'),
null,
String('abc'),
true,
undefined,
{ a: 1 },
{ abc: 'abc' },
{}
]
};
is-number-7.0.0/benchmark/index.js 0000664 0000000 0000000 00000004276 13317161403 0017026 0 ustar 00root root 0000000 0000000 const { Suite } = require('benchmark');
const cursor = require('ansi')(process.stdout);
const fixtures = require('./fixtures');
const cycle = (e, nl) => {
cursor.eraseLine();
cursor.horizontalAbsolute();
cursor.write('' + e.target);
if (nl) cursor.write('\n');
};
function bench(name) {
const suite = new Suite()
.on('start', () => console.log(`# ${name}`))
.on('complete', function(e) {
const fastest = this.filter('fastest').map('name').toString();
console.log(`fastest is '${fastest}'`);
console.log();
})
const res = {
run: suite.run.bind(suite),
add(key, fn) {
suite.add(key, {
onCycle: e => cycle(e),
onComplete: e => cycle(e, true),
fn
});
return res;
}
};
return res;
}
function run(fn, prop = 'all') {
[].concat(fixtures[prop]).forEach(val => fn(val));
}
bench('all')
.add('v6.1', () => run(isNumber61))
.add('v6.0', () => run(isNumber60))
.add('parseFloat', () => run(isNumberParseFloat))
.run()
bench('string')
.add('v6.1', () => run(isNumber61, 'string'))
.add('v6.0', () => run(isNumber60, 'string'))
.add('parseFloat', () => run(isNumberParseFloat, 'string'))
.run()
bench('number')
.add('v6.1', () => run(isNumber61, 'number'))
.add('v6.0', () => run(isNumber60, 'number'))
.add('parseFloat', () => run(isNumberParseFloat, 'number'))
.run()
function isNumberParseFloat(n) {
if (typeof num === 'number') {
return num - num === 0;
}
if (typeof num === 'string') {
return (num - parseFloat(num)) > -1;
}
return false;
}
function isNumber60(val) {
let number = +val;
// Discard Infinity and NaN
if ((number - number) !== 0) return false;
if (number === val) return true;
if (typeof val === 'string') {
// whitespace and empty strings are coerced to 0
// If number is 0, trim the string to see if its empty.
if (number === 0 && val.trim() === '') {
return false;
}
return true;
}
return false;
}
function isNumber61(val) {
if (typeof num === 'number') {
return num - num === 0;
}
if (typeof num === 'string' && num.trim() !== '') {
return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
}
return false;
}
is-number-7.0.0/benchmark/last.md 0000664 0000000 0000000 00000000247 13317161403 0016640 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-7.0.0/index.js 0000664 0000000 0000000 00000000633 13317161403 0015065 0 ustar 00root root 0000000 0000000 /*!
* is-number
*
* Copyright (c) 2014-present, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
module.exports = function(num) {
if (typeof num === 'number') {
return num - num === 0;
}
if (typeof num === 'string' && num.trim() !== '') {
return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
}
return false;
};
is-number-7.0.0/package.json 0000664 0000000 0000000 00000003077 13317161403 0015713 0 ustar 00root root 0000000 0000000 {
"name": "is-number",
"description": "Returns true if a number or string value is a finite number. Useful for regex matches, parsing, user input, etc.",
"version": "7.0.0",
"homepage": "https://github.com/jonschlinkert/is-number",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"Olsten Larck (https://i.am.charlike.online)",
"Rouven Weßling (www.rouvenwessling.de)"
],
"repository": "jonschlinkert/is-number",
"bugs": {
"url": "https://github.com/jonschlinkert/is-number/issues"
},
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"engines": {
"node": ">=0.12.0"
},
"scripts": {
"test": "mocha"
},
"devDependencies": {
"ansi": "^0.3.1",
"benchmark": "^2.1.4",
"gulp-format-md": "^1.0.0",
"mocha": "^3.5.3"
},
"keywords": [
"cast",
"check",
"coerce",
"coercion",
"finite",
"integer",
"is",
"isnan",
"is-nan",
"is-num",
"is-number",
"isnumber",
"isfinite",
"istype",
"kind",
"math",
"nan",
"num",
"number",
"numeric",
"parseFloat",
"parseInt",
"test",
"type",
"typeof",
"value"
],
"verb": {
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"related": {
"list": [
"is-plain-object",
"is-primitive",
"isobject",
"kind-of"
]
},
"plugins": [
"gulp-format-md"
],
"lint": {
"reflinks": true
}
}
}
is-number-7.0.0/test.js 0000664 0000000 0000000 00000004463 13317161403 0014742 0 ustar 00root root 0000000 0000000 /*!
* is-number
*
* Copyright (c) 2014-2018, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var isNumber = require('./');
describe('is a number', function() {
var fixtures = [
0xff,
5e3,
0,
0.1,
-0.1,
-1.1,
37,
3.14,
1,
1.1,
10,
10.1,
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,
// 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,
+[],
+false,
+Math.LN2,
+true,
+null,
+new Date()
];
fixtures.forEach(function(num, idx) {
it(JSON.stringify(num) + ' should be a number', function() {
assert(isNumber(num), 'expected "' + String(num) + '" to be a number');
});
});
});
describe('is not a number', function() {
var fixtures = [
' ', // issue#3
'\r\n\t', // issue#3
'',
'',
'3a',
'abc',
'false',
'null',
'true',
'undefined',
+'abc',
+/foo/,
+[1, 2, 4],
+Infinity,
+Math.sin,
+NaN,
+undefined,
+{ a: 1 },
+{},
/foo/,
[1, 2, 3],
[1],
[],
true,
false,
+function() {},
function() {},
Infinity,
-Infinity,
Math.sin,
NaN,
new Date(),
null,
undefined,
{}
];
fixtures.forEach(function(num) {
it(JSON.stringify(num) + ' should not be a number', function() {
assert(!isNumber(num), 'expected "' + String(num) + '" to not be a number');
});
});
});