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 }); + } diff --git a/ua-parser-js/ua-parser-js.d.ts b/ua-parser-js/ua-parser-js.d.ts index 5ac748dcf..4eea1b322 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,96 @@ 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 (); - - /** - * Create a new parser with UA prepopulated - */ - constructor (ua: string); + /** + * Returns parse result + */ + getResult(): UAParser.IResult; + + /** + * Create a new parser with UA prepopulated and extensions extended + */ + constructor(uastring?: string, extensions?: any); + } + }