Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuxim committed Dec 12, 2024
1 parent bae75cd commit 176989b
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/convertToObject.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
function convertToObject(sourceString) {
return sourceString
.split(';')
.filter((line) => line.trim())
.reduce((acc, line) => {
const [property, value] = line.split(':');
const convertToObject = (sourceString) => {
const trimmedSourceString = sourceString.trim();
const styleDeclarations = trimmedSourceString.split(';');

if (property && value) {
const trimmedProperty = property.trim();
const trimmedValue = value.trim();
const stylesObject = styleDeclarations.reduce((acc, declaration) => {
const [property, value] = declaration.split(':').map((item) => item.trim());

acc[trimmedProperty] = trimmedValue;
}
if (property && value) {
acc[property] = value;
}

return acc;
}, {});
}
return acc;
}, {});

return stylesObject;
};

module.exports = convertToObject;

0 comments on commit 176989b

Please sign in to comment.