Skip to content
This repository was archived by the owner on Feb 4, 2018. It is now read-only.

Commit b8d7b10

Browse files
committed
docs: describe toJson method in debuggability section
1 parent a25976a commit b8d7b10

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ API
106106
* [isBemEntityName(entityName)](#isbementitynameentityname)
107107
* [toString()](#tostring)
108108
* [valueOf()](#valueof)
109+
* [toJSON()](#tojson)
109110

110111
### constructor({ block, elem, mod })
111112

@@ -250,6 +251,10 @@ name.valueOf();
250251
// ➜ { block: 'button', mod: { name: 'focused', value: true } }
251252
```
252253

254+
### toJSON()
255+
256+
Returns object for `JSON.stringify()` purposes.
257+
253258
Debuggability
254259
-------------
255260

@@ -279,6 +284,19 @@ console.log(`name: ${name}`);
279284
// ➜ name: input_available
280285
```
281286

287+
Also `BemEntityName` has `toJSON` method to support `JSON.stringify()` behaviour.
288+
289+
```js
290+
const BemEntityName = require('@bem/entity-name');
291+
292+
const name = new BemEntityName({ block: 'input', mod: 'available' });
293+
294+
console.log(JSON.stringify(name));
295+
296+
// ➜ {"block":"input","mod":{"name":"available","val":true}}
297+
```
298+
299+
282300
License
283301
-------
284302

0 commit comments

Comments
 (0)