1 | # is-number [![NPM version](https://badge.fury.io/js/is-number.svg)](http://badge.fury.io/js/is-number) [![Build Status](https://travis-ci.org/jonschlinkert/is-number.svg)](https://travis-ci.org/jonschlinkert/is-number)
|
2 |
|
3 | > Returns true if the value is a number. comprehensive tests.
|
4 |
|
5 | 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).
|
6 |
|
7 | ## Install with [npm](npmjs.org)
|
8 |
|
9 | ```bash
|
10 | npm i is-number --save
|
11 | ```
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```js
|
16 | var isNumber = require('is-number');
|
17 | ```
|
18 |
|
19 | ### true
|
20 |
|
21 | See the [tests](./test.js) for more examples.
|
22 |
|
23 | ```js
|
24 | isNumber(5e3) //=> 'true'
|
25 | isNumber(0xff) //=> 'true'
|
26 | isNumber(-1.1) //=> 'true'
|
27 | isNumber(0) //=> 'true'
|
28 | isNumber(1) //=> 'true'
|
29 | isNumber(1.1) //=> 'true'
|
30 | isNumber(10) //=> 'true'
|
31 | isNumber(10.10) //=> 'true'
|
32 | isNumber(100) //=> 'true'
|
33 | isNumber('-1.1') //=> 'true'
|
34 | isNumber('0') //=> 'true'
|
35 | isNumber('012') //=> 'true'
|
36 | isNumber('0xff') //=> 'true'
|
37 | isNumber('1') //=> 'true'
|
38 | isNumber('1.1') //=> 'true'
|
39 | isNumber('10') //=> 'true'
|
40 | isNumber('10.10') //=> 'true'
|
41 | isNumber('100') //=> 'true'
|
42 | isNumber('5e3') //=> 'true'
|
43 | isNumber(parseInt('012')) //=> 'true'
|
44 | isNumber(parseFloat('012')) //=> 'true'
|
45 | ```
|
46 |
|
47 | ### False
|
48 |
|
49 | See the [tests](./test.js) for more examples.
|
50 |
|
51 | ```js
|
52 | isNumber('foo') //=> 'false'
|
53 | isNumber([1]) //=> 'false'
|
54 | isNumber([]) //=> 'false'
|
55 | isNumber(function () {}) //=> 'false'
|
56 | isNumber(Infinity) //=> 'false'
|
57 | isNumber(NaN) //=> 'false'
|
58 | isNumber(new Array('abc')) //=> 'false'
|
59 | isNumber(new Array(2)) //=> 'false'
|
60 | isNumber(new Buffer('abc')) //=> 'false'
|
61 | isNumber(null) //=> 'false'
|
62 | isNumber(undefined) //=> 'false'
|
63 | isNumber({abc: 'abc'}) //=> 'false'
|
64 | ```
|
65 |
|
66 | ## Other projects
|
67 |
|
68 | * [even](https://github.com/jonschlinkert/even): Get the even numbered items from an array.
|
69 | * [is-primitive](https://github.com/jonschlinkert/is-primitive): Returns `true` if the value is a primitive.
|
70 | * [is-even](https://github.com/jonschlinkert/is-even): Return true if the given number is even.
|
71 | * [is-odd](https://github.com/jonschlinkert/is-odd): Returns true if the given number is odd.
|
72 | * [kind-of](https://github.com/jonschlinkert/kind-of): Get the native type of a value.
|
73 | * [odd](https://github.com/jonschlinkert/odd): Get the odd numbered items from an array.
|
74 |
|
75 | ## Contributing
|
76 |
|
77 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-number/issues)
|
78 |
|
79 | ## Run tests
|
80 |
|
81 | Install dev dependencies:
|
82 |
|
83 | ```bash
|
84 | npm i -d && npm test
|
85 | ```
|
86 |
|
87 | ## Author
|
88 |
|
89 | **Jon Schlinkert**
|
90 |
|
91 | + [github/jonschlinkert](https://github.com/jonschlinkert)
|
92 | + [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
|
93 |
|
94 | ## License
|
95 |
|
96 | Copyright (c) 2015 Jon Schlinkert
|
97 | Released under the MIT license.
|
98 |
|
99 | ***
|
100 |
|
101 | _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on May 02, 2015._
|