Skip to content
This repository has been archived by the owner on Feb 4, 2018. It is now read-only.

BREAKING: simplify construct and add create method #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ new BemEntityName({
block: 'button',
mod: { name: 'focused', val: true }
});

// Shorthand for the boolean modifier of a block
new BemEntityName({
block: 'button',
mod: 'focused'
});
```

API
Expand Down
21 changes: 5 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';

const assert = require('assert');
const util = require('util');

const stringifyEntity = require('bem-naming').stringify;
const parseEntity = require('bem-naming').parse;

/**
* Enum for types of BEM entities.
Expand Down Expand Up @@ -30,26 +32,13 @@ module.exports = class BemEntityName {
* Used if neither `mod.val` nor `val` were not specified.
*/
constructor(obj) {
if (!obj.block) {
throw new Error('This is not valid BEM entity: the field `block` is undefined.');
}
assert(obj.block, 'This is not valid BEM entity: the field `block` is undefined.');
assert(!obj.mod || obj.mod.name, 'This is not valid BEM entity: the field `mod.name` is undefined.');

const data = this._data = { block: obj.block };

obj.elem && (data.elem = obj.elem);

const modObj = obj.mod;
const modName = (typeof modObj === 'string' ? modObj : modObj && modObj.name) || obj.modName;
const hasModVal = modObj && modObj.hasOwnProperty('val') || obj.hasOwnProperty('modVal');

if (modName) {
data.mod = {
name: modName,
val: hasModVal ? modObj && modObj.val || obj.modVal : true
};
} else if (modObj || hasModVal) {
throw new Error('This is not valid BEM entity: the field `mod.name` is undefined.');
}
obj.mod && (data.mod = { name: obj.mod.name, val: obj.mod.val || true });

this.__isBemEntityName__ = true;
}
Expand Down
39 changes: 0 additions & 39 deletions test/normalize.test.js

This file was deleted.