bem / bem-sdk Goto Github PK
View Code? Open in Web Editor NEWBEM SDK packages
Home Page: https://en.bem.info/toolbox/sdk/
BEM SDK packages
Home Page: https://en.bem.info/toolbox/sdk/
Preset support convention by Harry Roberts.
//`bemLikeNaming` is equal `customNaming`
var bemLikeNaming = new bemNaming.BEMNaming('csswizardry');
var customNaming = new bemNaming.BEMNaming({
elem: '__',
mod: '--'
});
It seems that the is*
methods are not always convenient.
Useful if you want to check an entity once.
Inconvenient if you want to use switch
logic.
typeOf(str)
bemNaming.typeOf('block'); // block
bemNaming.typeOf('block__elem'); // elem
bemNaming.typeOf('block_mod'); // blockMod
bemNaming.typeOf('block__elem_mod'); // elemMod
typeOf(obj)
bemNaming.typeOf({ block: 'block' }); // block
bemNaming.typeOf({ block: 'block', elem: 'elem' }); // elem
bemNaming.typeOf({ block: 'block', modName: 'mod' }); // blockMod
bemNaming.typeOf({ block: 'block', elem: 'elem', modName: 'mod' }); // elemMod
How you can use this method:
switch (bemNaming.typeOf(entity)) {
case 'block': /*...*/ break;
case 'elem': /*...*/ break;
case 'blockMod': /*...*/ break;
case 'elemMod': /*...*/ break;
}
or:
var type = bemNaming.typeOf(entity);
if (type === 'block') {
return val1;
}
if (type === 'elem') {
return val2;
}
return val3;
Spec:
naming.isBlock('block'); // true
naming.isBlock('block__elem'); // false
naming.isBlock({ block: 'block' }); // true
naming.isBlock({ block: 'block', elem: 'elem' }); // false
We have i-locale__promo.ru
element, which builds in ENB, but bem-naming is fails to parse it.
//cc @dench
lib/bem-naming.js
as es6 moduledist/bem-naming.dev.js
dist/bem-naming.dev.js.map
dist/bem-naming.js
main
should refer to dist/bem-naming.js
.Since there are:
etc.
Please add shortcut modifiers naming convention like .blockName__elName.-mod_val
ie class="blockName__elName -mod_val"
This format is used by us at iDeus: https://github.com/ideus-team/guidelines/blob/master/frontend/bem.md and some foreign developers: http://viget.com/extend/bem-sass-modifiers
This pattern contains only small english letters. Is this expected to be so?
I think we should use the mod
name instead of modName
with modVal
.
Now:
{ block: 'button', modName: 'size', modVal: 's' },
{ block: 'button', modName: 'disabled', modVal: true }
Need:
{ block: 'button', mod: { name: 'size', val: 's' } },
{ block: 'button', mod: 'disabled' }
Why?
{ block: 'button', modName: 'size', modVal: false }
.Hi, is there some tooling for checking the structure of CSS code following BEM approach and having and some warnings if there are errors?
Thanks a lot
like block__elem_mod!!!val
For now it's impossible to do.
Purpose is using for Harry Roberts' notation: block__elem--mod_val
.
Now to provide bemNaming
to global scope using this
:
(function (global) {
})(this);
In NodeJS this
link to module.exports
, but not in global
variables.
For browsers need use window
variable.
(function (global) {
})(typeof window !== "undefined" ? window : global);
Now we need use BEMNaming
class to create instance.
var BEMNaming = bemNaming.BEMNaming;
var myNaming = new BEMNaming({ elem: '__', mod: '--' });
myNaming.parse('block__elem--mod');
The bemNaming
can be function that returns a BEMNaming
instance.
var myNaming = bemNaming({ elem: '__', mod: '--' });
myNaming.parse('block__elem--mod');
Inspired by Pull Request #46
bemNaming.delims.elem // __
// 2 underscores
bemNaming.delims.mod // _
// 1 underscore
actual:
bemNaming({ elem: '__', mod: '--' }); // create instance of BEMNaming
bemNaming({ elem: '__', mod: '--' }); // create instance of BEMNaming
expected:
bemNaming({ elem: '__', mod: '--' }); // create instance of BEMNaming
bemNaming({ elem: '__', mod: '--' }); // get instance from previous step
Now namespace includes methods, but not includes elemDelim
and modDelim
fields.
Example:
import naming from 'bem-naming';
console.log(naming.elemDelim);
console.log(naming.modDelim);
Actual:
undefined
undefined
Expected:
__
_
Broken in #72
The parse
method should return BemEntityName
object.
It will allow use helpers of BemEntityName
.
const parse = require('naming').parse;
const entityName = parse('button_disabled');
entityName.id; // button_disabled
entityName.type; // mod
entityName.isEqual({ block: 'button' }); // false
entityName.belongsTo({ block: 'button' }); // true
The stringify
method should support BemEntityName
object to consistency.
now need use try..catch
:
try {
var str = bemNaming.stringify({ elem: 'elem' });
} catch(e) { /* ... */ }
it will be easier to check for an empty string:
var str = bemNaming.stringify({ elem: 'elem' });
if (str) {
/* ... */
}
It is necessary to add preset
option to constructor:
import bemNaming from 'bem-naming';
const naming = bemNaming('two-dashes');
Possible values:
origin
(by default) — Yandex convention (block__elem_mod_val)two-dashes
— Harry Roberts convention (block__elem--mod_val)Will be very helpful if there will be full BEMJSON support:
bemNaming.stringify({block: 'page', mods: {type: 'inner'}, mix: {block: 'page-404', elem: 'content', elemMods: {type: 'any'}}});
// page page_type_inner page-404__content_type_any
How to reproduce?
var stringifyEntity = require('bem-naming').stringify;
stringifyEntity({ block: 'button', modName: 'size', modVal: 's' });
// Uncaught TypeError: Cannot read property 'modDelim' of undefined
BEMNaming class it used to create instance.
var BEMNaming = bemNaming.BEMNaming,
myNaming = new BEMNaming({ elem: '__', mod: '--' });
myNaming.parse('block__elem--mod');
Why this module parses BEM identifier modificator and value as modName
and modVal
, but not as mod
and val
? (for example deps
uses mod
and val
notation - http://bem.info/tools/bem/bem-tools/depsjs/)
В таких случаях
block_mod_mod_val
получаем undefined
.
Я видел такое именование для картинок, например, такой файл
block_mod_modVal_blah.svg
или
block_mod_modVal__blah.png
// now
bemNaming.isBlock('') // throw
// need
bemNaming.isBlock('') // false
elemSeparator
modSeparator
literal
typeOf
method to BemEntityName
: We can use type field in BemEntityName
instance.typeOf
method.Spec:
naming.isBlock('block'); // false
naming.isBlock('block__elem'); // true
naming.isBlock({ block: 'block' }); // false
naming.isBlock({ block: 'block', elem: 'elem' }); // true
API
parse(str: string [, ({ delims: {elem, mod: { name, val }}, wordPattern } | string)])
stringify(obj: object | BemEntityName [, ({ delims: {elem, mod: { name, val }}, wordPattern } | string)])
Examples
const parse = require('@bem/naming.parse');
const stringify = require('@bem/naming.stringify');
parse('button__text'); // BemEntityName { block: 'button', text: 'text' }
stringify({ block: 'button', text: 'text' }); // 'button__text'
parse('button--disable', 'two-dashes'); // BemEntityName { block: 'button', mod: 'disable' }
stringify({ block: 'button', mod: 'disabled' }, 'two-dashes'); // 'button--disabled'
Spec:
naming.validate('block__elem'); // true
naming.validate('block^_^elem'); // false
Changes:
elemSeparator
to elem
modSeparator
to mod
wordPattern
instead of literal
How to use original naming:
var original = new bemNaming.BEMNaming({
elem: '__',
mod: '_',
wordPattern: '[a-z0-9]+(-[a-z0-9]+)*'
});
// or
var original = new bemNaming.BEMNaming();
// or
var original = bemNaming;
How to use convention by Harry Roberts :
var bemLike = new bemNaming.BEMNaming({
elem: '__',
mod: '--'
});
// or
var bemLike = new bemNaming.BEMNaming({
elem: '__',
mod: '--',
wordPattern: '[a-z0-9]+(-[a-z0-9]+)*'
});
// or
var bemLike = new bemNaming.BEMNaming({
mod: '--'
});
How use custom naming:
var custom = new bemNaming.BEMNaming({
elem: '-',
mod: '--',
wordPattern: '[a-zA-Z0-9]+'
});
['b1__e1', 'b1_m1_v1'].map(bemNaming.parse);
should work.
isElemMod(str | obj)
— modifier of element onlyisBlockMod(str | obj)
— modifier of block onlyA declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.