diff --git a/types/enquire.js/enquire.js-tests.ts b/types/enquire.js/enquire.js-tests.ts new file mode 100644 index 0000000000..a11ba053c2 --- /dev/null +++ b/types/enquire.js/enquire.js-tests.ts @@ -0,0 +1,17 @@ +import enquire = require('enquire.js'); + +enquire + .register('(min-width: 300px) and (max-width: 600px)', { + deferSetup: true, + match: () => {}, + unmatch: () => {}, + setup: () => {}, + destroy: () => {} + }) + .register('(min-width: 300px) and (max-width: 600px)', {}); + +enquire.register('(min-width: 300px) and (max-width: 600px)', [{}, {}], true); + +enquire.register('(min-width: 300px) and (max-width: 600px)', () => {}, true); + +enquire.unregister('(min-width: 300px) and (max-width: 600px)'); diff --git a/types/enquire.js/index.d.ts b/types/enquire.js/index.d.ts new file mode 100644 index 0000000000..d7dcafdc30 --- /dev/null +++ b/types/enquire.js/index.d.ts @@ -0,0 +1,43 @@ +// Type definitions for enquire.js 2.1 +// Project: https://github.com/WickyNilliams/enquire.js/ +// Definitions by: Christian Rackerseder +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 + +interface Options { + /** + * If set to true, defers execution of the setup function until the first time the media query is matched + */ + deferSetup?: boolean; + /** + * If supplied, triggered when a media query matches. + */ + match?(): void; + /** + * If supplied, triggered when the media query transitions from a matched state to an unmatched state. + */ + unmatch?(): void; + /** + * If supplied, triggered once, when the handler is registered. + */ + setup?(): void; + + /** + * If supplied, triggered when handler is unregistered. Place cleanup code here + */ + destroy?(): void; +} + +type Callback = () => void; + +interface EnquireJs { + register( + mediaQuery: string, + options: Options | Options[] | Callback, + shouldDegrade?: boolean, + ): EnquireJs; + unregister(mediaQuery: string, handler?: Callback | Options): void; +} + +declare const enquire: EnquireJs; +export = enquire; diff --git a/types/enquire.js/tsconfig.json b/types/enquire.js/tsconfig.json new file mode 100644 index 0000000000..ffbd13d6e2 --- /dev/null +++ b/types/enquire.js/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "enquire.js-tests.ts" + ] +} diff --git a/types/enquire.js/tslint.json b/types/enquire.js/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/enquire.js/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }