From 2e787df3c786cafdcdb11d98fe882c527bd6584e Mon Sep 17 00:00:00 2001 From: Zhang Yi Jiang Date: Tue, 12 Feb 2019 16:23:30 +0800 Subject: [PATCH] Add types for json2mq --- types/json2mq/index.d.ts | 14 ++++++++++++++ types/json2mq/json2mq-tests.ts | 25 +++++++++++++++++++++++++ types/json2mq/tsconfig.json | 23 +++++++++++++++++++++++ types/json2mq/tslint.json | 1 + 4 files changed, 63 insertions(+) create mode 100644 types/json2mq/index.d.ts create mode 100644 types/json2mq/json2mq-tests.ts create mode 100644 types/json2mq/tsconfig.json create mode 100644 types/json2mq/tslint.json diff --git a/types/json2mq/index.d.ts b/types/json2mq/index.d.ts new file mode 100644 index 0000000000..4efae7d889 --- /dev/null +++ b/types/json2mq/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for json2mq 0.2 +// Project: https://github.com/akiran/json2mq +// Definitions by: Zhang Yi Jiang +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = json2mq; + +declare function json2mq(query: json2mq.QueryObject | json2mq.QueryObject[]): string; + +declare namespace json2mq { + interface QueryObject { + [property: string]: string | number | boolean; + } +} diff --git a/types/json2mq/json2mq-tests.ts b/types/json2mq/json2mq-tests.ts new file mode 100644 index 0000000000..6a8baa81af --- /dev/null +++ b/types/json2mq/json2mq-tests.ts @@ -0,0 +1,25 @@ +import * as json2mq from 'json2mq'; + +json2mq({ screen: true }); // -> 'screen' + +json2mq({ handheld: false }); // -> 'not handheld' + +json2mq({ minWidth: 100, maxWidth: 200 }); +// -> '(min-width: 100px) and (max-width: 200px)' + +json2mq({ minWidth: 100, maxWidth: '20em' }); +// -> '(min-width: 100px) and (max-width: 20em)' + +json2mq([{ screen: true, minWidth: 100 }, { handheld: true, orientation: 'landscape' }]); +// -> 'screen and (min-width: 100px), handheld and (orientation: landscape)' + +json2mq({ all: true, monochrome: true }); +// -> 'all and monochrome' + +// Test QueryObject +const mediaQuery: json2mq.QueryObject = { + screen: true, + monochrome: false, + maxWidth: 200, + minHeight: '10rem', +}; diff --git a/types/json2mq/tsconfig.json b/types/json2mq/tsconfig.json new file mode 100644 index 0000000000..c4b51247a8 --- /dev/null +++ b/types/json2mq/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", + "json2mq-tests.ts" + ] +} diff --git a/types/json2mq/tslint.json b/types/json2mq/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/json2mq/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }