@bem/sdk.decl
Version:
Manage declaration of BEM entities
25 lines (20 loc) • 680 B
JavaScript
;
const merge = require('./merge');
/**
* Subtracting sets of cells.
*
* @param {BemCell[]} collection - Original set
* @param {...(BemCell[])} removingSet - Set (or sets) with cells that should be removed
* @returns {BemCell[]} - Resulting set of cells
*/
module.exports = function (collection, removingSet) {
const hash = {};
(arguments.length > 2) && (removingSet = merge.apply(null, [].slice.call(arguments, 1)));
// Build index on what declaration
for (let i = 0, l = removingSet.length; i < l; ++i) {
hash[removingSet[i].id] = true;
}
return collection.filter(function (item) {
return !hash[item.id];
});
};