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

Commit 7ecaf14

Browse files
author
blond
committed
docs(toJSON): add example to toJSON method
1 parent d131857 commit 7ecaf14

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ buttonTextBoldName.belongsTo(buttonName); // false
270270

271271
### valueOf()
272272

273-
Returns object representing the entity name.
273+
Returns normalized object representing the entity name.
274274

275275
```js
276276
const BemEntityName = require('@bem/entity-name');
@@ -283,7 +283,15 @@ name.valueOf();
283283

284284
### toJSON()
285285

286-
Returns object for `JSON.stringify()` purposes.
286+
Returns raw data for `JSON.stringify()` purposes.
287+
288+
```js
289+
const BemEntityName = require('@bem/entity-name');
290+
291+
const name = new BemEntityName({ block: 'input', mod: 'available' });
292+
293+
JSON.stringify(name); // {"block":"input","mod":{"name":"available","val":true}}
294+
```
287295

288296
### toString()
289297

lib/entity-name.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class BemEntityName {
284284
}
285285

286286
/**
287-
* Returns object representing the entity name. Is needed for debug in Node.js.
287+
* Returns normalized object representing the entity name.
288288
*
289289
* In some browsers `console.log()` calls `valueOf()` on each argument.
290290
* This method will be called to get custom string representation of the object.
@@ -305,7 +305,14 @@ class BemEntityName {
305305
valueOf() { return this._data; }
306306

307307
/**
308-
* Return raw data for `JSON.stringify()`.
308+
* Returns raw data for `JSON.stringify()` purposes.
309+
*
310+
* @example
311+
* const BemEntityName = require('@bem/entity-name');
312+
*
313+
* const name = new BemEntityName({ block: 'input', mod: 'available' });
314+
*
315+
* JSON.stringify(name); // {"block":"input","mod":{"name":"available","val":true}}
309316
*
310317
* @returns {BemSDK.EntityName.StrictRepresentation}
311318
*/

0 commit comments

Comments
 (0)