From 48fea977d057c6d777bdc2ac6afad30be74849c2 Mon Sep 17 00:00:00 2001 From: Lucas Woo Date: Thu, 28 Jan 2016 11:07:07 +0800 Subject: [PATCH 1/3] add ua extensions definitions --- ua-parser-js/ua-parser-js.d.ts | 142 ++++++++++++++++++++++----------- 1 file changed, 96 insertions(+), 46 deletions(-) diff --git a/ua-parser-js/ua-parser-js.d.ts b/ua-parser-js/ua-parser-js.d.ts index 5ac748dcf..4d93f66a3 100644 --- a/ua-parser-js/ua-parser-js.d.ts +++ b/ua-parser-js/ua-parser-js.d.ts @@ -1,6 +1,6 @@ -// Type definitions for js-cookie v2.0 +// Type definitions for ua-parser-js v0.7.10 // Project: https://github.com/faisalman/ua-parser-js -// Definitions by: Viktor Miroshnikov +// Definitions by: Viktor Miroshnikov , Lucas Woo // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module UAParser { @@ -61,7 +61,7 @@ declare module UAParser { version: string; } - export interface IOS{ + export interface IOS { /** * Possible 'os.name' * AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS, Contiki, @@ -78,7 +78,7 @@ declare module UAParser { version: string; } - export interface ICPU{ + export interface ICPU { /** * Possible architecture: * 68k, amd64, arm, arm64, avr, ia32, ia64, irix, irix64, mips, mips64, pa-risc, @@ -87,7 +87,7 @@ declare module UAParser { architecture: string; } - export interface IResult{ + export interface IResult { ua: string; browser: IBrowser; device: IDevice; @@ -95,56 +95,106 @@ declare module UAParser { os: IOS; cpu: ICPU; } + + export interface BROWSER { + NAME: string, + + // Deprecated + MAJOR: string, + VERSION: string + } + export interface CPU { + ARCHITECTURE: string + } + + export interface DEVICE { + MODEL: string, + VENDOR: string, + TYPE: string, + CONSOLE: string, + MOBILE: string, + SMARTTV: string, + TABLET: string, + WEARABLE: string, + EMBEDDED: string + } + + export interface ENGINE { + NAME: string, + VERSION: string + } + + export interface OS { + NAME: string, + VERSION: string + } + } -declare class UAParser { - /** - * Returns browser information - */ - getBrowser(): UAParser.IBrowser; - /** - * Returns OS information - */ - getOS(): UAParser.IOS; +declare module "ua-parser-js" { - /** - * Returns browsers engine information - */ - getEngine(): UAParser.IEngine; + export class UAParser { + static VERSION: string; + static BROWSER: UAParser.BROWSER; + static CPU: UAParser.CPU; + static DEVICE: UAParser.DEVICE; + static ENGINE: UAParser.ENGINE; + static OS: UAParser.OS; + + /** + * Returns browser information + */ + getBrowser(): UAParser.IBrowser; + /** + * Returns OS information + */ + getOS(): UAParser.IOS; - /** - * Returns device information - */ - getDevice(): UAParser.IDevice; + /** + * Returns browsers engine information + */ + getEngine(): UAParser.IEngine; - /** - * Returns parsed CPU information - */ - getCPU(): UAParser.ICPU; + /** + * Returns device information + */ + getDevice(): UAParser.IDevice; - /** - * Returns UA string of current instance - */ - getUA(): string; + /** + * Returns parsed CPU information + */ + getCPU(): UAParser.ICPU; - /** - * Set & parse UA string - */ - setUA(ua: string): void; + /** + * Returns UA string of current instance + */ + getUA(): string; - /** - * Returns parse result - */ - getResult(): UAParser.IResult; + /** + * Set & parse UA string + */ + setUA(uastring: string): UAParser; - /** - * Create a new parser - */ - constructor (); + /** + * Returns parse result + */ + getResult(): UAParser.IResult; - /** - * Create a new parser with UA prepopulated - */ - constructor (ua: string); + /** + * Create a new parser + */ + constructor(); + + /** + * Create a new parser with UA prepopulated + */ + constructor(uastring: string); + + /** + * Create a new parser with UA prepopulated and extensions extended + */ + constructor(uastring: string, extensions: any); + } + } From 8284977a966c0d064e91b6548d63718973dac3c3 Mon Sep 17 00:00:00 2001 From: Lucas Woo Date: Thu, 28 Jan 2016 11:07:27 +0800 Subject: [PATCH 2/3] add ua extensions tests --- ua-parser-js/ua-parser-js-tests.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ua-parser-js/ua-parser-js-tests.ts b/ua-parser-js/ua-parser-js-tests.ts index 02ddf1403..7ff2c5db5 100644 --- a/ua-parser-js/ua-parser-js-tests.ts +++ b/ua-parser-js/ua-parser-js-tests.ts @@ -1,6 +1,8 @@ /// -function test_parser(){ +import {UAParser} from 'ua-parser-js'; + +function test_parser() { var ua = 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6'; var parser = new UAParser(ua); var result = parser.getResult(); @@ -41,4 +43,9 @@ function test_parser(){ result.cpu.architecture parser.getCPU().architecture + // Extensions + var uaString = 'ownbrowser/1.3'; + var ownBrowser = [[/(ownbrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]]; + var parser = new UAParser(uaString, { browser: ownBrowser }); + } From 5b84dddc7c9eddd127aaf5f66a5ae20b0346e719 Mon Sep 17 00:00:00 2001 From: Lucas Woo Date: Thu, 28 Jan 2016 12:10:20 +0800 Subject: [PATCH 3/3] remove redundant constructor --- ua-parser-js/ua-parser-js.d.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/ua-parser-js/ua-parser-js.d.ts b/ua-parser-js/ua-parser-js.d.ts index 4d93f66a3..4eea1b322 100644 --- a/ua-parser-js/ua-parser-js.d.ts +++ b/ua-parser-js/ua-parser-js.d.ts @@ -180,21 +180,11 @@ declare module "ua-parser-js" { * Returns parse result */ getResult(): UAParser.IResult; - - /** - * Create a new parser - */ - constructor(); - - /** - * Create a new parser with UA prepopulated - */ - constructor(uastring: string); /** * Create a new parser with UA prepopulated and extensions extended */ - constructor(uastring: string, extensions: any); + constructor(uastring?: string, extensions?: any); } }