Skip to content

Commit 0e8ff34

Browse files
committed
feat(import-notation): add fillup to public api
1 parent 6da9626 commit 0e8ff34

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

packages/import-notation/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,29 @@ API
3838

3939
* [parse](#parsestr-scope)
4040
* [stringify](#stringify)
41+
* [fillup](#fillupstr-scope)
42+
43+
### fillup(str, scope)
44+
45+
Parameter | Type | Description
46+
----------|----------|--------------------------------------------------------
47+
`str` | `string` | BEM import notation check [notation section](#notation)
48+
`scope` | `object` | BEM entity name representation
49+
50+
Fills up given import-notation by context entity to its full form.
51+
52+
Example:
53+
54+
```js
55+
fillup('e:text', { block: 'button' }) // → 'b:button e:text'
56+
```
4157

4258
### parse(str, [scope])
4359

4460
Parameter | Type | Description
4561
----------|----------|--------------------------------------------------------
4662
`str` | `string` | BEM import notation check [notation section](#notation)
47-
[`scope`] | `object` | BEM entity name representation.
63+
[`scope`] | `object` | BEM entity name representation
4864

4965
Parses the string into BEM entities.
5066

packages/import-notation/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,6 @@ function stringify(cells) {
9191

9292
module.exports = {
9393
parse,
94-
stringify
94+
stringify,
95+
fillup : helpers.fillup
9596
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var expect = require('chai').expect,
2+
f = require('..').fillup;
3+
4+
describe('scope', () => {
5+
describe('block', () => {
6+
it('should copy block if notation has no block #1', () => {
7+
expect(f('e:icon', { block : 'button' })).to.eql('b:button e:icon');
8+
});
9+
10+
it('should copy block if notation has no block #2', () => {
11+
expect(f('m:theme=default', { block : 'button' })).to.eql('b:button m:theme=default');
12+
});
13+
14+
it('should not copy block if notation has block', () => {
15+
expect(f('b:button e:icon', { block : 'input' })).to.eql('b:button e:icon');
16+
});
17+
});
18+
19+
describe('elem', () => {
20+
it('should copy elem if notation has no elem', () => {
21+
expect(f('m:theme=default', { block : 'button', elem : 'icon' })).to.eql('b:button e:icon m:theme=default');
22+
});
23+
24+
it('should not copy elem if notation has elem', () => {
25+
expect(f('b:button e:icon', { block : 'input', elem : 'clear' })).to.eql('b:button e:icon');
26+
});
27+
});
28+
});

0 commit comments

Comments
 (0)