JavaScript library for generating random data and intercepting Ajax requests
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Extensive collection of random data generators for creating realistic fake data including basic types, names, addresses, dates, web data, and more. All functions are accessible through Mock.Random.
Core random data generators for primitive types and basic structures.
/**
* Generate random boolean value
* @param min - Minimum probability weight (default: 1)
* @param max - Maximum probability weight (default: 1)
* @param current - Current value to use for probability calculation
* @returns Random boolean
*/
Mock.Random.boolean(min?: number, max?: number, current?: boolean): boolean;
Mock.Random.bool(min?: number, max?: number, current?: boolean): boolean; // Alias
/**
* Generate random natural number (>= 0)
* @param min - Minimum value (default: 0)
* @param max - Maximum value (default: 9007199254740992)
* @returns Random natural number
*/
Mock.Random.natural(min?: number, max?: number): number;
/**
* Generate random integer
* @param min - Minimum value (default: -9007199254740992)
* @param max - Maximum value (default: 9007199254740992)
* @returns Random integer
*/
Mock.Random.integer(min?: number, max?: number): number;
Mock.Random.int(min?: number, max?: number): number; // Alias
/**
* Generate random floating point number
* @param min - Minimum integer part
* @param max - Maximum integer part
* @param dmin - Minimum decimal places (default: 0)
* @param dmax - Maximum decimal places (default: 17)
* @returns Random float
*/
Mock.Random.float(min?: number, max?: number, dmin?: number, dmax?: number): number;
/**
* Generate random character
* @param pool - Character pool ('lower', 'upper', 'number', 'symbol', or custom string)
* @returns Random character
*/
Mock.Random.character(pool?: string): string;
Mock.Random.char(pool?: string): string; // Alias
/**
* Generate random string
* @param pool - Character pool or length (if number)
* @param min - Minimum length
* @param max - Maximum length
* @returns Random string
*/
Mock.Random.string(pool?: string | number, min?: number, max?: number): string;
Mock.Random.str(pool?: string | number, min?: number, max?: number): string; // Alias
/**
* Generate range of integers
* @param start - Start value
* @param stop - Stop value
* @param step - Step increment (default: 1)
* @returns Array of integers
*/
Mock.Random.range(start: number, stop?: number, step?: number): number[];Basic Examples:
// Boolean values
Mock.Random.boolean(); // true or false
Mock.Random.bool(1, 2, true); // 1:2 ratio for keeping true
// Numbers
Mock.Random.natural(1, 100); // 1 to 100
Mock.Random.integer(-50, 50); // -50 to 50
Mock.Random.float(0, 10, 2, 4); // 0.xx to 10.xxxx
// Characters and strings
Mock.Random.character('lower'); // 'a' to 'z'
Mock.Random.string('number', 6); // '123456'
Mock.Random.string(5, 10); // 5-10 character string
// Ranges
Mock.Random.range(5); // [0, 1, 2, 3, 4]
Mock.Random.range(2, 8, 2); // [2, 4, 6]Generators for dates, times, and formatted datetime strings.
/**
* Generate random date string
* @param format - Date format (default: 'yyyy-MM-dd')
* @returns Formatted date string
*/
Mock.Random.date(format?: string): string;
/**
* Generate random time string
* @param format - Time format (default: 'HH:mm:ss')
* @returns Formatted time string
*/
Mock.Random.time(format?: string): string;
/**
* Generate random datetime string
* @param format - DateTime format (default: 'yyyy-MM-dd HH:mm:ss')
* @returns Formatted datetime string
*/
Mock.Random.datetime(format?: string): string;
/**
* Get current time with optional formatting and unit precision
* @param unit - Time unit for precision ('year', 'month', 'day', 'hour', 'minute', 'second', 'week')
* @param format - Output format (default: 'yyyy-MM-dd HH:mm:ss')
* @returns Formatted current time
*/
Mock.Random.now(unit?: string, format?: string): string;Date Examples:
// Basic dates
Mock.Random.date(); // "2023-05-15"
Mock.Random.time(); // "14:30:22"
Mock.Random.datetime(); // "2023-05-15 14:30:22"
// Custom formats
Mock.Random.date('MM/dd/yyyy'); // "05/15/2023"
Mock.Random.time('HH:mm'); // "14:30"
Mock.Random.datetime('yyyy年MM月dd日'); // "2023年05月15日"
// Current time
Mock.Random.now(); // Current time formatted
Mock.Random.now('day'); // Current day start
Mock.Random.now('month', 'yyyy-MM'); // Current month startGenerators for words, sentences, paragraphs, and titles in English and Chinese.
/**
* Generate random word
* @param min - Minimum length (default: 3)
* @param max - Maximum length (default: 10)
* @returns Random word
*/
Mock.Random.word(min?: number, max?: number): string;
/**
* Generate random sentence
* @param min - Minimum word count (default: 12)
* @param max - Maximum word count (default: 18)
* @returns Random sentence with period
*/
Mock.Random.sentence(min?: number, max?: number): string;
/**
* Generate random paragraph
* @param min - Minimum sentence count (default: 3)
* @param max - Maximum sentence count (default: 7)
* @returns Random paragraph
*/
Mock.Random.paragraph(min?: number, max?: number): string;
/**
* Generate random title
* @param min - Minimum word count (default: 3)
* @param max - Maximum word count (default: 7)
* @returns Random title with capitalized words
*/
Mock.Random.title(min?: number, max?: number): string;
// Chinese text generators
Mock.Random.cword(pool?: string, min?: number, max?: number): string; // Chinese word(s)
Mock.Random.csentence(min?: number, max?: number): string; // Chinese sentence
Mock.Random.cparagraph(min?: number, max?: number): string; // Chinese paragraph
Mock.Random.ctitle(min?: number, max?: number): string; // Chinese titleGenerators for personal names in English and Chinese.
/**
* Generate random first name
* @returns Random first name
*/
Mock.Random.first(): string;
/**
* Generate random last name
* @returns Random last name
*/
Mock.Random.last(): string;
/**
* Generate random full name
* @param middle - Include middle name (default: false)
* @returns Random full name
*/
Mock.Random.name(middle?: boolean): string;
// Chinese name generators
Mock.Random.cfirst(): string; // Chinese first name
Mock.Random.clast(): string; // Chinese last name
Mock.Random.cname(): string; // Chinese full nameGenerators for URLs, domains, emails, and IP addresses.
/**
* Generate random URL
* @param protocol - URL protocol (default: random)
* @param host - Host name (default: random domain)
* @returns Random URL
*/
Mock.Random.url(protocol?: string, host?: string): string;
/**
* Generate random protocol
* @returns Random protocol (http, ftp, etc.)
*/
Mock.Random.protocol(): string;
/**
* Generate random domain
* @param tld - Top-level domain (optional)
* @returns Random domain name
*/
Mock.Random.domain(tld?: string): string;
/**
* Generate random top-level domain
* @returns Random TLD (.com, .org, etc.)
*/
Mock.Random.tld(): string;
/**
* Generate random email address
* @param domain - Email domain (default: random)
* @returns Random email address
*/
Mock.Random.email(domain?: string): string;
/**
* Generate random IP address
* @returns Random IPv4 address
*/
Mock.Random.ip(): string;Generators for geographical locations and addresses.
/**
* Generate random region name
* @returns Random region
*/
Mock.Random.region(): string;
/**
* Generate random province name
* @returns Random province
*/
Mock.Random.province(): string;
/**
* Generate random city name
* @param prefix - Include province prefix
* @returns Random city name
*/
Mock.Random.city(prefix?: boolean): string;
/**
* Generate random county name
* @param prefix - Include city prefix
* @returns Random county name
*/
Mock.Random.county(prefix?: boolean): string;
/**
* Generate random postal/zip code
* @param len - Length of zip code (default: 6)
* @returns Random zip code
*/
Mock.Random.zip(len?: number): string;Generators for color values in various formats.
/**
* Generate random color
* @param name - Named color to return (optional)
* @returns Random color name or specified named color
*/
Mock.Random.color(name?: string): string;
/**
* Generate random hex color
* @returns Random hex color (#rrggbb)
*/
Mock.Random.hex(): string;
/**
* Generate random RGB color
* @returns Random RGB color string
*/
Mock.Random.rgb(): string;
/**
* Generate random RGBA color
* @returns Random RGBA color string
*/
Mock.Random.rgba(): string;
/**
* Generate random HSL color
* @returns Random HSL color string
*/
Mock.Random.hsl(): string;Generators for image URLs and data URIs.
/**
* Generate random image URL
* @param size - Image size (default: random ad size)
* @param background - Background color (default: random)
* @param foreground - Foreground/text color (default: random)
* @param format - Image format (default: 'png')
* @param text - Image text (default: size)
* @returns Random image URL
*/
Mock.Random.image(size?: string, background?: string, foreground?: string, format?: string, text?: string): string;
Mock.Random.img(size?: string, background?: string, foreground?: string, format?: string, text?: string): string; // Alias
/**
* Generate random data URI image (base64 encoded)
* @param size - Image size (default: random ad size)
* @param text - Image text (default: size)
* @returns Random data URI image as base64 string
*/
Mock.Random.dataImage(size?: string, text?: string): string;Helper functions for array manipulation and data transformation.
/**
* Capitalize first letter of string
* @param word - Input string
* @returns Capitalized string
*/
Mock.Random.capitalize(word: string): string;
/**
* Convert string to uppercase
* @param str - Input string
* @returns Uppercase string
*/
Mock.Random.upper(str: string): string;
/**
* Convert string to lowercase
* @param str - Input string
* @returns Lowercase string
*/
Mock.Random.lower(str: string): string;
/**
* Pick random element(s) from array
* @param array - Source array or individual arguments
* @param min - Minimum count (default: 1)
* @param max - Maximum count (default: 1)
* @returns Random element or array of elements
*/
Mock.Random.pick(array: any[] | any, min?: number, max?: number): any;
/**
* Shuffle array elements
* @param array - Array to shuffle
* @returns Shuffled array
*/
Mock.Random.shuffle(array: any[]): any[];Additional generators for IDs, dice rolls, and special values.
// Dice generators
Mock.Random.d4(): number; // 1-4
Mock.Random.d6(): number; // 1-6
Mock.Random.d8(): number; // 1-8
Mock.Random.d12(): number; // 1-12
Mock.Random.d20(): number; // 1-20
Mock.Random.d100(): number; // 1-100
/**
* Generate GUID/UUID
* @returns Random GUID string
*/
Mock.Random.guid(): string;
Mock.Random.uuid(): string; // Alias
/**
* Generate Chinese 18-digit ID card number
* @returns Random Chinese ID card number
*/
Mock.Random.id(): string;
/**
* Generate increment value (auto-incrementing counter)
* @param step - Increment step (default: 1)
* @returns Incremented value
*/
Mock.Random.increment(step?: number): number;
/**
* Alias for increment function
* @param step - Increment step (default: 1)
* @returns Incremented value
*/
Mock.Random.inc(step?: number): number;