Add types for json2mq

This commit is contained in:
Zhang Yi Jiang 2019-02-12 16:23:30 +08:00
parent 5f59f3dc7a
commit 2e787df3c7
4 changed files with 63 additions and 0 deletions

14
types/json2mq/index.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
// Type definitions for json2mq 0.2
// Project: https://github.com/akiran/json2mq
// Definitions by: Zhang Yi Jiang <https://github.com/ZhangYiJiang>
// 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;
}
}

View File

@ -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',
};

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }