Skip to content

Commit

Permalink
Fix after @zxqfox review
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeti-or committed Mar 10, 2017
1 parent c206ee2 commit 842d29e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
13 changes: 8 additions & 5 deletions README.md
Expand Up @@ -21,7 +21,7 @@ Tool for working with BEM import strings.
[dependency-img]: http://img.shields.io/david/bem-sdk/bem-import-notation.svg


Extract [BEM entities](https://en.bem.info/methodology/key-concepts/#bem-entity) from import strings.
Extract [BEM entities] from import strings.

Installation
------------
Expand Down Expand Up @@ -51,6 +51,7 @@ API
---

* [parse](#parsestr-ctx)
* [stringify](#stringify)

### parse(str, ctx)

Expand Down Expand Up @@ -87,11 +88,11 @@ So `parse('m:theme=normal', { block: 'button' })` is not same as `parse('b:butto
### stringify

Parameter | Type | Description
----------|----------|-------------------------------------------------------------------
`entities`| `array` | Array of [bem-entities] to merge into bem-import string [notation]
----------|----------|------------------------------------------------------------------------------
`entities`| `array` | Array of [BEM entities] to merge into import string [notation](#notation)

Forms a string from `bem-entities`. Be aware to merge only one type of entities.
Array must contain block and its mods, or elem and its mods.
Forms a string from [BEM entities]. Be aware to merge only one type of entities.
The array should contains one block or one elem and optionally it's modifiers.

Notation
--------
Expand Down Expand Up @@ -220,3 +221,5 @@ License
-------

Code and documentation copyright 2017 YANDEX LLC. Code released under the [Mozilla Public License 2.0](LICENSE.txt).

[BEM entities]: https://en.bem.info/methodology/key-concepts/#bem-entity
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -60,15 +60,15 @@ function parse(importString, ctx) {
}

/**
* Get bem-import string notation representation of a bem-cells array.
* Create import string notation of passed bem-cells.
*
* Example:
* ```js
* stringify([{ block : 'button' }, { block : 'button', mod : { name : 'theme', val : 'normal' } }])
* // 'b:button m:theme=normal'
* ```
* @public
* @param {BemCell[]} - Array of bem-entites to merge into bem-import string notation
* @param {BemCell[]} - Set of BEM entites to merge into import string notation
* @returns {String}
*/
function stringify(cells) {
Expand All @@ -81,13 +81,13 @@ function stringify(cells) {
return acc;
}, { m : {} });

return ['b', 'e', 'm', 't'].reduce((str, k) => str += tmpl[k](merged[k]), '');
return ['b', 'e', 'm', 't'].map(k => tmpl[k](merged[k])).join('');
}

const tmpl = {
b : b => `b:${b}`,
e : e => e ? ` e:${e}` : '',
m : m => Object.keys(m).reduce((acc, name) => acc + `${tmpl.mn(name)}${tmpl.mv(m[name])}`, ''),
m : m => Object.keys(m).map(name => `${tmpl.mn(name)}${tmpl.mv(m[name])}`).join(''),
mn : m => ` m:${m}`,
mv : v => v.length ? `=${v.join('|')}` : '',
t : t => t ? ` t:${t}` : ''
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -6,8 +6,8 @@
"scripts": {
"pretest": "npm run lint",
"test": "npm run specs",
"specs": "mocha tests",
"cover": "nyc mocha tests",
"specs": "mocha",
"cover": "nyc mocha",
"lint": "eslint ."
},
"repository": {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 842d29e

Please sign in to comment.