Projekt

Obecné

Profil

Stáhnout (4.32 KB) Statistiky
| Větev: | Revize:
1
# is-number [![NPM version](https://img.shields.io/npm/v/is-number.svg?style=flat)](https://www.npmjs.com/package/is-number) [![NPM downloads](https://img.shields.io/npm/dm/is-number.svg?style=flat)](https://npmjs.org/package/is-number) [![Build Status](https://img.shields.io/travis/jonschlinkert/is-number.svg?style=flat)](https://travis-ci.org/jonschlinkert/is-number)
2

    
3
> Returns true if the value is a number. comprehensive tests.
4

    
5
## Install
6

    
7
Install with [npm](https://www.npmjs.com/):
8

    
9
```sh
10
$ npm install --save is-number
11
```
12

    
13
## Usage
14

    
15
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).
16

    
17
```js
18
var isNumber = require('is-number');
19
```
20

    
21
### true
22

    
23
See the [tests](./test.js) for more examples.
24

    
25
```js
26
isNumber(5e3)      //=> 'true'
27
isNumber(0xff)     //=> 'true'
28
isNumber(-1.1)     //=> 'true'
29
isNumber(0)        //=> 'true'
30
isNumber(1)        //=> 'true'
31
isNumber(1.1)      //=> 'true'
32
isNumber(10)       //=> 'true'
33
isNumber(10.10)    //=> 'true'
34
isNumber(100)      //=> 'true'
35
isNumber('-1.1')   //=> 'true'
36
isNumber('0')      //=> 'true'
37
isNumber('012')    //=> 'true'
38
isNumber('0xff')   //=> 'true'
39
isNumber('1')      //=> 'true'
40
isNumber('1.1')    //=> 'true'
41
isNumber('10')     //=> 'true'
42
isNumber('10.10')  //=> 'true'
43
isNumber('100')    //=> 'true'
44
isNumber('5e3')    //=> 'true'
45
isNumber(parseInt('012'))   //=> 'true'
46
isNumber(parseFloat('012')) //=> 'true'
47
```
48

    
49
### False
50

    
51
See the [tests](./test.js) for more examples.
52

    
53
```js
54
isNumber('foo')             //=> 'false'
55
isNumber([1])               //=> 'false'
56
isNumber([])                //=> 'false'
57
isNumber(function () {})    //=> 'false'
58
isNumber(Infinity)          //=> 'false'
59
isNumber(NaN)               //=> 'false'
60
isNumber(new Array('abc'))  //=> 'false'
61
isNumber(new Array(2))      //=> 'false'
62
isNumber(new Buffer('abc')) //=> 'false'
63
isNumber(null)              //=> 'false'
64
isNumber(undefined)         //=> 'false'
65
isNumber({abc: 'abc'})      //=> 'false'
66
```
67

    
68
## About
69

    
70
### Related projects
71

    
72
* [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.")
73
* [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.")
74
* [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.")
75
* [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. ")
76
* [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.")
77
* [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.")
78

    
79
### Contributing
80

    
81
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
82

    
83
### Building docs
84

    
85
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
86

    
87
To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
88

    
89
```sh
90
$ npm install -g verb verb-generate-readme && verb
91
```
92

    
93
### Running tests
94

    
95
Install dev dependencies:
96

    
97
```sh
98
$ npm install -d && npm test
99
```
100

    
101
### Author
102

    
103
**Jon Schlinkert**
104

    
105
* [github/jonschlinkert](https://github.com/jonschlinkert)
106
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
107

    
108
### License
109

    
110
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
111
Released under the [MIT license](https://github.com/jonschlinkert/is-number/blob/master/LICENSE).
112

    
113
***
114

    
115
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.30, on September 10, 2016._
(2-2/4)