Skip to content

Commit

Permalink
feat(import-notation): add fillup to public api
Browse files Browse the repository at this point in the history
  • Loading branch information
Vittly committed May 6, 2018
1 parent 6da9626 commit 0e8ff34
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
18 changes: 17 additions & 1 deletion packages/import-notation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion packages/import-notation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ function stringify(cells) {

module.exports = {
parse,
stringify
stringify,
fillup : helpers.fillup
};
28 changes: 28 additions & 0 deletions packages/import-notation/test/fillup.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
});

0 comments on commit 0e8ff34

Please sign in to comment.