parseunit
v0.3.1
Published
Parse strings with a number and unit
Downloads
22,890
Maintainers
Readme
parseunit
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}