add polyfill-service types

This commit is contained in:
Arturas
2018-06-27 00:29:40 +01:00
parent 8c2749435d
commit d2aaf65196
4 changed files with 109 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
// Type definitions for polyfill-service 3.25
// Project: https://github.com/financial-times/polyfill-service#readme
// Definitions by: Arturas Molcanovas <https://github.com/Alorel>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
export type PolyfillFlag = 'gated' | 'always';
export type Unknown = 'polyfill' | 'ignore';
export interface Feature {
flags?: PolyfillFlag[];
}
export interface Features {
[feature: string]: Feature;
}
export interface GetPolyfillsOptions {
uaString: string;
features?: Features;
excludes?: string[];
}
export interface GetPolyfillStringOptions extends GetPolyfillsOptions {
minify?: boolean;
unknown?: Unknown;
}
export interface PolyfillSpec {
aliasOf?: Set<string>;
flags: Set<PolyfillFlag>;
}
export interface GetPolyfillsResponse {
[name: string]: PolyfillSpec;
}
export function listAllPolyfills(): Promise<ReadonlyArray<string>>;
export function getPolyfillString(options: GetPolyfillsOptions): Promise<string>;
export function getPolyfills(options: GetPolyfillsOptions): Promise<GetPolyfillsResponse>;
@@ -0,0 +1,43 @@
import * as svc from 'polyfill-service';
const o: svc.GetPolyfillsOptions = {
uaString: ''
};
o.excludes = ['foo'];
o.features = {
foo: {},
bar: {flags: ['gated', 'always']}
};
const o2: svc.GetPolyfillStringOptions = {
uaString: ''
};
o2.excludes = ['foo'];
o2.features = {
foo: {},
bar: {flags: ['gated', 'always']}
};
o2.minify = true;
o2.minify = false;
o2.unknown = 'polyfill';
o2.unknown = 'ignore';
svc.listAllPolyfills().then(v => {
v[0].toLocaleLowerCase();
});
svc.getPolyfillString(o2).then(s => {
s.toLocaleUpperCase();
});
svc.getPolyfills(o).then(r => {
const p = r.Symbol;
p.flags.clear();
const a = p.aliasOf;
if (a) {
a.clear();
}
});
+23
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",
"polyfill-service-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }