@styn/plugin-tokenizer
Version:
Create tokens to use in your styn styles
43 lines (32 loc) • 939 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
function flatten(ob) {
let toReturn = {};
for (const i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if (typeof ob[i] == "object" && ob[i] !== null) {
const flatObject = flatten(ob[i]);
for (const x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
toReturn[i + "." + x] = flatObject[x];
}
} else {
toReturn[i] = ob[i];
}
}
return toReturn;
}
const tokenizer = tokens => (tree, walk) => {
return walk(tree, rule => {
const tokensFlat = flatten(tokens);
if (rule.declarations) {
for (const property in rule.declarations) {
const value = rule.declarations[property];
if (typeof value !== "object" && value in tokensFlat) {
rule.declarations[property] = tokensFlat[value];
}
}
}
});
};
exports.tokenizer = tokenizer;