Skip to content

Commit

Permalink
Create declaration file .d.ts for extensions submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalman committed Nov 30, 2023
1 parent fdbeabb commit e4f2463
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@
},
"./extensions": {
"require": "./src/extensions/ua-parser-extensions.js",
"import": "./src/extensions/ua-parser-extensions.mjs"
"import": "./src/extensions/ua-parser-extensions.mjs",
"types": "./src/extensions/ua-parser-extensions.d.ts"
},
"./helpers": {
"require": "./src/helpers/ua-parser-helpers.js",
Expand Down
13 changes: 13 additions & 0 deletions src/extensions/ua-parser-extensions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Type definitions for Helpers submodule of UAParser.js v2.0.0-beta.1
// Project: https://github.com/faisalman/ua-parser-js
// Definitions by: Faisal Salman <https://github.com/faisalman>

import type { UAParserExt } from "../main/ua-parser";

export const Apps: UAParserExt;
export const Bots: UAParserExt;
export const CLIs: UAParserExt;
export const ExtraDevices: UAParserExt;
export const Emails: UAParserExt;
export const MediaPlayers: UAParserExt;
export const Modules: UAParserExt;
10 changes: 6 additions & 4 deletions src/main/ua-parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ declare namespace UAParser {
}

type RegexMap = ((RegExp | string | (string | RegExp | Function)[])[])[];
type UAParserProps = 'browser' | 'cpu' | 'device' | 'engine' | 'os';
type UAParserExt = Record<UAParserProps, RegexMap>;

export function UAParser(uastring?: string, extensions?: Record<string, RegexMap>, headers?: Record<string, string>): IResult;
export function UAParser(uastring?: string, extensions?: UAParserExt, headers?: Record<string, string>): IResult;
export function UAParser(uastring?: string, headers?: Record<string, string>): IResult;
export function UAParser(extensions?: Record<string, RegexMap>, headers?: Record<string, string>): IResult;
export function UAParser(extensions?: UAParserExt, headers?: Record<string, string>): IResult;
export function UAParser(headers?: Record<string, string>): IResult;

export class UAParser {
Expand Down Expand Up @@ -84,9 +86,9 @@ declare namespace UAParser {
};
static readonly VERSION: string;

constructor(uastring?: string, extensions?: Record<string, RegexMap>, headers?: Record<string, string>);
constructor(uastring?: string, extensions?: UAParserExt, headers?: Record<string, string>);
constructor(uastring?: string, headers?: Record<string, string>);
constructor(extensions?: Record<string, RegexMap>, headers?: Record<string, string>);
constructor(extensions?: UAParserExt, headers?: Record<string, string>);
constructor(headers?: Record<string, string>);

getUA(): string;
Expand Down

0 comments on commit e4f2463

Please sign in to comment.