UNPKG

s-to-o

Version:

Convert an string to an object

15 lines (12 loc) 258 B
'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})); };