Created
April 5, 2022 20:13
-
-
Save serkodev/25cee88a79700bb95e89d09370ef0658 to your computer and use it in GitHub Desktop.
Group selector of Master styles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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