Create declaration file .d.ts for extensions submodule

This commit is contained in:
Faisal Salman 2023-11-30 11:12:28 +07:00
parent fdbeabbaed
commit e4f2463849
3 changed files with 21 additions and 5 deletions

View File

@ -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",

View File

@ -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;

View File

@ -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 {
@ -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;