diff --git a/types/bem-cn/bem-cn-tests.ts b/types/bem-cn/bem-cn-tests.ts new file mode 100644 index 0000000000..d57e138777 --- /dev/null +++ b/types/bem-cn/bem-cn-tests.ts @@ -0,0 +1,46 @@ +import * as block from "bem-cn"; + +// expected 'block' +block("block")(); + +// expected 'block__elem' +block("block")("elem")(); + +// expected 'block__elem block__elem_disabled block__elem_size_small' +block("block")("elem", { disabled: true, size: 'small' })(); + +// expected 'block block_disabled' +block("block")({ disabled: true})(); + +// expected 'block mix' +block("block").mix("mix"); + +// expected 'block mix mix2' +block("block").mix(["mix", "mix2"]); + +// expected 'block is-hidden' +block("block").state({ hidden: true }); + +// expected 'block' +block("block").state({ hidden: false }); + +// expected 'block is-hidden is-error' +block("block").state({ hidden: true, error: true }); + +// expected 'block is-loading' +block("block").is({ loading: true }); + +// expected 'block has-content' +block("block").has({ content: true }); + +block.setup({ + el: '~~', + mod: '--', + modValue: '-' +}); + +// expected 'block~~elem' +block("block")("elem"); + +// expected 'block block--mod-value' +block("block")({ mod: "value"}); diff --git a/types/bem-cn/index.d.ts b/types/bem-cn/index.d.ts new file mode 100644 index 0000000000..5a78df4435 --- /dev/null +++ b/types/bem-cn/index.d.ts @@ -0,0 +1,41 @@ +// Type definitions for bem-cn 2.1 +// Project: https://github.com/albburtsev/bem-cn +// Definitions by: Vitaly Selkin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +type StateFn = (states: { [key: string]: boolean }) => Inner; + +interface Modifications { + [key: string]: (string | boolean); +} + +interface Block { + (name: string): Inner; + + reset(): void; + setup(settings?: Settings): void; +} + +interface Inner { + (elem: string | Modifications): Inner; + (elem: string, mods: Modifications): Inner; + (): string; + + mix(mixes: string | string[]): Inner; + has: StateFn; + state: StateFn; + is: StateFn; + toString(): string; + split(separator: string, limit?: number): string[]; +} + +interface Settings { + ns?: string; + el?: string; + mod?: string; + modValue?: string; + classMap?: { [className: string]: string } | null; +} + +declare const block: Block; +export = block; diff --git a/types/bem-cn/tsconfig.json b/types/bem-cn/tsconfig.json new file mode 100644 index 0000000000..a4c2cd86cb --- /dev/null +++ b/types/bem-cn/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "bem-cn-tests.ts" + ] +} diff --git a/types/bem-cn/tslint.json b/types/bem-cn/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/bem-cn/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}