Skip to content

Commit f20e9f7

Browse files
committed
Merge pull request #79 from bem/docs
Update Docs
2 parents c19a7fe + 4f49550 commit f20e9f7

File tree

2 files changed

+191
-157
lines changed

2 files changed

+191
-157
lines changed

README.md

Lines changed: 96 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,34 @@ About
1919

2020
This tool allows getting information about BEM entity using [string](#string-representation) as well as forming string representation based on [BEM-naming](#bem-naming).
2121

22+
Install
23+
-------
24+
25+
```
26+
$ npm install --save bem-naming
27+
```
28+
29+
Usage
30+
-----
31+
32+
```js
33+
var bemNaming = require('bem-naming');
34+
35+
bemNaming.parse('button__text'); // { block: 'button', elem: 'text' }
36+
37+
bemNaming.stringify({ block: 'button', modName: 'checked' }); // button_checked
38+
```
39+
40+
Table of Contents
41+
-----------------
42+
43+
* [String representation](#string-representation)
44+
* [Common misconceptions](#common-misconceptions)
45+
* [BEM-naming](#bem-naming-1)
46+
* [API](#api)
47+
* [Custom naming convention](#custom-naming-convention)
48+
* [Convention by Harry Roberts](#convention-by-harry-roberts)
49+
2250
String representation
2351
---------------------
2452
To define BEM entities we often use a special string format that allows us 100% define what entity exactly is represented.
@@ -111,24 +139,24 @@ Example:
111139
API
112140
---
113141

114-
* [`validate(str)`](#validatestr)
115-
* [`parse(str)`](#parsestr)
116-
* [`stringify(obj)`](#stringifyobj)
117-
* [`typeOf(str)`](#typeofstr)
118-
* [`typeOf(obj)`](#typeofobj)
119-
* [`isBlock(str)`](#isblockstr)
120-
* [`isBlock(obj)`](#isblockobj)
121-
* [`isBlockMod(str)`](#isblockmodstr)
122-
* [`isBlockMod(obj)`](#isblockmodobj)
123-
* [`isElem(str)`](#iselemstr)
124-
* [`isElem(obj)`](#iselemobj)
125-
* [`isElemMod(str)`](#iselemmodstr)
126-
* [`isElemMod(obj)`](#iselemmodobj)
127-
* [`elemDelim`](#elemdelim)
128-
* [`modDelim`](#moddelim)
129-
* [`modValDelim`](#modvaldelim)
130-
131-
### `validate(str)`
142+
* [validate(str)](#validatestr)
143+
* [parse(str)](#parsestr)
144+
* [stringify(obj)](#stringifyobj)
145+
* [typeOf(str)](#typeofstr)
146+
* [typeOf(obj)](#typeofobj)
147+
* [isBlock(str)](#isblockstr)
148+
* [isBlock(obj)](#isblockobj)
149+
* [isBlockMod(str)](#isblockmodstr)
150+
* [isBlockMod(obj)](#isblockmodobj)
151+
* [isElem(str)](#iselemstr)
152+
* [isElem(obj)](#iselemobj)
153+
* [isElemMod(str)](#iselemmodstr)
154+
* [isElemMod(obj)](#iselemmodobj)
155+
* [elemDelim](#elemdelim)
156+
* [modDelim](#moddelim)
157+
* [modValDelim](#modvaldelim)
158+
159+
### validate(str)
132160

133161
Checks a string to be valid BEM notation.
134162

@@ -139,9 +167,7 @@ bemNaming.validate('block-name'); // true
139167
bemNaming.validate('^*^'); // false
140168
```
141169

142-
-------------------------------------------------------------------------------
143-
144-
### `parse(str)`
170+
### parse(str)
145171

146172
It parses string `str` into BEM-naming.
147173

@@ -152,9 +178,7 @@ bemNaming.parse('block__elem_mod_val'); // { block: 'block', elem: 'elem',
152178
// modName: 'mod', modVal: 'val' }
153179
```
154180

155-
-------------------------------------------------------------------------------
156-
157-
### `stringify(obj)`
181+
### stringify(obj)
158182

159183
It forms a string according to BEM-naming `obj`.
160184

@@ -167,8 +191,6 @@ bemNaming.stringify({
167191
}); // 'block__elem_mod_val'
168192
```
169193

170-
-------------------------------------------------------------------------------
171-
172194
### `typeOf(str)`
173195

174196
Returns a string indicating the type of the BEM entity.
@@ -182,9 +204,7 @@ bemNaming.typeOf('block__elem'); // elem
182204
bemNaming.typeOf('block__elem_mod'); // elemMod
183205
```
184206

185-
-------------------------------------------------------------------------------
186-
187-
### `typeOf(obj)`
207+
### typeOf(obj)
188208

189209
Returns a string indicating the type of the BEM entity.
190210

@@ -197,9 +217,7 @@ bemNaming.typeOf({ block: 'block', elem: 'elem' }); // elem
197217
bemNaming.typeOf({ block: 'block', elem: 'elem', modName: 'mod' }); // elemMod
198218
```
199219

200-
-------------------------------------------------------------------------------
201-
202-
### `isBlock(str)`
220+
### isBlock(str)
203221

204222
Checks whether string `str` is a block.
205223

@@ -210,9 +228,7 @@ bemNaming.isBlock('block-name'); // true
210228
bemNaming.isBlock('block__elem'); // false
211229
```
212230

213-
-------------------------------------------------------------------------------
214-
215-
### `isBlock(obj)`
231+
### isBlock(obj)
216232

217233
Checks whether BEM-naming `obj` is a block.
218234

@@ -223,9 +239,7 @@ bemNaming.isBlock({ block: 'block-name' }); // true
223239
bemNaming.isBlock({ block: 'block', elem: 'elem' }); // false
224240
```
225241

226-
-------------------------------------------------------------------------------
227-
228-
### `isBlockMod(str)`
242+
### isBlockMod(str)
229243

230244
Checks whether string `str` is modifier of a block.
231245

@@ -236,9 +250,7 @@ bemNaming.isBlockMod('block_mod'); // true
236250
bemNaming.isBlockMod('block__elem_mod'); // false
237251
```
238252

239-
-------------------------------------------------------------------------------
240-
241-
### `isBlockMod(obj)`
253+
### isBlockMod(obj)
242254

243255
Checks whether BEM-naming `obj` is modifier of a block.
244256

@@ -252,9 +264,7 @@ bemNaming.isBlockMod({ block: 'block', elem: 'elem',
252264
modName: 'mod', modVal: true }); // false
253265
```
254266

255-
-------------------------------------------------------------------------------
256-
257-
### `isElem(str)`
267+
### isElem(str)
258268

259269
Checks whether string `str` is element of a block.
260270

@@ -265,9 +275,7 @@ bemNaming.isElem('block__elem'); // true
265275
bemNaming.isElem('block-name'); // false
266276
```
267277

268-
-------------------------------------------------------------------------------
269-
270-
### `isElem(obj)`
278+
### isElem(obj)
271279

272280
Checks whether BEM-naming `obj` is element of a block.
273281

@@ -278,9 +286,7 @@ bemNaming.isElem({ block: 'block', elem: 'elem' }); // true
278286
bemNaming.isElem({ block: 'block-name' }); // false
279287
```
280288

281-
-------------------------------------------------------------------------------
282-
283-
### `isElemMod(str)`
289+
### isElemMod(str)
284290

285291
Checks whether string `str` is modifier of an element.
286292

@@ -291,9 +297,7 @@ bemNaming.isElemMod('block__elem_mod'); // true
291297
bemNaming.isElemMod('block__elem'); // false
292298
```
293299

294-
-------------------------------------------------------------------------------
295-
296-
### `isElemMod(obj)`
300+
### isElemMod(obj)
297301

298302
Checks whether BEM-naming `obj` is modifier of an element.
299303

@@ -307,21 +311,15 @@ bemNaming.isElemMod({ block: 'block',
307311
modName: 'mod', modVal: true}); // false
308312
```
309313

310-
-------------------------------------------------------------------------------
311-
312-
### `elemDelim`
314+
### elemDelim
313315

314316
String to separate elem from block.
315317

316-
-------------------------------------------------------------------------------
317-
318-
### `modDelim`
318+
### modDelim
319319

320320
String to separate modifiers from blocks and elements.
321321

322-
-------------------------------------------------------------------------------
323-
324-
### `modValDelim`
322+
### modValDelim
325323

326324
String to separate value of modifier from name of modifier.
327325

@@ -330,22 +328,6 @@ Custom naming convention
330328

331329
Use `bemNaming` function to create instance to manage naming of your own naming convention.
332330

333-
Function `bemNaming` gets the object from the following options:
334-
335-
* **String** `elem` — separates element's name from block. Default as `__`.
336-
* **String|Object** `mod` — separates modifiers from blocks and elements. Default as `_`.
337-
338-
This option can get object:
339-
340-
```js
341-
{ name: String, val: String }
342-
```
343-
344-
* **String** `name` — separates name of modifier from blocks and elements. Default as `_`.
345-
* **String** `val` — separates value of modifier from name of modifier. Default as the value of the `name`.
346-
347-
* **String** `wordPattern` — defines which symbols can be used for block, element and modifier's names. Default as `[a-z0-9]+(?:-[a-z0-9]+)*`.
348-
349331
Example:
350332

351333
```js
@@ -366,6 +348,42 @@ myNaming.stringify({ // 'blockName-elemName--boolElemMod'
366348
});
367349
```
368350

351+
### bemNaming({ elem, mod, wordPattern })
352+
353+
#### elem
354+
355+
Type: `String`
356+
357+
Default: `__`
358+
359+
Separates element's name from block
360+
361+
#### mod
362+
363+
Type: `String`, `{ name: String, val: String }`
364+
365+
Default: `_`
366+
367+
Separates modifiers from blocks and elements.
368+
369+
This option can take object with following fields:
370+
371+
* `name` — separates name of modifier from blocks and elements.
372+
373+
Default as `_`.
374+
375+
* `val` — separates value of modifier from name of modifier.
376+
377+
Default as the value of the `name`.
378+
379+
#### wordPattern
380+
381+
Type: `String`
382+
383+
Default: `[a-z0-9]+(?:-[a-z0-9]+)*`
384+
385+
Defines which symbols can be used for block, element and modifier's names.
386+
369387
Convention by Harry Roberts
370388
---------------------------
371389

0 commit comments

Comments
 (0)