From 842d29e1f169648c9360d4a560064f3e2c8e8678 Mon Sep 17 00:00:00 2001 From: Vasiliy Loginevskiy Date: Fri, 10 Mar 2017 21:06:21 +0300 Subject: [PATCH] Fix after @zxqfox review --- README.md | 13 ++++++++----- index.js | 8 ++++---- package.json | 4 ++-- {tests => test}/parse.js | 0 {tests => test}/stringify.js | 0 5 files changed, 14 insertions(+), 11 deletions(-) rename {tests => test}/parse.js (100%) rename {tests => test}/stringify.js (100%) diff --git a/README.md b/README.md index 0ad49df..cc1c2c9 100644 --- a/README.md +++ b/README.md @@ -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 ------------ @@ -51,6 +51,7 @@ API --- * [parse](#parsestr-ctx) +* [stringify](#stringify) ### parse(str, ctx) @@ -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 -------- @@ -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 diff --git a/index.js b/index.js index fd44b68..2ce3091 100644 --- a/index.js +++ b/index.js @@ -60,7 +60,7 @@ 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 @@ -68,7 +68,7 @@ function parse(importString, ctx) { * // '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) { @@ -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}` : '' diff --git a/package.json b/package.json index 9146545..39d7ca8 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/tests/parse.js b/test/parse.js similarity index 100% rename from tests/parse.js rename to test/parse.js diff --git a/tests/stringify.js b/test/stringify.js similarity index 100% rename from tests/stringify.js rename to test/stringify.js