@typeforce/to-number
v1.0.0
Published
Convert a value to a `number`
Downloads
2
Readme
to-number
Convert a value to a number
.
Usage
npm install @typeforce/to-number --save # Install package via NPM
import { expect } from "chai";
import toNumber from "@typeforce/to-number";
expect(toNumber(new Number(42))).to.equal(42);
expect(toNumber("42")).to.equal(42);
expect(toNumber(-42)).to.equal(-42);
expect(toNumber(undefined)).to.be.NaN;
expect(toNumber(null)).to.be.NaN;
This package contains TypeScript type declarations.
Content Delivery Network (CDN)
This package can be imported via unpkg as demonstrated below.
<script src="https://unpkg.com/@typeforce/to-number/dist/index.min.js"></script>
<script type="application/javascript">
var x = "42";
var y = toNumber(x);
</script>
Build & Test
This package uses Gulp for building, and Chai and Mocha for testing.
npm install # Installs dependencies.
npm run build # Build the project.
npm test # Run tests.
License
Refer to the LICENSE
file for license information.