UNPKG

@makerx/ts-dossier

Version:

A support library to facilitate the easy creation of builders for use with an Object-Mother test pattern in TypeScript

193 lines (192 loc) 5.12 kB
/** * Generates a random number between 0 or [Number.MIN_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER) when `allowNegative` is set * and [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER). * * ```typescript * const unsignedNumber = randomNumber() * const signedNumber = randomNumber(true) * ``` * @param {boolean} [allowNegative=false] A flag to allow negative numbers. */ export declare function randomNumber(allowNegative?: boolean): number; /** * Generates a random number between `min` and `max`. * * ```typescript * const number = randomNumber(10, 20) * ``` * * @param {number} min The minimum (inclusive). * @param {number} max The maximum (inclusive). */ export declare function randomNumberBetween(min: number, max: number): number; /** * Generates a float between `min` and `max`. * * ```typescript * const number = randomFloatBetween(10, 20) * ``` * @param {number} min The minimum (inclusive). * @param {number} max The maximum (inclusive). * @param {number} [decimals] The maximum amount of decimals. */ export declare function randomFloatBetween(min: number, max: number, decimals?: number): number; /** * Generates a random string with a length between `min` and `max`. * * ```typescript * const string = randomString(5, 10) * ``` * * @param {number} min The minimum length (inclusive). * @param {number} max The maximum length (inclusive). */ export declare function randomString(min: number, max: number): string; /** * Generates a cryptographically random UUID in the form of 00000000-0000-0000-0000-000000000000. * * ```typescript * const id = randomId() * ``` */ export declare function randomId(): string; export declare const randomDateRangeMin: Date; export declare const randomDateRangeMax: Date; /** * Generates a random date between {@linkplain randomDateRangeMin} and {@linkplain randomDateRangeMax}. * * ```typescript * const date = randomDate() * ``` */ export declare function randomDate(): Date; /** * Generates a random date between `min` and `max`. * * ```typescript * const date = randomDateBetween(new Date(2001, 1, 1), new Date(2030, 1, 1)) * ``` * * @param {Date} min The minimum date (inclusive). * @param {Date} max The maximum date (inclusive). */ export declare function randomDateBetween(min: Date, max: Date): Date; /** * Generates a random bool `true` or `false` * * ```typescript * const bool = randomBoolean() * ``` */ export declare function randomBoolean(): boolean; /** * Resets the incremented counters set when called by {@linkplain incrementedNumber}. */ export declare function resetIncrementedNumbers(): void; /** * Returns an incremented number or zero if be called with the `key` for the first time. * * ```typescript * let countKey1 = incrementedNumber('key1') * countKey1 = incrementedNumber('key1') * console.log(countKey1) // Outputs 1 * * const countKey2 = incrementedNumber('key2') * console.log(countKey2) // Outputs 0 * ``` * * @param {string} key The key to track the incremented counter against. */ export declare function incrementedNumber(key: string): number; /** * Returns a random element from the supplied collection. * * ```typescript * const randomElement = randomElement([1, 2, 3, 4, 5]) * ``` * * @param {Array} elements The collection to select a random element from. */ export declare function randomElement<T>(elements: T[]): T; /** * Generates a random "thing's" name. * * ```text * Examples: * * 1. really adorable rock * 2. madly agreeable plant * 3. abnormally adventurous hamburger * ``` * * ```typescript * const name = randomThingName() * ``` */ export declare function randomThingName(): string; /** * Generates a random person's name. * * ```text * Examples: * * 1. James Smith * 2. Mary Johnson * 3. John Williams * 5. Patricia Brown * ``` * * ```typescript * const name = randomPersonName() * ``` */ export declare function randomPersonName(): string; /** * Generates a random email address. * * ```text * Examples: * * 1. really_adorable_rock@gmail.com * 2. madly_agreeable_plant@outlook.com * 3. abnormally_adventurous_hamburger@yahoo.com * ``` * * ```typescript * const name = randomEmail() * ``` */ export declare function randomEmail(): string; /** * Generates a random phone number. * * ```text * Examples: * * 1. 1000000000 * 2. 8974562314 * 3. 9982214305 * ``` * * ```typescript * const phoneNumber = randomPhoneNumber() * ``` * @param {number} [length = 10] The length of the phone number. */ export declare function randomPhoneNumber(length?: number): number; /** * Generates a random url. * * ```text * Examples: * * 1. really-adorable-rock.com * 2. madly-agreeable-plant.com.au * 3. abnormally-adventurous-hamburger.co.uk * ``` * * ```typescript * const name = randomUrl() * ``` */ export declare function randomUrl(): string;