parseunit editorconfig eslint travis-ci npm

Parse a string with a number and unit e.g. '12px' -> [12, 'px']

3 years after

parseunit

Travis npm David David

Parse strings with a number and unit.

API

ES5

var parse = require('parseunit');
var parsed = parse('12px');
console.log(parsed[0], parsed[1]); // 12 'px'

// or parse into an object for better readability
var parseObj = parse.parseObj;
var parsed = parseObj('12px');
console.log(parsed.val, parsed.unit); // 12 'px'

ES6

import parseUnit, {parseUnitObj} from 'parseunit';

const [val, unit] = parseUnit('12px');
// or
const {val, unit} = parseUnitObj('12px');

console.log(val, unit); // 12 'px'

parseUnit

Default export

Params

  • str string

Returns

  • [val, unit] [number, string]

parseUnitObj

Params

  • str string

Returns

  • {val, unit} {number, string}

Alternatives

parse-unit

Related Repositories

UnitsNet

UnitsNet

Makes life working with units of measurement just a little bit better. ...


Top Contributors

ThomWright

Releases

-   v0.3.1 zip tar
-   v0.3.0 zip tar
-   v0.2.1 zip tar
-   v0.2.0 zip tar
-   v0.1.1 zip tar
-   v0.1.0 zip tar