From 0e8ff3494e30dea1a199cb7300150a8c1bbd4ddc Mon Sep 17 00:00:00 2001 From: Vitaly Kosenko Date: Sun, 6 May 2018 13:22:28 +0500 Subject: [PATCH] feat(import-notation): add fillup to public api --- packages/import-notation/README.md | 18 ++++++++++++- packages/import-notation/index.js | 3 ++- packages/import-notation/test/fillup.test.js | 28 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 packages/import-notation/test/fillup.test.js diff --git a/packages/import-notation/README.md b/packages/import-notation/README.md index c2c865f3..63cc590c 100644 --- a/packages/import-notation/README.md +++ b/packages/import-notation/README.md @@ -38,13 +38,29 @@ API * [parse](#parsestr-scope) * [stringify](#stringify) +* [fillup](#fillupstr-scope) + +### fillup(str, scope) + +Parameter | Type | Description +----------|----------|-------------------------------------------------------- +`str` | `string` | BEM import notation check [notation section](#notation) +`scope` | `object` | BEM entity name representation + +Fills up given import-notation by context entity to its full form. + +Example: + +```js +fillup('e:text', { block: 'button' }) // → 'b:button e:text' +``` ### parse(str, [scope]) Parameter | Type | Description ----------|----------|-------------------------------------------------------- `str` | `string` | BEM import notation check [notation section](#notation) -[`scope`] | `object` | BEM entity name representation. +[`scope`] | `object` | BEM entity name representation Parses the string into BEM entities. diff --git a/packages/import-notation/index.js b/packages/import-notation/index.js index 0b70ecc0..f0cb6595 100644 --- a/packages/import-notation/index.js +++ b/packages/import-notation/index.js @@ -91,5 +91,6 @@ function stringify(cells) { module.exports = { parse, - stringify + stringify, + fillup : helpers.fillup }; diff --git a/packages/import-notation/test/fillup.test.js b/packages/import-notation/test/fillup.test.js new file mode 100644 index 00000000..1b9e0f8b --- /dev/null +++ b/packages/import-notation/test/fillup.test.js @@ -0,0 +1,28 @@ +var expect = require('chai').expect, + f = require('..').fillup; + +describe('scope', () => { + describe('block', () => { + it('should copy block if notation has no block #1', () => { + expect(f('e:icon', { block : 'button' })).to.eql('b:button e:icon'); + }); + + it('should copy block if notation has no block #2', () => { + expect(f('m:theme=default', { block : 'button' })).to.eql('b:button m:theme=default'); + }); + + it('should not copy block if notation has block', () => { + expect(f('b:button e:icon', { block : 'input' })).to.eql('b:button e:icon'); + }); + }); + + describe('elem', () => { + it('should copy elem if notation has no elem', () => { + expect(f('m:theme=default', { block : 'button', elem : 'icon' })).to.eql('b:button e:icon m:theme=default'); + }); + + it('should not copy elem if notation has elem', () => { + expect(f('b:button e:icon', { block : 'input', elem : 'clear' })).to.eql('b:button e:icon'); + }); + }); +});