Skip to content

Commit

Permalink
docs: add debuggability section
Browse files Browse the repository at this point in the history
  • Loading branch information
qfox committed Jan 17, 2017
1 parent ecba717 commit 977212a
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,59 @@ const cell = new BemCell({
cell.id; // ➜ "button__text@desktop.css"
```

Debuggability
-------------

In Node.js, `console.log()` calls `util.inspect()` on each argument without a formatting placeholder.

`BemCell` has `inspect()` method to get custom string representation of the object.

```js
const BemCell = require('@bem/cell');
const BemEntityName = require('@bem/entity-name');

const cell = new BemCell({
entity: new BemEntityName({ block: 'input', mod: 'available' }),
tech: 'css'
});

console.log(cell);

// ➜ BemCell { entity: { block: 'input', mod: { name: 'available' } }, tech: 'css' }
```

You can also convert `BemCell` object to `string`.

```js
const BemCell = require('@bem/cell');
const BemEntityName = require('@bem/entity-name');

const cell = new BemCell({
entity: new BemEntityName({ block: 'input', mod: 'available' }),
tech: 'css'
});

console.log(`cell: ${cell}`);

// ➜ cell: input_available.css
```

Also `BemCell` has `toJson` method to support `JSON.stringify()` behaviour.

```js
const BemCell = require('@bem/cell');
const BemEntityName = require('@bem/entity-name');

const cell = new BemCell({
entity: new BemEntityName({ block: 'input', mod: 'available' }),
tech: 'css'
});

console.log(JSON.stringify(cell));

// ➜ {"entity":{"block":"input","mod":{"name":"available","val":true}},"tech":"css"}
```

License
-------

Expand Down

0 comments on commit 977212a

Please sign in to comment.