Skip to content

Commit b93bd98

Browse files
author
blond
committed
feat(presets): add two-dashes preset
This preset create naming by Harry Roberts. It is nessesary to not pass all options every time you use the convention by Harry Roberts. ```js var bemNaming = require('bem-naming'); // without preset var myNaming = bemNaming({ elem: '__', mod: { name: '—-', val: '_' } }); // with preset var myNaming = bemNaming('two-dashes'); ```
1 parent b225514 commit b93bd98

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

index.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,28 +205,42 @@ var defineAsGlobal = true,
205205
'isBlock', 'isElem', 'isBlockMod', 'isElemMod'
206206
],
207207
fields = ['elemDelim', 'modDelim', 'modValDelim'],
208+
presets = {
209+
'two-dashes': {
210+
elem: '__',
211+
modName: '--',
212+
modVal: '_',
213+
wordPattern: '[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*'
214+
}
215+
},
208216
bemNaming = function (options) {
209217
options || (options = {});
210218

211-
var mod = options.mod || '_',
212-
modName, modVal;
219+
var naming;
213220

214-
if (typeof mod === 'string') {
215-
modName = mod;
216-
modVal = mod;
221+
if (options === 'two-dashes') {
222+
naming = presets['two-dashes'];
217223
} else {
218-
modName = mod.name || '_';
219-
modVal = mod.val || modName;
220-
}
221-
222-
var naming = {
224+
var mod = options.mod || '_',
225+
modName, modVal;
226+
227+
if (typeof mod === 'string') {
228+
modName = mod;
229+
modVal = mod;
230+
} else {
231+
modName = mod.name || '_';
232+
modVal = mod.val || modName;
233+
}
234+
235+
naming = {
223236
elem: options.elem || '__',
224237
modName: modName,
225238
modVal: modVal,
226239
wordPattern: options.wordPattern || '[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*'
227-
},
228-
id = JSON.stringify(naming);
240+
}
241+
}
229242

243+
var id = JSON.stringify(naming);
230244
if (cache[id]) {
231245
return cache[id];
232246
}

0 commit comments

Comments
 (0)