parse-css-number
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

parse-css-number

NPM version npm license Travis Build Status codecov BundlePhobia Minified BundlePhobia Minified + gzip code style: prettier Unicorn Approved

npm

Parses a CSS <number>, being either an integer or a number with a fractional component.

Installation

$ npm install parse-css-number [--save[-dev]]

Usage

const parseCSSNumber = require('parse-css-number')
 
// Valid numbers
// https://developer.mozilla.org/en-US/docs/Web/CSS/number#Valid_numbers
parseCSSNumber('12') // A raw <integer> is also a <number>.
parseCSSNumber('4.01') // Positive fraction
parseCSSNumber('-456.8') // Negative fraction
parseCSSNumber('0.0') // Zero
parseCSSNumber('+0.0') // Zero, with a leading +
parseCSSNumber('-0.0') // Zero, with a leading -
parseCSSNumber('.60') // Fractional number without a leading zero
parseCSSNumber('10e3') // Scientific notation
parseCSSNumber('-3.4e-2') // Complicated scientific notation
 
// Invalid numbers
// https://developer.mozilla.org/en-US/docs/Web/CSS/number#Invalid_numbers
parseCSSNumber('12.') // Decimal points must be followed by at least one digit.
parseCSSNumber('+-12.2') // Only one leading +/- is allowed.
parseCSSNumber('12.1.1') // Only one decimal point is allowed.

See the tests for more scenarios.

ES6/2015 import

import parseCSSNumber from 'parse-css-number'

Testing

$ npm test

This will run tests and generate a code coverage report. Anything less than 100% coverage will throw an error.

Package Sidebar

Install

npm i parse-css-number

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

8.82 kB

Total Files

10

Last publish

Collaborators

  • jedmao