Skip to content

Commit

Permalink
Merge 7043954 into 4307438
Browse files Browse the repository at this point in the history
  • Loading branch information
qfox committed Jan 17, 2017
2 parents 4307438 + 7043954 commit 223e094
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ API
* [tech](#tech)
* [layer](#layer)
* [id](#id)
* [isBemCell(cell)](#isbemcellcell)

### constructor(obj)

Expand Down Expand Up @@ -129,6 +130,26 @@ const cell = new BemCell({
cell.id; // ➜ "button__text@desktop.css"
```

### isBemCell(cell)

Determines whether specified cell is instance of BemCell.

Parameter | Type | Description
----------|-----------------|-----------------------
`cell` | `BemCell` | The cell to check.

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

const cell = new BemCell({
entity: new BemEntityName({ block: 'button', elem: 'text' })
});

BemCell.isBemCell(cell); // true
BemCell.isBemCell({}); // false
```

License
-------

Expand Down
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,25 @@ module.exports = class BemCell {

return this._id;
}

/**
* Determines whether specified cell is instance of BemCell.
*
* @param {BemCell} cell - the cell to check.
*
* @returns {boolean} A Boolean indicating whether or not specified entity is instance of BemCell.
* @example
* const BemCell = require('@bem/cell');
* const BemEntityName = require('@bem/entity-name');
*
* const cell = new BemCell({
* entity: new BemEntityName({ block: 'button', elem: 'text' })
* });
*
* BemCell.isBemCell(cell); // true
* BemCell.isBemCell({}); // false
*/
static isBemCell(cell) {
return cell && this.name === cell.constructor.name;
}
};
21 changes: 21 additions & 0 deletions test/is-bem-cell.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const test = require('ava');
const BemEntityName = require('@bem/entity-name');

const BemCell = require('../index');

test('should check valid entities', t => {
const cell = new BemCell({
entity: new BemEntityName({ block: 'block' })
});

t.true(BemCell.isBemCell(cell));
});

test('should not pass invalid blocks', t => {
t.falsy(BemCell.isBemCell({}));
t.falsy(BemCell.isBemCell([]));
});

test('should not pass null', t => {
t.falsy(BemCell.isBemCell(null));
});

0 comments on commit 223e094

Please sign in to comment.