CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
README.md187 linesDownload Raw Back to is-number
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 3> Returns true if the value is a finite number.4 5Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.6 7## Install8 9Install with [npm](https://www.npmjs.com/):10 11```sh12$ npm install --save is-number13```14 15## Why is this needed?16 17In 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:18 19```js20console.log(+[]); //=> 021console.log(+''); //=> 022console.log(+'   '); //=> 023console.log(typeof NaN); //=> 'number'24```25 26This library offers a performant way to smooth out edge cases like these.27 28## Usage29 30```js31const isNumber = require('is-number');32```33 34See the [tests](./test.js) for more examples.35 36### true37 38```js39isNumber(5e3);               // true40isNumber(0xff);              // true41isNumber(-1.1);              // true42isNumber(0);                 // true43isNumber(1);                 // true44isNumber(1.1);               // true45isNumber(10);                // true46isNumber(10.10);             // true47isNumber(100);               // true48isNumber('-1.1');            // true49isNumber('0');               // true50isNumber('012');             // true51isNumber('0xff');            // true52isNumber('1');               // true53isNumber('1.1');             // true54isNumber('10');              // true55isNumber('10.10');           // true56isNumber('100');             // true57isNumber('5e3');             // true58isNumber(parseInt('012'));   // true59isNumber(parseFloat('012')); // true60```61 62### False63 64Everything else is false, as you would expect:65 66```js67isNumber(Infinity);          // false68isNumber(NaN);               // false69isNumber(null);              // false70isNumber(undefined);         // false71isNumber('');                // false72isNumber('   ');             // false73isNumber('foo');             // false74isNumber([1]);               // false75isNumber([]);                // false76isNumber(function () {});    // false77isNumber({});                // false78```79 80## Release history81 82### 7.0.083 84* Refactor. Now uses `.isFinite` if it exists.85* 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.86 87### 6.0.088 89* Optimizations, thanks to @benaadams.90 91### 5.0.092 93**Breaking changes**94 95* removed support for `instanceof Number` and `instanceof String`96 97## Benchmarks98 99As with all benchmarks, take these with a grain of salt. See the [benchmarks](./benchmark/index.js) for more detail.100 101```102# all103v7.0 x 413,222 ops/sec ±2.02% (86 runs sampled)104v6.0 x 111,061 ops/sec ±1.29% (85 runs sampled)105parseFloat x 317,596 ops/sec ±1.36% (86 runs sampled)106fastest is 'v7.0'107 108# string109v7.0 x 3,054,496 ops/sec ±1.05% (89 runs sampled)110v6.0 x 2,957,781 ops/sec ±0.98% (88 runs sampled)111parseFloat x 3,071,060 ops/sec ±1.13% (88 runs sampled)112fastest is 'parseFloat,v7.0'113 114# number115v7.0 x 3,146,895 ops/sec ±0.89% (89 runs sampled)116v6.0 x 3,214,038 ops/sec ±1.07% (89 runs sampled)117parseFloat x 3,077,588 ops/sec ±1.07% (87 runs sampled)118fastest is 'v6.0'119```120 121## About122 123<details>124<summary><strong>Contributing</strong></summary>125 126Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).127 128</details>129 130<details>131<summary><strong>Running Tests</strong></summary>132 133Running 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:134 135```sh136$ npm install && npm test137```138 139</details>140 141<details>142<summary><strong>Building docs</strong></summary>143 144_(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.)_145 146To generate the readme, run the following command:147 148```sh149$ npm install -g verbose/verb#dev verb-generate-readme && verb150```151 152</details>153 154### Related projects155 156You might also be interested in these projects:157 158* [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.")159* [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. ")160* [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.")161* [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.")162 163### Contributors164 165| **Commits** | **Contributor** | 166| --- | --- |167| 49 | [jonschlinkert](https://github.com/jonschlinkert) |168| 5 | [charlike-old](https://github.com/charlike-old) |169| 1 | [benaadams](https://github.com/benaadams) |170| 1 | [realityking](https://github.com/realityking) |171 172### Author173 174**Jon Schlinkert**175 176* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)177* [GitHub Profile](https://github.com/jonschlinkert)178* [Twitter Profile](https://twitter.com/jonschlinkert)179 180### License181 182Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).183Released under the [MIT License](LICENSE).184 185***186 187_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 15, 2018._