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

Commit a6678d9

Browse files
committed
BREAKING: simplify construct and add create method
1 parent e7f862d commit a6678d9

File tree

2 files changed

+5
-55
lines changed

2 files changed

+5
-55
lines changed

index.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
22

3+
const assert = require('assert');
34
const util = require('util');
45

56
const stringifyEntity = require('bem-naming').stringify;
7+
const parseEntity = require('bem-naming').parse;
68

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

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

3940
obj.elem && (data.elem = obj.elem);
40-
41-
const modObj = obj.mod;
42-
const modName = (typeof modObj === 'string' ? modObj : modObj && modObj.name) || obj.modName;
43-
const hasModVal = modObj && modObj.hasOwnProperty('val') || obj.hasOwnProperty('modVal');
44-
45-
if (modName) {
46-
data.mod = {
47-
name: modName,
48-
val: hasModVal ? modObj && modObj.val || obj.modVal : true
49-
};
50-
} else if (modObj || hasModVal) {
51-
throw new Error('This is not valid BEM entity: the field `mod.name` is undefined.');
52-
}
41+
obj.mod && (data.mod = { name: obj.mod.name, val: obj.mod.val || true });
5342

5443
this.__isBemEntityName__ = true;
5544
}

test/normalize.test.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)