From 12f7d2809dfa8e5da27c281a521a91f2acdc1c39 Mon Sep 17 00:00:00 2001 From: Alexander Abashkin Date: Tue, 14 Mar 2017 17:00:06 +0300 Subject: [PATCH 1/3] Added module declaration --- platform/index.d.ts | 23 ++++++++++++----------- platform/platform-tests.ts | 8 +++----- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/platform/index.d.ts b/platform/index.d.ts index c02615b932..ad6100c707 100644 --- a/platform/index.d.ts +++ b/platform/index.d.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -interface PlatformStatic { +interface Platform { description?: string; layout?: string; manufacturer?: string; @@ -13,18 +13,19 @@ interface PlatformStatic { product?: string; ua?: string; version?: string; - os?: PlatformOS; - parse?(ua: string): PlatformStatic; + os?: { + architecture?: number; + family?: string; + version?: string; + toString(): string; + }; + parse?(ua: string): Platform; toString?(): string; } -interface PlatformOS { - architecture?: number; //platform's docs say this is a string, but their code doesn't agree - family?: string; - version?: string; - toString(): string; +declare var platform: Platform; + +declare module "platform" { + export = platform; } -declare var platform: PlatformStatic; - - diff --git a/platform/platform-tests.ts b/platform/platform-tests.ts index ce24ada335..572e85830c 100644 --- a/platform/platform-tests.ts +++ b/platform/platform-tests.ts @@ -1,7 +1,5 @@ - - interface ITestContainer { - [name: string]: PlatformStatic; + [name: string]: Platform; } @@ -40,8 +38,8 @@ var tests: ITestContainer = { function runTests() { - var t: PlatformStatic; - var p: PlatformStatic; + var t: Platform; + var p: Platform; var x: string; var px: any; var res: boolean; From 023bcf3e7ae33cac5fc278cfd415683d4297f5a6 Mon Sep 17 00:00:00 2001 From: Alexander Abashkin Date: Tue, 14 Mar 2017 17:55:00 +0300 Subject: [PATCH 2/3] =?UTF-8?q?Platform=20=E2=80=94=20Fixed=20declarations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/index.d.ts | 9 ++++----- platform/platform-tests.ts | 34 ++++++++++++++-------------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/platform/index.d.ts b/platform/index.d.ts index ad6100c707..eed60394f4 100644 --- a/platform/index.d.ts +++ b/platform/index.d.ts @@ -1,10 +1,9 @@ -// Type definitions for Platform 1.0.0 +// Type definitions for Platform 1.3 // Project: https://github.com/bestiejs/platform.js // Definitions by: Jake Hickman // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -interface Platform { +declare interface Platform { description?: string; layout?: string; manufacturer?: string; @@ -23,9 +22,9 @@ interface Platform { toString?(): string; } -declare var platform: Platform; - declare module "platform" { + declare var platform: Platform; + export = platform; } diff --git a/platform/platform-tests.ts b/platform/platform-tests.ts index 572e85830c..65433ffb13 100644 --- a/platform/platform-tests.ts +++ b/platform/platform-tests.ts @@ -1,9 +1,8 @@ -interface ITestContainer { +interface TestContainer { [name: string]: Platform; } - -var tests: ITestContainer = { +var tests: TestContainer = { 'Chrome Mobile 16.0.912.77 on Android 4.0.3': { description: "Chrome Mobile 16.0.912.77 on Android 4.0.3", layout: "WebKit", @@ -45,34 +44,29 @@ function runTests() { var res: boolean; var onFalse: (name: string) => () => any; - for (var n in tests) { - + for (const [n, value] of Object.entries(tests)) { t = tests[n]; p = platform.parse(t.ua); - onFalse = (name: string) => { return () => { console.log('\tfailed on prop "' + name + '" for "' + n + '"'); - } - } + }; + }; console.log('Starting tests for: ' + n); - falsy(() => { return t.description === p.description }, onFalse('description')); - falsy(() => { return t.layout === p.layout }, onFalse('layout')); - falsy(() => { return t.name === p.name }, onFalse('name')); - falsy(() => { return t.prerelease === p.prerelease }, onFalse('prerelease')); - falsy(() => { return t.ua === p.ua }, onFalse('ua')); - falsy(() => { return t.version === p.version }, onFalse('version')); - - falsy(() => { return t.os.architecture === p.os.architecture }, onFalse('os.architecture')); - falsy(() => { return t.os.family === p.os.family }, onFalse('os.family')); - falsy(() => { return t.os.version === p.os.version }, onFalse('os.version')); + falsy(() => t.description === p.description, onFalse('description')); + falsy(() => t.layout === p.layout, onFalse('layout')); + falsy(() => t.name === p.name, onFalse('name')); + falsy(() => t.prerelease === p.prerelease, onFalse('prerelease')); + falsy(() => t.ua === p.ua, onFalse('ua')); + falsy(() => t.version === p.version, onFalse('version')); + falsy(() => t.os.architecture === p.os.architecture, onFalse('os.architecture')); + falsy(() => t.os.family === p.os.family, onFalse('os.family')); + falsy(() => t.os.version === p.os.version, onFalse('os.version')); console.log('Finished tests for: ' + n); - - } } From bb8dfc6c4744926ef38245fb85cb6186f1100b49 Mon Sep 17 00:00:00 2001 From: Alexander Abashkin Date: Tue, 14 Mar 2017 18:01:18 +0300 Subject: [PATCH 3/3] =?UTF-8?q?Platform=20=E2=80=94=20Fixed=20declarations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/index.d.ts | 4 ++-- platform/tsconfig.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/index.d.ts b/platform/index.d.ts index eed60394f4..fd995a085e 100644 --- a/platform/index.d.ts +++ b/platform/index.d.ts @@ -22,9 +22,9 @@ declare interface Platform { toString?(): string; } -declare module "platform" { - declare var platform: Platform; +declare var platform: Platform; +declare module "platform" { export = platform; } diff --git a/platform/tsconfig.json b/platform/tsconfig.json index c7a29f12be..2efb10866a 100644 --- a/platform/tsconfig.json +++ b/platform/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6", + "es2017", "dom" ], "noImplicitAny": true,