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

Commit a97884b

Browse files
authored
Merge pull request #113 from bem-sdk/fix/typings
Fix typings
2 parents 9ac650f + cedd0ea commit a97884b

22 files changed

+110
-115
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ TypeScript support
393393

394394
The package includes [typings](./index.d.ts) for TypeScript. You have to set up transpilation yourself. When you set `module` to `commonjs` in your `tsconfig.json` file, TypeScript will automatically find the type definitions for `@bem/entity-name`.
395395

396-
The interfaces are provided in global namespace `BemSDK.EntityName`. It is necessary to use interfaces in JsDoc.
396+
The interfaces are provided in global namespace `BEMSDK.EntityName`. It is necessary to use interfaces in JsDoc.
397397

398398
Debuggability
399399
-------------

index.d.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
import './globals.d';
2-
3-
declare class BemEntityName {
4-
constructor(obj: BemSDK.EntityName.Options);
5-
6-
readonly block: string;
7-
readonly elem: string | undefined;
8-
readonly mod: BemSDK.EntityName.ModifierRepresentation | undefined;
9-
readonly modName: string | undefined;
10-
readonly modVal: string | true | undefined;
11-
readonly type: BemSDK.EntityName.TYPE;
12-
readonly scope: BemEntityName | null;
13-
readonly id: string;
14-
15-
isSimpleMod(): boolean | null;
16-
isEqual(entityName: BemEntityName): boolean;
17-
belongsTo(entityName: BemEntityName): boolean;
18-
valueOf(): BemSDK.EntityName.StrictRepresentation;
19-
toJSON(): BemSDK.EntityName.StrictRepresentation;
20-
toString(): string;
21-
inspect(depth: number, options: object): string;
22-
23-
static create(obj: BemSDK.EntityName.NonStrictRepresentation | string): BemEntityName;
24-
static isBemEntityName(entityName: any): boolean;
25-
}
1+
import BemEntityName from './types/entity-name.d';
262

273
export = BemEntityName;

jsconfig.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
{
2-
"compilerOptions": {
3-
"target": "ES6",
4-
"module": "commonjs"
5-
},
6-
"files": [
7-
"index.js",
8-
"index.d.ts"
9-
]
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"module": "commonjs"
5+
},
6+
"include": [
7+
"lib",
8+
"types"
9+
],
10+
"exclude": [
11+
"node_modules"
12+
],
13+
"files": [
14+
"index.js",
15+
"index.d.ts"
16+
]
1017
}

