UNPKG
parse-unit
Version:
latest (1.0.1)
1.0.1
1.0.0
parses number and unit, '20px' into [20, 'px']
github.com/mattdesl/parse-unit
mattdesl/parse-unit
parse-unit
/
index.js
10 lines
(9 loc)
•
229 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
module.exports =
function
parseUnit
(
str,
out
)
{
if
(!
out
)
out
= [
0
,
''
] str = String(str)
var
num = parseFloat(str,
10
)
out
[
0
] = num
out
[
1
] = str.match(/[\d.\-\+]*\s*(.*)/)[
1
] ||
''
return
out
}