@crocsx/scss-to-json
Version:
A utility for converting SCSS variables files to JSON
32 lines (24 loc) • 814 B
JavaScript
;
function DeclarationStore() {
this.declarations = [];
}
DeclarationStore.prototype = {
addDeclaration: function(declaration) {
this.declarations.push(declaration);
},
replaceVariables: function(scssString) {
var replacedString = scssString;
this.declarations.forEach(function(declaration) {
var variable = declaration.variable.value;
var value = declaration.value.value;
var subsetRegex = new RegExp('\\' + variable + '[\\w_-]', 'g');
var isSubset = !!replacedString.match(subsetRegex);
if (!isSubset && variable) {
var regex = new RegExp('(\\' + variable + ')([\\W\\,]?)', 'g');
replacedString = replacedString.replace(regex, value + '$2');
}
});
return replacedString;
}
};
module.exports = DeclarationStore;