Skip to content

Commit

Permalink
fully updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Fridrif27 committed Nov 7, 2024
1 parent 6053b31 commit 370cfef
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/convertToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,20 @@
* @return {object}
*/
function convertToObject(sourceString) {
const declarations = sourceString.trim().split(';');

const stylesObj = {};

declarations.forEach((declaration) => {
const parts = declaration.split(':');

if (parts.length === 2) {
const property = parts[0].trim();
let value = parts[1].trim();

if (value.includes('!important')) {
value = value.replace('!important', '').trim() + ' !important';
}
return sourceString
.trim()
.split(';')
.reduce((stylesObj, declaration) => {
const [property, value] = declaration
.split(':')
.map((part) => part.trim());

if (property && value) {
stylesObj[property] = value;
}
}
});

return stylesObj;
return stylesObj;
}, {});
}

module.exports = convertToObject;

0 comments on commit 370cfef

Please sign in to comment.