JSPM

parse-unit

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 394333
  • Score
    100M100P100Q169423F
  • License MIT

parses number and unit, '20px' into [20, 'px']

Package Exports

  • parse-unit

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parse-unit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

parse-unit

stable

Parses a number and unit string, eg "20px" into [20, "px"].

var unit = require('parse-unit')

//prints [50, "gold"]
console.log( unit("50 gold") ) 

Usage

NPM

parse(str[, out])

Parses the string and its unit, returning an array containing the number and unit, separated.

"-20 foo" => [-20, "foo"]
"5.5%" => [5.5, "%"]
5 => [5, ""]
"5" => [5, ""]

This will create a new array unless you specify an array to out, which allows you to re-use arrays.

License

MIT, see LICENSE.md for details.