UNPKG
s-to-o
Version:
latest (1.2.1)
1.2.1
1.2.0
1.1.0
1.0.0
Convert an string to an object
abranhe/s-to-o
s-to-o
/
index.js
15 lines
(12 loc)
•
258 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'use strict'
;
module
.
exports
=
str
=>
{
return
str .
replace
(
/\s/g
,
''
) .
split
(
','
) .
map
(
key
=>
{
const
a = key.
split
(
':'
)[
0
];
const
b = key.
split
(
':'
)[
1
];
return
{[a]:
isNaN
(b) ? b :
Number
(b)}; }) .
reduce
(
(
x, y
) =>
({...x, ...y})); };