@@ -9,7 +9,7 @@ const stringifyEntity = require('@bem/naming').stringify;
9
9
* Enum for types of BEM entities.
10
10
*
11
11
* @readonly
12
- * @enum {String }
12
+ * @enum {string }
13
13
*/
14
14
const TYPES = {
15
15
BLOCK : 'block' ,
@@ -33,17 +33,9 @@ class EntityTypeError extends ExtendableError {
33
33
}
34
34
}
35
35
36
- module . exports = class BemEntityName {
36
+ class BemEntityName {
37
37
/**
38
- * @param {object } obj — representation of entity name.
39
- * @param {string } obj.block — the block name of entity.
40
- * @param {string } [obj.elem] — the element name of entity.
41
- * @param {object } [obj.mod] — the modifier of entity.
42
- * @param {string } obj.mod.name — the modifier name of entity.
43
- * @param {string } [obj.mod.val] — the modifier value of entity.
44
- * @param {string } [obj.modName] — the modifier name of entity. Used if `mod.name` wasn't specified.
45
- * @param {string } [obj.modVal] — the modifier value of entity.
46
- * Used if neither `mod.val` nor `val` were not specified.
38
+ * @param {BemSDK.EntityName.Options } obj — representation of entity name.
47
39
*/
48
40
constructor ( obj ) {
49
41
if ( ! obj . block ) {
@@ -94,7 +86,7 @@ module.exports = class BemEntityName {
94
86
*
95
87
* name.elem; // text
96
88
*
97
- * @returns {string|undefined } - name of entity element.
89
+ * @returns {? string } - name of entity element.
98
90
*/
99
91
get elem ( ) { return this . _data . elem ; }
100
92
@@ -112,7 +104,7 @@ module.exports = class BemEntityName {
112
104
* modName.mod; // { name: 'disabled', val: true }
113
105
* blockName.mod; // undefined
114
106
*
115
- * @returns {{mod: string, val: (string|true)}|undefined } - entity modifier.
107
+ * @returns {?BemSDK.EntityName.ModifierRepresentation } - entity modifier.
116
108
*/
117
109
get mod ( ) { return this . _data . mod ; }
118
110
@@ -121,7 +113,7 @@ module.exports = class BemEntityName {
121
113
*
122
114
* If entity is not modifier then returns `undefined`.
123
115
*
124
- * @returns {string|undefined } - entity modifier name.
116
+ * @returns {? string } - entity modifier name.
125
117
* @deprecated - use `mod.name` instead.
126
118
*/
127
119
get modName ( ) { return this . mod && this . mod . name ; }
@@ -131,7 +123,7 @@ module.exports = class BemEntityName {
131
123
*
132
124
* If entity is not modifier then returns `undefined`.
133
125
*
134
- * @returns {string|undefined } - entity modifier name.
126
+ * @returns {?( string|true) } - entity modifier name.
135
127
* @deprecated - use `mod.val` instead.
136
128
*/
137
129
get modVal ( ) { return this . mod && this . mod . val ; }
@@ -211,7 +203,7 @@ module.exports = class BemEntityName {
211
203
*
212
204
* name.isSimpleMod(); // null
213
205
*
214
- * @returns {boolean|null }
206
+ * @returns {( boolean|null) }
215
207
*/
216
208
isSimpleMod ( ) {
217
209
return this . mod ? this . mod . val === true : null ;
@@ -250,7 +242,7 @@ module.exports = class BemEntityName {
250
242
*
251
243
* // ➜ { block: 'button', mod: { name: 'focused', value: true } }
252
244
*
253
- * @returns {{block: string, elem: (string|undefined), mod: ({name: string, val: (string|true)}|undefined)} }
245
+ * @returns {BemSDK.EntityName.StrictRepresentation }
254
246
*/
255
247
valueOf ( ) { return this . _data ; }
256
248
@@ -284,8 +276,7 @@ module.exports = class BemEntityName {
284
276
/**
285
277
* Return raw data for `JSON.stringify()`.
286
278
*
287
- * @returns {{block: string, elem: (string|undefined),
288
- * mod: ({name: string, val: (string|true|undefined)}|undefined) }}
279
+ * @returns {BemSDK.EntityName.StrictRepresentation }
289
280
*/
290
281
toJSON ( ) {
291
282
return this . _data ;
@@ -294,9 +285,6 @@ module.exports = class BemEntityName {
294
285
/**
295
286
* Determines whether specified entity is the deepEqual entity.
296
287
*
297
- * @param {BemEntityName } entityName - the entity to compare.
298
- *
299
- * @returns {boolean } - A Boolean indicating whether or not specified entity is the deepEqual entity.
300
288
* @example
301
289
* const BemEntityName = require('@bem/entity-name');
302
290
*
@@ -305,6 +293,9 @@ module.exports = class BemEntityName {
305
293
*
306
294
* inputName.isEqual(buttonName); // false
307
295
* buttonName.isEqual(buttonName); // true
296
+ *
297
+ * @param {BemEntityName } entityName - the entity to compare.
298
+ * @returns {boolean } - A Boolean indicating whether or not specified entity is the deepEqual entity.
308
299
*/
309
300
isEqual ( entityName ) {
310
301
return entityName && ( this . id === entityName . id ) ;
@@ -313,16 +304,16 @@ module.exports = class BemEntityName {
313
304
/**
314
305
* Determines whether specified entity is instance of BemEntityName.
315
306
*
316
- * @param {BemEntityName } entityName - the entity to check.
317
- *
318
- * @returns {boolean } A Boolean indicating whether or not specified entity is instance of BemEntityName.
319
307
* @example
320
308
* const BemEntityName = require('@bem/entity-name');
321
309
*
322
310
* const entityName = new BemEntityName({ block: 'input' });
323
311
*
324
312
* BemEntityName.isBemEntityName(entityName); // true
325
313
* BemEntityName.isBemEntityName({}); // false
314
+ *
315
+ * @param {* } entityName - the entity to check.
316
+ * @returns {boolean } A Boolean indicating whether or not specified entity is instance of BemEntityName.
326
317
*/
327
318
static isBemEntityName ( entityName ) {
328
319
return entityName && entityName . __isBemEntityName__ ;
@@ -331,24 +322,15 @@ module.exports = class BemEntityName {
331
322
/**
332
323
* Creates BemEntityName instance by any object representation.
333
324
*
334
- * @param {object|string } obj — representation of entity name.
335
- * @param {string } obj.block — the block name of entity.
336
- * @param {string } [obj.elem] — the element name of entity.
337
- * @param {object|string } [obj.mod] — the modifier of entity.
338
- * @param {string } [obj.val] - the modifier value of entity. Used if `obj.mod` is a string.
339
- * @param {string } obj.mod.name — the modifier name of entity.
340
- * @param {string } [obj.mod.val] — the modifier value of entity.
341
- * @param {string } [obj.modName] — the modifier name of entity. Used if `obj.mod.name` wasn't specified.
342
- * @param {string } [obj.modVal] — the modifier value of entity.
343
- * Used if neither `obj.mod.val` nor `obj.val` were not specified.
344
- *
345
- * @returns {BemEntityName } An object representing entity name.
346
325
* @example
347
326
* const BemEntityName = require('@bem/entity-name');
348
327
*
349
328
* BemEntityName.create({ block: 'my-button', mod: 'theme', val: 'red' });
350
329
* BemEntityName.create({ block: 'my-button', modName: 'theme', modVal: 'red' });
351
330
* // → BemEntityName { block: 'my-button', mod: { name: 'theme', val: 'red' } }
331
+ *
332
+ * @param {(BemSDK.EntityName.NonStrictRepresentation|string) } obj — representation of entity name.
333
+ * @returns {BemEntityName } An object representing entity name.
352
334
*/
353
335
static create ( obj ) {
354
336
if ( BemEntityName . isBemEntityName ( obj ) ) {
@@ -378,4 +360,11 @@ module.exports = class BemEntityName {
378
360
379
361
return new BemEntityName ( data ) ;
380
362
}
381
- } ;
363
+ }
364
+
365
+ module . exports = BemEntityName ;
366
+
367
+ // TypeScript imports the `default` property for
368
+ // an ES2015 default import (`import BemEntityName from '@bem/entity-name'`)
369
+ // See: https://github.com/Microsoft/TypeScript/issues/2242#issuecomment-83694181
370
+ module . exports . default = BemEntityName ;
0 commit comments