594e0e47003bdb539e471e6fb9efa7a33e91032acc3b24865517d76c0983aefc488f9e765cb7c884ed739aa47ad4b4add31b1415ccadc63d6b938522dfe063 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # is-number [![NPM version](https://img.shields.io/npm/v/is-number.svg?style=flat)](https://www.npmjs.com/package/is-number) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-number.svg?style=flat)](https://npmjs.org/package/is-number) [![NPM total downloads](https://img.shields.io/npm/dt/is-number.svg?style=flat)](https://npmjs.org/package/is-number) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-number.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-number)
  2. > Returns true if the value is a number. comprehensive tests.
  3. Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
  4. ## Install
  5. Install with [npm](https://www.npmjs.com/):
  6. ```sh
  7. $ npm install --save is-number
  8. ```
  9. ## Usage
  10. 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).
  11. ```js
  12. var isNumber = require('is-number');
  13. ```
  14. ### true
  15. See the [tests](./test.js) for more examples.
  16. ```js
  17. isNumber(5e3) //=> 'true'
  18. isNumber(0xff) //=> 'true'
  19. isNumber(-1.1) //=> 'true'
  20. isNumber(0) //=> 'true'
  21. isNumber(1) //=> 'true'
  22. isNumber(1.1) //=> 'true'
  23. isNumber(10) //=> 'true'
  24. isNumber(10.10) //=> 'true'
  25. isNumber(100) //=> 'true'
  26. isNumber('-1.1') //=> 'true'
  27. isNumber('0') //=> 'true'
  28. isNumber('012') //=> 'true'
  29. isNumber('0xff') //=> '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('5e3') //=> 'true'
  36. isNumber(parseInt('012')) //=> 'true'
  37. isNumber(parseFloat('012')) //=> 'true'
  38. ```
  39. ### False
  40. See the [tests](./test.js) for more examples.
  41. ```js
  42. isNumber('foo') //=> 'false'
  43. isNumber([1]) //=> 'false'
  44. isNumber([]) //=> 'false'
  45. isNumber(function () {}) //=> 'false'
  46. isNumber(Infinity) //=> 'false'
  47. isNumber(NaN) //=> 'false'
  48. isNumber(new Array('abc')) //=> 'false'
  49. isNumber(new Array(2)) //=> 'false'
  50. isNumber(new Buffer('abc')) //=> 'false'
  51. isNumber(null) //=> 'false'
  52. isNumber(undefined) //=> 'false'
  53. isNumber({abc: 'abc'}) //=> 'false'
  54. ```
  55. ## About
  56. <details>
  57. <summary><strong>Contributing</strong></summary>
  58. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
  59. </details>
  60. <details>
  61. <summary><strong>Running Tests</strong></summary>
  62. 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:
  63. ```sh
  64. $ npm install && npm test
  65. ```
  66. </details>
  67. <details>
  68. <summary><strong>Building docs</strong></summary>
  69. _(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.)_
  70. To generate the readme, run the following command:
  71. ```sh
  72. $ npm install -g verbose/verb#dev verb-generate-readme && verb
  73. ```
  74. </details>
  75. ### Related projects
  76. You might also be interested in these projects:
  77. * [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.")
  78. * [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.")
  79. * [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.")
  80. * [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. ")
  81. * [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.")
  82. * [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.")
  83. ### Contributors
  84. | **Commits** | **Contributor** |
  85. | --- | --- |
  86. | 38 | [jonschlinkert](https://github.com/jonschlinkert) |
  87. | 5 | [charlike](https://github.com/charlike) |
  88. ### Author
  89. **Jon Schlinkert**
  90. * [github/jonschlinkert](https://github.com/jonschlinkert)
  91. * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
  92. ### License
  93. Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
  94. Released under the [MIT License](LICENSE).
  95. ***
  96. _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on October 17, 2017._