Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BemCell.isBemCell #11

Merged
merged 3 commits into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
});