mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
feat(d.ts): add random-useragent type definition (#35493)
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
bd511dccbb
commit
fa6704c2ba
62
types/random-useragent/index.d.ts
vendored
Normal file
62
types/random-useragent/index.d.ts
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
// Type definitions for random-useragent 0.3
|
||||
// Project: https://github.com/skratchdot/random-useragent
|
||||
// Definitions by: Jeffry Angtoni <https://github.com/jeffryang24>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Generated user agent object interface.
|
||||
*/
|
||||
export interface UserAgent {
|
||||
folder: string;
|
||||
description: string;
|
||||
userAgent: string;
|
||||
appCodename: string;
|
||||
appName: string;
|
||||
appVersion: string;
|
||||
platform: string;
|
||||
vendor: string;
|
||||
vendorSub: string;
|
||||
browserName: string;
|
||||
browserMajor: string;
|
||||
browserVersion: string;
|
||||
deviceModel: string;
|
||||
deviceType: string;
|
||||
deviceVendor: string;
|
||||
engineName: string;
|
||||
engineVersion: string;
|
||||
osName: string;
|
||||
osVersion: string;
|
||||
cpuArchitecture: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random user agent string (optionally using a filter).
|
||||
* @param [filter] - An `Array.prototype.filter()` callback function.
|
||||
*/
|
||||
export function getRandom(
|
||||
filter?: (value: UserAgent, index: number, array: UserAgent[]) => boolean
|
||||
): string | null;
|
||||
|
||||
/**
|
||||
* Get a random user agent's parsed data (optionally using a filter).
|
||||
* @param [filter] - An `Array.prototype.filter()` callback function.
|
||||
*/
|
||||
export function getRandomData(
|
||||
filter?: (value: UserAgent, index: number, array: UserAgent[]) => boolean
|
||||
): UserAgent | null;
|
||||
|
||||
/**
|
||||
* Get an array of all the user agent strings (optionally using a filter).
|
||||
* @param [filter] - An `Array.prototype.filter()` callback function.
|
||||
*/
|
||||
export function getAll(
|
||||
filter?: (value: UserAgent, index: number, array: UserAgent[]) => boolean
|
||||
): string[];
|
||||
|
||||
/**
|
||||
* Get an array of all the parsed user agent data (optionally using a filter).
|
||||
* @param [filter] - An `Array.prototype.filter()` callback function.
|
||||
*/
|
||||
export function getAllData(
|
||||
filter?: (value: UserAgent, index: number, array: UserAgent[]) => boolean
|
||||
): UserAgent[];
|
||||
31
types/random-useragent/random-useragent-tests.ts
Normal file
31
types/random-useragent/random-useragent-tests.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import {
|
||||
getAll,
|
||||
getAllData,
|
||||
getRandom,
|
||||
getRandomData,
|
||||
UserAgent
|
||||
} from "random-useragent";
|
||||
|
||||
function filter(value: UserAgent) {
|
||||
return value.browserName !== "Chrome";
|
||||
}
|
||||
|
||||
// $ExpectType string | null
|
||||
getRandom();
|
||||
// $ExpectType string | null
|
||||
getRandom(filter);
|
||||
|
||||
// $ExpectType UserAgent | null
|
||||
getRandomData();
|
||||
// $ExpectType UserAgent | null
|
||||
getRandomData(filter);
|
||||
|
||||
// $ExpectType string[]
|
||||
getAll();
|
||||
// $ExpectType string[]
|
||||
getAll(filter);
|
||||
|
||||
// $ExpectType UserAgent[]
|
||||
getAllData();
|
||||
// $ExpectType UserAgent[]
|
||||
getAllData(filter);
|
||||
16
types/random-useragent/tsconfig.json
Normal file
16
types/random-useragent/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": ["index.d.ts", "random-useragent-tests.ts"]
|
||||
}
|
||||
1
types/random-useragent/tslint.json
Normal file
1
types/random-useragent/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user