Skip to content

Commit

Permalink
corrections solution
Browse files Browse the repository at this point in the history
  • Loading branch information
pslzhn committed Dec 12, 2024
1 parent dc3a727 commit 131788c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ function convertToObject(sourceString) {
return sourceString
.split(';')
.filter((line) => line.trim())
.map((line) => line.split(/:(.+)/).map((part) => part.trim()))
.map((line) => {
const colonIndex = line.indexOf(':');

if (colonIndex === -1) {
return [null, null];
}

const key = line.slice(0, colonIndex).trim();
const value = line.slice(colonIndex + 1).trim();

return [key, value];
})
.reduce((styles, [key, value]) => {
if (key && value) {
styles[key] = value;
Expand Down

0 comments on commit 131788c

Please sign in to comment.