feat(d.ts): add random-useragent type definition (#35493)

This commit is contained in:
Jeffry Angtoni
2019-05-16 02:37:50 +07:00
committed by Nathan Shively-Sanders
parent bd511dccbb
commit fa6704c2ba
4 changed files with 110 additions and 0 deletions

62
types/random-useragent/index.d.ts vendored Normal file
View 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[];

View 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);

View 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"]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }