Created
April 2, 2019 14:33
-
-
Save kunukn/4c5803ddb5615de8aa7c1e78e82c2bde to your computer and use it in GitHub Desktop.
BEM Utils
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
| // BEM Util | |
| export function getModifiers(prefix, modifiers) { | |
| if (!modifiers) return '' | |
| const array = modifiers | |
| .trim() | |
| .split(' ') | |
| .map(m => m.trim()) | |
| .filter(Boolean) | |
| if (array.length === 0) return '' | |
| return array.map(m => `${prefix}--${m}`).join(' ') | |
| } | |
| // BEM Util | |
| export function getElements(prefix, elems) { | |
| if (!elems) return '' | |
| const array = elems | |
| .trim() | |
| .split(' ') | |
| .map(e => e.trim()) | |
| .filter(Boolean) | |
| if (array.length === 0) return '' | |
| return array.map(e => `${prefix}__${e}`).join(' ') | |
| } | |
| // BEM Util | |
| export function modifierFactory(block) { | |
| return params => getModifiers(block, params) | |
| } | |
| // BEM Util | |
| export function elementFactory(block) { | |
| return params => getElements(block, params) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment