From f77d8d6d09da5be3b10f1ae677dda08339372f9b Mon Sep 17 00:00:00 2001 From: Nikita Matrosov Date: Thu, 19 Jan 2017 16:10:44 +0300 Subject: [PATCH] CB-12369: Add plugin typings from DefinitelyTyped This closes #53 --- package.json | 1 + types/index.d.ts | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 types/index.d.ts diff --git a/package.json b/package.json index 3457a51..a87f6cd 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "cordova-plugin-network-information", "version": "1.3.2-dev", "description": "Cordova Network Information Plugin", + "types": "./types/index.d.ts", "cordova": { "id": "cordova-plugin-network-information", "platforms": [ diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..60b6c26 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,62 @@ +// Type definitions for Apache Cordova Network Information plugin +// Project: https://github.com/apache/cordova-plugin-network-information +// Definitions by: Microsoft Open Technologies Inc +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// +// Copyright (c) Microsoft Open Technologies Inc +// Licensed under the MIT license + +interface Navigator { + /** + * This plugin provides an implementation of an old version of the Network Information API. + * It provides information about the device's cellular and wifi connection, and whether the device has an internet connection. + */ + connection: Connection; + // see https://github.com/apache/cordova-plugin-network-information/blob/dev/doc/index.md#api-change + // for + network: { + /** + * This plugin provides an implementation of an old version of the Network Information API. + * It provides information about the device's cellular and wifi connection, and whether the device has an internet connection. + */ + connection: Connection + } +} + +interface Document { + addEventListener(type: "online", connectionStateCallback: () => any, useCapture?: boolean): void; + addEventListener(type: "offline", connectionStateCallback: () => any, useCapture?: boolean): void; +} + +/** + * The connection object, exposed via navigator.connection, provides information + * about the device's cellular and wifi connection. + */ +interface Connection { + /** + * This property offers a fast way to determine the device's network connection state, and type of connection. + * One of: + * Connection.UNKNOWN + * Connection.ETHERNET + * Connection.WIFI + * Connection.CELL_2G + * Connection.CELL_3G + * Connection.CELL_4G + * Connection.CELL + * Connection.NONE + */ + type: string; + addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; + removeEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; +} + +declare var Connection: { + UNKNOWN: string; + ETHERNET: string; + WIFI: string; + CELL_2G: string; + CELL_3G: string; + CELL_4G: string; + CELL: string; + NONE: string; +} \ No newline at end of file