From df9b5ea053d3f3735f2fe29ff0bc35b69e694ba5 Mon Sep 17 00:00:00 2001 From: Alexey Yaroshevich Date: Wed, 18 Jan 2017 01:20:44 +0300 Subject: [PATCH 1/3] feat: BemCell.isBemCell method --- index.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/index.js b/index.js index 2305364..35caeaf 100644 --- a/index.js +++ b/index.js @@ -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; + } }; From fcfda87b651ec438c1cd9c9ead25ffbc4ead9462 Mon Sep 17 00:00:00 2001 From: Alexey Yaroshevich Date: Wed, 18 Jan 2017 01:21:32 +0300 Subject: [PATCH 2/3] tests: BemCell.isBemCell method --- test/is-bem-cell.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/is-bem-cell.test.js diff --git a/test/is-bem-cell.test.js b/test/is-bem-cell.test.js new file mode 100644 index 0000000..ddd747e --- /dev/null +++ b/test/is-bem-cell.test.js @@ -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)); +}); From 704395450249da78fb6785e113d147e01f2c62fe Mon Sep 17 00:00:00 2001 From: Alexey Yaroshevich Date: Wed, 18 Jan 2017 01:22:11 +0300 Subject: [PATCH 3/3] docs: isBemCell method --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 3f3d819..5d06a46 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ API * [tech](#tech) * [layer](#layer) * [id](#id) +* [isBemCell(cell)](#isbemcellcell) ### constructor(obj) @@ -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 -------