lib/entity-name.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const TYPES = {
2222

2323
class BemEntityName {
2424
/**
25-
* @param {BemSDK.EntityName.Options} obj — representation of entity name.
25+
* @param {BEMSDK.EntityName.Options} obj — representation of entity name.
2626
*/
2727
constructor(obj) {
2828
if (!obj.block) {
@@ -61,7 +61,7 @@ class BemEntityName {
6161
*
6262
* name.block; // button
6363
*
64-
* @returns {string} name of entity block.
64+
* @returns {BEMSDK.EntityName.BlockName} name of entity block.
6565
*/
6666
get block() { return this._data.block; }
6767

@@ -76,7 +76,7 @@ class BemEntityName {
7676
*
7777
* name.elem; // text
7878
*
79-
* @returns {?string} - name of entity element.
79+
* @returns {?BEMSDK.EntityName.ElementName} - name of entity element.
8080
*/
8181
get elem() { return this._data.elem; }
8282

@@ -94,7 +94,7 @@ class BemEntityName {
9494
* modName.mod; // { name: 'disabled', val: true }
9595
* blockName.mod; // undefined
9696
*
97-
* @returns {?BemSDK.EntityName.ModifierRepresentation} - entity modifier.
97+
* @returns {?BEMSDK.EntityName.Modifier} - entity modifier.
9898
*/
9999
get mod() { return this._data.mod; }
100100

@@ -103,7 +103,7 @@ class BemEntityName {
103103
*
104104
* If entity is not modifier then returns `undefined`.
105105
*
106-
* @returns {?string} - entity modifier name.
106+
* @returns {?BEMSDK.EntityName.ModifierName} - entity modifier name.
107107
* @deprecated use {@link BemEntityName#mod.name}
108108
*/
109109
get modName() {
@@ -117,7 +117,7 @@ class BemEntityName {
117117
*
118118
* If entity is not modifier then returns `undefined`.
119119
*
120-
* @returns {?(string|true)} - entity modifier name.
120+
* @returns {?BEMSDK.EntityName.ModifierValue} - entity modifier name.
121121
* @deprecated use {@link BemEntityName#mod.val}
122122
*/
123123
get modVal() {
@@ -141,7 +141,7 @@ class BemEntityName {
141141
*
142142
* name.type; // elemMod
143143
*
144-
* @returns {string} - type of entity. One of 'block', 'elem', 'blockMod', 'elemMod'.
144+
* @returns {BEMSDK.EntityName.Type} - type of entity.
145145
*/
146146
get type() {
147147
if (this._type) { return this._type; }
@@ -172,7 +172,7 @@ class BemEntityName {
172172
* buttonTextName.scope; // BemEntityName { block: 'button' }
173173
* buttonTextBoldName.scope; // BemEntityName { block: 'button', elem: 'elem' }
174174
*
175-
* @returns {BemEntityName} - scope entity name.
175+
* @returns {(BemEntityName|null)} - scope entity name.
176176
*/
177177
get scope() {
178178
if (this.type === TYPES.BLOCK) { return null; }
@@ -200,7 +200,7 @@ class BemEntityName {
200200
*
201201
* name.id; // button_disabled
202202
*
203-
* @returns {string} - id of entity.
203+
* @returns {BEMSDK.EntityName.Id} - id of entity.
204204
*/
205205
get id() {
206206
if (this._id) { return this._id; }
@@ -300,7 +300,7 @@ class BemEntityName {
300300
*
301301
* // ➜ { block: 'button', mod: { name: 'focused', value: true } }
302302
*
303-
* @returns {BemSDK.EntityName.StrictRepresentation}
303+
* @returns {BEMSDK.EntityName.Representation}
304304
*/
305305
valueOf() { return this._data; }
306306

@@ -314,7 +314,7 @@ class BemEntityName {
314314
*
315315
* JSON.stringify(name); // {"block":"input","mod":{"name":"available","val":true}}
316316
*
317-
* @returns {BemSDK.EntityName.StrictRepresentation}
317+
* @returns {BEMSDK.EntityName.Representation}
318318
*/
319319
toJSON() {
320320
return this._data;
@@ -373,7 +373,7 @@ class BemEntityName {
373373
* BemEntityName.create({ block: 'my-button', modName: 'theme', modVal: 'red' });
374374
* // → BemEntityName { block: 'my-button', mod: { name: 'theme', val: 'red' } }
375375
*
376-
* @param {(BemSDK.EntityName.NonStrictRepresentation|string)} obj — representation of entity name.
376+
* @param {(BEMSDK.EntityName.CreateOptions|string)} obj — representation of entity name.
377377
* @returns {BemEntityName} An object representing entity name.
378378
*/
379379
static create(obj) {

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"typings": "index.d.ts",
2626
"files": [
2727
"lib/**",
28+
"types/**",
2829
"index.js",
29-
"index.d.ts",
30-
"globals.d.ts"
30+
"index.d.ts"
3131
],
3232
"engines": {
3333
"node": ">= 4.0"
@@ -38,6 +38,7 @@
3838
"es6-error": "4.0.2"
3939
},
4040
"devDependencies": {
41+
"@types/node": "^4.2.5",
4142
"@types/proxyquire": "^1.3.27",
4243
"@types/sinon": "^2.1.2",
4344
"ava": "^0.19.0",
@@ -56,7 +57,7 @@
5657
"test": "nyc ava",
5758
"lint": "npm run lint:js && npm run lint:dts",
5859
"lint:js": "eslint .",
59-
"lint:dts": "tslint **.d.ts",
60+
"lint:dts": "tslint types/*.d.ts",
6061
"coveralls": "nyc report --reporter=text-lcov | coveralls"
6162
},
6263
"ava": {

test/belongs-to.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const test = require('ava');
1+
import test from 'ava';
22

3-
const BemEntityName = require('../lib/entity-name');
3+
import BemEntityName from '..';
44

55
test('should not detect belonging between block and itself', t => {
66
const blockName = new BemEntityName({ block: 'block' });

test/bem-fields.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava';
22

3-
import BemEntityName from '../lib/entity-name';
3+
import BemEntityName from '..';
44

55
test('should provide `block` field', t => {
66
const entityName = new BemEntityName({ block: 'block' });

test/create.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava';
22

3-
import BemEntityName from '../lib/entity-name';
3+
import BemEntityName from '..';
44

55
test('should return object as is if it`s a BemEntityName', t => {
66
const entityName = new BemEntityName({ block: 'block' });

test/deprecate.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const test = require('ava');
2-
const sinon = require('sinon');
3-
const proxyquire = require('proxyquire');
1+
import test from 'ava';
2+
import sinon from 'sinon';
3+
import proxyquire from 'proxyquire';
44

5-
const BemEntityName = require('../lib/entity-name');
5+
import BemEntityName from '..';
66

77
const deprecateSpy = sinon.spy();
88
const deprecate = proxyquire('../lib/deprecate', {

test/entity-type-error.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const test = require('ava');
1+
import test from 'ava';
22

3-
const EntityTypeError = require('../lib/entity-type-error');
3+
import EntityTypeError from '../lib/entity-type-error';
44

55
test('should create type error', t => {
66
const error = new EntityTypeError();

0 commit comments

Comments
 (0)