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

Commit ffd7beb

Browse files
author
blond
committed
refactor(EntityTypeError): move EntityTypeError to separate file
1 parent 942e0d3 commit ffd7beb

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

index.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
const util = require('util');
44

5-
const ExtendableError = require('es6-error');
65
const stringifyEntity = require('@bem/naming').stringify;
76
const deprecate = require('depd')(require('./package.json').name);
87

8+
const EntityTypeError = require('./lib/entity-type-error');
9+
910
/**
1011
* Enum for types of BEM entities.
1112
*
@@ -18,21 +19,6 @@ const TYPES = {
1819
ELEM: 'elem',
1920
ELEM_MOD: 'elemMod'
2021
};
21-
/**
22-
* The EntityTypeError object represents an error when a value is not valid BEM entity.
23-
*/
24-
class EntityTypeError extends ExtendableError {
25-
/**
26-
* @param {object} obj — not valid object
27-
* @param {string} [reason] — human-readable reason why object is not valid
28-
*/
29-
constructor(obj, reason) {
30-
const str = util.inspect(obj, { depth: 1 });
31-
const message = `the object \`${str}\` is not valid BEM entity`;
32-
33-
super(reason ? `${message}, ${reason}` : message);
34-
}
35-
}
3622

3723
class BemEntityName {
3824
/**

lib/entity-type-error.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const util = require('util');
4+
5+
const ExtendableError = require('es6-error');
6+
7+
/**
8+
* The EntityTypeError object represents an error when a value is not valid BEM entity.
9+
*/
10+
module.exports = class EntityTypeError extends ExtendableError {
11+
/**
12+
* @param {object} obj — not valid object
13+
* @param {string} [reason] — human-readable reason why object is not valid
14+
*/
15+
constructor(obj, reason) {
16+
const str = util.inspect(obj, { depth: 1 });
17+
const message = `the object \`${str}\` is not valid BEM entity`;
18+
19+
super(reason ? `${message}, ${reason}` : message);
20+
}
21+
};

0 commit comments

Comments
 (0)