fingerprint-oss
Version:
A comprehensive JavaScript library for device fingerprinting and system information collection. Provides robust, deterministic fingerprinting for web applications with privacy-conscious design.
215 lines (214 loc) • 6.07 kB
TypeScript
export interface BrowserDetails {
name?: string;
version?: string;
}
export interface OSDetails {
name?: string;
version?: string;
versionName?: string;
}
export interface PlatformDetails {
type?: string;
vendor?: string;
model?: string;
}
export interface EngineDetails {
name?: string;
version?: string;
}
export interface ParsedResult {
browser: BrowserDetails;
os: OSDetails;
platform: PlatformDetails;
engine: EngineDetails;
}
/**
* The main class that arranges the whole parsing process.
*/
declare class Parser {
private _ua;
parsedResult: ParsedResult;
/**
* Create instance of Parser
*
* @param {String} UA User-Agent string
* @param {Boolean} [skipParsing=false] parser can skip parsing in purpose of performance
* improvements if you need to make a more particular parsing
* like {@link Parser#parseBrowser} or {@link Parser#parsePlatform}
*
* @throw {Error} in case of empty UA String
*
* @constructor
*/
constructor(UA: string, skipParsing?: boolean);
/**
* Get UserAgent string of current Parser instance
* @return {String} User-Agent String of the current <Parser> object
*
* @public
*/
getUA(): string;
/**
* Test a UA string for a regexp
* @param {RegExp} regex
* @return {Boolean}
*/
test(regex: RegExp): boolean;
/**
* Get parsed browser object
* @return {Object}
*/
parseBrowser(): BrowserDetails;
/**
* Get parsed browser object
* @return {Object}
*
* @public
*/
getBrowser(): BrowserDetails;
/**
* Get browser's name
* @return {String} Browser's name or an empty string
*
* @public
*/
getBrowserName(toLowerCase?: boolean): string;
/**
* Get browser's version
* @return {String} version of browser
*
* @public
*/
getBrowserVersion(): string | undefined;
/**
* Get OS
* @return {Object}
*
* @example
* this.getOS();
* {
* name: 'macOS',
* version: '10.11.12'
* }
*/
getOS(): OSDetails;
/**
* Parse OS and save it to this.parsedResult.os
* @return {*|{}}
*/
parseOS(): OSDetails;
/**
* Get OS name
* @param {Boolean} [toLowerCase] return lower-cased value
* @return {String} name of the OS — macOS, Windows, Linux, etc.
*/
getOSName(toLowerCase?: boolean): string;
/**
* Get OS version
* @return {String} full version with dots ('10.11.12', '5.6', etc)
*/
getOSVersion(): string | undefined;
/**
* Get parsed platform
* @return {{}}
*/
getPlatform(): PlatformDetails;
/**
* Get platform name
* @param {Boolean} [toLowerCase=false]
* @return {*}
*/
getPlatformType(toLowerCase?: boolean): string;
/**
* Get parsed platform
* @return {{}}
*/
parsePlatform(): PlatformDetails;
/**
* Get parsed engine
* @return {{}}
*/
getEngine(): EngineDetails;
/**
* Get engines's name
* @return {String} Engines's name or an empty string
*
* @public
*/
getEngineName(toLowerCase?: boolean): string;
/**
* Get parsed platform
* @return {{}}
*/
parseEngine(): EngineDetails;
/**
* Parse full information about the browser
* @returns {Parser}
*/
parse(): Parser;
/**
* Get parsed result
* @return {ParsedResult}
*/
getResult(): ParsedResult;
/**
* Check if parsed browser matches certain conditions
*
* @param {Object} checkTree It's one or two layered object,
* which can include a platform or an OS on the first layer
* and should have browsers specs on the bottom-laying layer
*
* @returns {Boolean|undefined} Whether the browser satisfies the set conditions or not.
* Returns `undefined` when the browser is no described in the checkTree object.
*
* @example
* const browser = Bowser.getParser(window.navigator.userAgent);
* if (browser.satisfies({chrome: '>118.01.1322' }))
* // or with os
* if (browser.satisfies({windows: { chrome: '>118.01.1322' } }))
* // or with platforms
* if (browser.satisfies({desktop: { chrome: '>118.01.1322' } }))
*/
satisfies(checkTree: any): boolean | undefined;
/**
* Check if the browser name equals the passed string
* @param {string} browserName The string to compare with the browser name
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
* @returns {boolean}
*/
isBrowser(browserName: string, includingAlias?: boolean): boolean;
compareVersion(version: string): boolean | undefined;
/**
* Check if the OS name equals the passed string
* @param {string} osName The string to compare with the OS name
* @returns {boolean}
*/
isOS(osName: string): boolean;
/**
* Check if the platform type equals the passed string
* @param {string} platformType The string to compare with the platform type
* @returns {boolean}
*/
isPlatform(platformType: string): boolean;
/**
* Check if the engine name equals the passed string
* @param {string} engineName The string to compare with the engine name
* @returns {boolean}
*/
isEngine(engineName: string): boolean;
/**
* Is anything? Check if the browser is called "anything",
* the OS called "anything" or the platform called "anything"
* @param {String} anything
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
* @returns {Boolean}
*/
is(anything: string, includingAlias?: boolean): boolean;
/**
* Check if any of the given values satisfies this.is(anything)
* @param {String[]} anythings
* @returns {Boolean}
*/
some(anythings?: string[]): boolean;
}
export default Parser;