Skip to content

Instantly share code, notes, and snippets.

@serkodev
Created April 5, 2022 20:13
Show Gist options
  • Select an option

  • Save serkodev/25cee88a79700bb95e89d09370ef0658 to your computer and use it in GitHub Desktop.

Select an option

Save serkodev/25cee88a79700bb95e89d09370ef0658 to your computer and use it in GitHub Desktop.
Group selector of Master styles
// Author: SerKo (https://github.com/serkodev)
function group(cls, sel) {
return function parse(cls, sel) {
if (typeof cls == "string") {
return cls.split(/\s/).reduce((a, cur) => cur ? a.concat(cur + sel) : a, []);
} else if (typeof cls == "object") {
return cls.reduce((a, cur) => a.concat(...parse(cur, sel)), []);
} else return [];
}(cls, sel || "").join(" ");
}
group("f:1 m:2 p:3", "@xm");
// f:1@xm m:2@xm p:3@xm
group(["f:1", "m:2", "p:3"], "@xm");
// f:1@xm m:2@xm p:3@xm
group(["f:1 m:2", "p:3"], "@xm");
// f:1@xm m:2@xm p:3@xm
group([`
f:1
m:2
`,
"p:3"],
"@xm");
// f:1@xm m:2@xm p:3@xm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment