GithubHelp home page GithubHelp logo

bem / bem-sdk Goto Github PK

View Code? Open in Web Editor NEW
85.0 22.0 26.0 2.18 MB

BEM SDK packages

Home Page: https://en.bem.info/toolbox/sdk/

JavaScript 100.00%
bem naming decl deps bundle cell config entity-name graph walk

bem-sdk's People

Contributors

4exova avatar a-lexxx avatar a-x- avatar belozer avatar bem-robot avatar birhoff avatar blond avatar dab avatar egavr avatar floatdrop avatar godfreyd avatar greenkeeper[bot] avatar greenkeeperio-bot avatar krishnevsky avatar lakate avatar migs911 avatar mursya avatar pavlovsdog1106 avatar qfox avatar skad0 avatar sverbitckaya-bot avatar swinx avatar tadatuta avatar tormozz48 avatar veged avatar vithar avatar vittly avatar voischev avatar yarastqt avatar yeti-or avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bem-sdk's Issues

Add `csswizardry` preset

Preset support convention by Harry Roberts.

//`bemLikeNaming` is equal `customNaming`
var bemLikeNaming = new bemNaming.BEMNaming('csswizardry');
var customNaming = new bemNaming.BEMNaming({
    elem: '__',
    mod: '--'        
});

Add `typeOf` method

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;

Add `isBlock` method

Spec:

naming.isBlock('block');                             // true
naming.isBlock('block__elem');                       // false

naming.isBlock({ block: 'block' });                  // true
naming.isBlock({ block: 'block', elem: 'elem' });    // false

i-locale__promo.ru

We have i-locale__promo.ru element, which builds in ENB, but bem-naming is fails to parse it.

//cc @dench

Add dist

  • rewrite lib/bem-naming.js as es6 module
  • add compiled module for development dist/bem-naming.dev.js
  • add source maps for development dist/bem-naming.dev.js.map
  • move minified version to dist/bem-naming.js
  • bower & npm main should refer to dist/bem-naming.js.

The Mod Field

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?

  1. The record will be easier for boolean modifiers.
  2. There will be less confusion with the { block: 'button', modName: 'size', modVal: false }.
  3. The modifier is always described by one field.
  4. It will be easier to define the type of entity.

True Global

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);

Simplify API: custom naming convention

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');

Provide delimiters

Inspired by Pull Request #46

bemNaming.delims.elem // __
                      //    2 underscores
bemNaming.delims.mod  // _  
                      //    1 underscore

Cache create of custom naming

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

Does not delim fields

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

BemEntityName object

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.

Provide common presets

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)

Implement BEMJSON notation

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 

Functions not working without context

How to reproduce?

var stringifyEntity = require('bem-naming').stringify;

stringifyEntity({ block: 'button', modName: 'size', modVal: 's' });

// Uncaught TypeError: Cannot read property 'modDelim' of undefined

Remove deprecated `BEMNaming` field

BEMNaming class it used to create instance.

var BEMNaming = bemNaming.BEMNaming,
    myNaming = new BEMNaming({ elem: '__', mod: '--' }); 

myNaming.parse('block__elem--mod');

parse returns undefined

В таких случаях

block_mod_mod_val

получаем undefined.

Я видел такое именование для картинок, например, такой файл

block_mod_modVal_blah.svg

или

block_mod_modVal__blah.png

Add `isElem` method

Spec:

naming.isBlock('block');                             // false
naming.isBlock('block__elem');                       // true

naming.isBlock({ block: 'block' });                  // false
naming.isBlock({ block: 'block', elem: 'elem' });    // true

Split into small modules

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'

Add `validate` method

Spec:

naming.validate('block__elem');   // true
naming.validate('block^_^elem');  // false

Update API

Changes:

  • rename elemSeparator to elem
  • rename modSeparator to mod
  • use 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]+'
});

Add `isMod` methods

  • isElemMod(str | obj) — modifier of element only
  • isBlockMod(str | obj) — modifier of block only

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.