npm

Need private packages and team management tools?Check out npm Orgs. »

parse-unit

1.0.1 • Public • Published

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.

install

npm i parse-unit

Downloadsweekly downloads

143,354

version

1.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability