Skip to content

Latest commit

 

History

History
556 lines (383 loc) · 21.5 KB

CHANGELOG.md

File metadata and controls

556 lines (383 loc) · 21.5 KB

Changelog

2.0.0

BEM SDK

The bem-naming became part of the BEM SDK. In this regard, there have been several changes for consistency with other packages of BEM SDK.

Now BEM SDK modules are used in assembly systems and bem-tools plugins. Therefore, the modules support Node.js only.

  • Removed support of YModules and AMD (@blond #138).
  • Stopped publishing to Bower (@blond #118).

If it becomes necessary to use BEM SDK in browsers or other environments we'll figure out a system solution for all modules.

API

According to the principles of BEM SDK each module solves only one problem.

The bem-naming module did more than just parse and stringify BEM names.

Removed typeOf method (#98)

To work with BEM entities there are packages @bem/entity and @bem/entity-name.

API v1.x.x

const bemNaming = require('bem-naming');

// get type by string
bemNaming.typeOf('button'); // block

// get type by entity object
bemNaming.typeOf({ block: 'button', modName: 'focused' }); // blockMod

API v2.x.x

// get type by string
const parseBemName = require('@bem/naming').parse;
const blockName = parseBemName('button');

blockName.type // block

// get type by entity object
const BemEntityName = require('@bem/entity-name');
const modName = new BemEntityName({ block: 'button', mod: 'focused' });

modName.type; // blockMod

Removed validate method (#147)

Use parse method instead.

API v1.x.x

const validate = require('bem-naming').validate;

validate('block-name'); // true
validate('^*^');        // false

API v2.x.x

const parse = require('@bem/naming').parse;

Boolean(parse('block-name')); // true
Boolean(parse('^*^'));        // false

The parse method returns BemEntityName object (#126).

It will allow to use helpers of BemEntityName.

Important: in BemEntityName the modName and modVal fields are deprecated. Use the mod field instead (#95).

API v1.x.x

const parse = require('bem-naming').parse;

const entityName = parse('button_disabled');

entityName.modName; // disabled
entityName.modVal;  // true

console.log(entityName); // { block: 'button', modName: 'disabled', modVal: true }

API v2.x.x

const parse = require('@bem/naming').parse;

const entityName = parse('button_disabled');

entityName.mod;  // { name: 'disabled', val: true }
entityName.id;   // button_disabled
entityName.type; // mod

console.log(entityName); // BemEntityName { block: 'button', mod: { name: 'disabled', val: true } }

The stringify method supports BemEntityName instance (#152).

Important: in BemEntityName the modName and modVal fields are deprecated. Use the mod field instead (#95).

API v1.x.x

const stringify = require('bem-naming').stringify;

stringify({ block: 'button', modName: 'disabled', modVal: true });

// ➜ button_disabled

API v2.x.x

const stringify = require('@bem/naming').stringify;
const BemEntityName = require('@bem/entity-name');

const entityName = new BemEntityName({ block: 'button', mod: 'disabled' });

stringify(entityName);

// ➜ button_disabled

The bem-naming constructor signature for custom-naming was changed (#160).

{ elem: '…', mod: '…' }{ delims: { elem: '…', mod: '…' } }

API v1.x.x

const bemNaming = require('bem-naming');

const myNaming = bemNaming({
    elem: '-',
    mod: { name: '--', val: '_' }
    wordPattern: '[a-zA-Z0-9]+'
});

myNaming.parse('block--mod_val'); // { block: 'block'
                                  //   modName: 'mod',
                                  //   modVal: 'val' }

API v2.x.x

const bemNaming = require('@bem/naming');

const myNaming = bemNaming({
    delims: {
        elem: '-',
        mod: { name: '--', val: '_' }
    },
    wordPattern: '[a-zA-Z0-9]+'
});

myNaming.parse('block--mod_val'); // BemEntityName
                                  // { block: 'block',
                                  //   mod: { name: 'mod', val: 'val' } }

Important: now if the delimiter of modifier value is not specified it doesn't inherit from delimiter of modifier name and falls back to default bemNaming.modValDelim (#169).

API v1.x.x

const bemNaming = require('bem-naming');

// myNaming1 is equal myNaming2
const myNaming1 = bemNaming({ mod: { name: '--' } });
const myNaming2 = bemNaming({ mod: { name: '--', val: '--' } });

API v2.x.x

const bemNaming = require('@bem/naming');

// myNaming1 is equal myNaming2
const myNaming1 = bemNaming({ delims: { mod: '--' } });
const myNaming2 = bemNaming({ delims: { mod: { name: '--', val: '--' } } });

// but myNaming1 is not equal myNaming3
const myNaming3 = bemNaming({ delims: { mod: { name: '--' } } });
// because myNaming3 is equal myNaming4
const myNaming4 = bemNaming({ delims: { mod: { name: '--', val: bemNaming.modValDelim } } });

Delims field (#167).

Added delims field instead of elemDelim, modDelim and modValDelim for consistency with bemNaming function.

API v1.x.x

const bemNaming = require('bem-naming');

bemNaming.elemDelim
bemNaming.modDelim
bemNaming.modValDelim

API v2.x.x

const bemNaming = require('@bem/naming');

bemNaming.delims.elem
bemNaming.delims.mod.name
bemNaming.delims.mod.val

NPM

Now BEM SDK modules are published in @bem scope, so the bem-naming module was renamed to @bem/naming (@blond #158).

Read more about scopes in NPM Documentation.

To install 1.x version of the module you need to run the command:

$ npm i bem-naming

To install 2.x version of the module you need to run the command:

$ npm i @bem/naming

Presets

  • Added react preset (@yeti-or #161).

Performance

  • Accelerated initialization for origin naming (@tadatuta #134).

Chore

  • Moved the package to bem-sdk organization (@blond b22dfc5).
  • Removed Russian docs (@blond #142).
  • Updated docs (@blond #153).
  • Run tests in Node.js v6 (@blond #114).

1.0.1

Bug fixes

  • Functions not working without context (#91).

    Example:

    var stringifyEntity = require('bem-naming').stringify;
    
    stringifyEntity({ block: 'button', modName: 'size', modVal: 's' });
    
    // Uncaught TypeError: Cannot read property 'modDelim' of undefined

Commits

1.0.0

Modifier Delimiters (#76)

Added support to separate value of modifier from name of modifier with specified string.

Before one could only specify a string to separate name of a modifier from name of a block or an element. It string used to separate value of modifier from name of modifier.

Before:

var myNaming = bemNaming({
    mod: '--'
});

var obj = {
    block: 'block',
    modName: 'mod',
    modVal: 'val'
};

myNaming.stringify(obj); // 'block--mod--val'

Now:

var myNaming = bemNaming({
    mod: { name: '--', val: '_' }
});

var obj = {
    block: 'block',
    modName: 'mod',
    modVal: 'val'
};

myNaming.stringify(obj); // 'block--mod_val'

Also added the modValDelim field.

Presets (#81)

Added naming presets:

  • origin (by default) — Yandex convention (block__elem_mod_val).
  • two-dashesHarry Roberts convention (block__elem--mod_val).

It is nessesary not to pass all options every time you use the convention by Harry Roberts.

var bemNaming = require('bem-naming');

// with preset
var myNaming = bemNaming('two-dashes');

Bug fixes

  • Functions for custom naming not working without context(#72).

    Example:

    var bemNaming = require('bem-naming');
    
    var myNaming = bemNaming({ mod: '--' });
    
    ['block__elem', 'block--mod'].map(myNaming.parse); // The `parse` function requires context of `myNaming` object.
                                                       // To correct work Usage of bind (myNaming.parse.bind(myNaming)) // was necessary.
  • this was used instead of global object. (#86).

Removed deprecated

  • The BEMNaming filed removed (#74).

    Use bemNaming function to create custom naming:

    var bemNaming = require('bemNaming');
    
    var myNaming = bemNaming({ elem: '__', mod: '--' });
  • The elemSeparator, modSeparator and literal options removed (#75).

    Use elem, mod and wordPattern instead.

  • The bem-naming.min.js file removed.

Other

  • The stringify method should return undefined for invalid objects, but not throw errror (#71).

    It will be easier to check for an empty string than use try..catch.

    Before:

    try {
        var str = bemNaming.stringify({ elem: 'elem' });
    } catch(e) { /* ... */ }

    Now:

    var str = bemNaming.stringify({ elem: 'elem' });
    
    if (str) {
        /* ... */
    }

Commits

0.5.1

  • Implemented caching for BEMNaming instances (#53).
  • stringify method is speeded up by 2,5 times (#57).
  • parse method is speeded up on 15% (#58).
  • typeOf method is speeded up by 2,25 times (#59).

0.5.0

  • API: delimiters provided (#48).

0.4.0

  • Simplified API for custom naming convention (#37).
  • Added method typeOf (#35).
  • Added support for CamelCase (#34).
  • Added license.

0.3.0

  • Option elemSeparator is deprecated, use elem instead.
  • Option modSeparator is deprecated, use mod instead.
  • Option literal is deprecated, use wordPattern instead.

0.2.1

  • Fixed package.json file.

0.2.0

  • Added ability to use BEM-naming object without modVal field.
  • Added minified version.
  • Fixed bug with is* methods for invalid strings.
  • Fixed bug with bemNaming for IE6-8.

0.1.0

  • Methods validate, isBlock, isElem, isBlockMod, isElemMod were added.
  • Generated string will not get modifier if modVal field of BEM-naming object is undefined.
  • stringify method throws error if invalid BEM-naming object is specified.
  • parse method was fixed: BEM-naming object does not contain explicit undefined fields.