From d2aaf651963a26c75ae6bc1ac47cc773298b7934 Mon Sep 17 00:00:00 2001 From: Arturas Date: Wed, 27 Jun 2018 00:29:40 +0100 Subject: [PATCH] add polyfill-service types --- types/polyfill-service/index.d.ts | 42 ++++++++++++++++++ .../polyfill-service-tests.ts | 43 +++++++++++++++++++ types/polyfill-service/tsconfig.json | 23 ++++++++++ types/polyfill-service/tslint.json | 1 + 4 files changed, 109 insertions(+) create mode 100644 types/polyfill-service/index.d.ts create mode 100644 types/polyfill-service/polyfill-service-tests.ts create mode 100644 types/polyfill-service/tsconfig.json create mode 100644 types/polyfill-service/tslint.json diff --git a/types/polyfill-service/index.d.ts b/types/polyfill-service/index.d.ts new file mode 100644 index 0000000000..0dbcde2b0e --- /dev/null +++ b/types/polyfill-service/index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for polyfill-service 3.25 +// Project: https://github.com/financial-times/polyfill-service#readme +// Definitions by: Arturas Molcanovas +// 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; + flags: Set; +} + +export interface GetPolyfillsResponse { + [name: string]: PolyfillSpec; +} + +export function listAllPolyfills(): Promise>; + +export function getPolyfillString(options: GetPolyfillsOptions): Promise; + +export function getPolyfills(options: GetPolyfillsOptions): Promise; diff --git a/types/polyfill-service/polyfill-service-tests.ts b/types/polyfill-service/polyfill-service-tests.ts new file mode 100644 index 0000000000..b74bfbd7f7 --- /dev/null +++ b/types/polyfill-service/polyfill-service-tests.ts @@ -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(); + } +}); diff --git a/types/polyfill-service/tsconfig.json b/types/polyfill-service/tsconfig.json new file mode 100644 index 0000000000..c2c1abf8c0 --- /dev/null +++ b/types/polyfill-service/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", + "polyfill-service-tests.ts" + ] +} diff --git a/types/polyfill-service/tslint.json b/types/polyfill-service/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/polyfill-service/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }