/** * Random generate value * * @example * ```javascript * import random from '@antv/dw-random'; * * const name = random.name(); * ``` * * with your own seed * ```javascript * import { Random } from '@antv/dw-random'; * const random = new Random(200); * console.log(random.phone()); * ``` * extend * ```javascript * import { Random } from '@antv/dw-random'; * Random.mixin({ * user() { * return { * name: this.cname(), * aget: this.integer({ max: 50, min: 25 }) * } * } * }) * ``` * * @packageDocumentation */ /** * @public */ export declare type AnyFunc = (...args: any[]) => any; /** * Basic(bool int float regexp) Generater * basic generator for bool int float regexp * @public */ export declare class BasicRandom { /** * extends class's prototype * @param options - methods * * @example * ```javascript * BasiceRandom.mixin({ * percent() { * return `${this.float({ min: 0, max: 100, fixed: 2 })}%`; * }, * }); * * const R = new Random(); * R.percent(); // '10.12%' * R.n(R.percent, 2) // ['12.10%', '25.22%'] * ``` */ static mixin(options: MixinOptions): void; /** * random的逻辑 生成 0-1之内的数字 可以使用 `Math.random` */ random: RandomFunc; /** * MersenneTwister 的 seed */ private readonly seed?; /** * MersenneTwister */ private mt?; constructor(seed?: number); constructor(seed?: RandomFunc); /** * Return a random boolean value (true or false). * @param options - options */ boolean(options?: BooleanOptions): boolean; /** * Reture a random integer * @param options - options */ integer(options?: Interval): number; /** * Genarate a float / double number * * @param options - */ float(options?: FloatOptions): number; /** * generate an integer number * @param options - */ natural(options?: Interval): number; /** * Given an array, pick a random element and return it * @param array - The array to process * */ pickone(array: T[]): T; /** * Given an array, pick some random elements and return them in a new array * @param array - the array to process * @param count - the counts to pick */ pickset(array: T[], count?: number): T[]; /** * Given an array, scramble the order and return it. * @param array - the array to process * @beta */ shuffle(array: T[]): T[]; /** * Provide any function that generates random stuff (usually another generate function) * and a number and n() will generate an array of items with a length matching the length you specified. * @param generator - the generator * @param length - the length * @param params - the generator's params * * @example * ```javascript * const R = new Random(); * R.n(R.natural, 10, { min: 0, max: 100 }); // ten numbers which arn between 0 and 100 * ``` */ n(generator: T, length?: number, ...params: Parameters): ReturnType[]; /** * Generate a string which match regexp * * @example * ```javascript * new Random().randexp('\\d{4}-\\d{8}'); * ``` * * @param source - regexp or source of regexp * @param flag - flag(only support `i`) */ randexp(source: string | RegExp, flag?: string): string; } /** * the params to generate boolean * @public */ export declare interface BooleanOptions { /** likelihood 0-100 */ likelihood?: number; } /** @public */ export declare interface CCharacterOptions { pool?: string; } /** * Generator for address * * @public */ export declare class ChAddressRandom extends BasicRandom { /** * Generate a country name in chainese */ country(): string; /** * Generate a chainese province */ province(): string; /** * return a random chinese city name */ city(): string; /** * return a random chinese district name */ district(): string; /** * return a random chinese road name */ road(): string; /** * return a random chinese address name */ address(): string; /** return a random post code */ postcode(): string; } /** * @public */ export declare interface CharacterOptions { pool?: string; numeric?: boolean; symbols?: boolean; lower?: boolean; upper?: boolean; } /** @public */ export declare interface CLastNameOptions extends Person { length?: number; } /** * database for color generator * @public */ export declare interface ColorDB { colorKeywords: string[]; } /** * Generator for color * @public */ export declare class ColorRandom extends BasicRandom { database: ColorDB; /** * return a rag color */ rgb(options?: RGBOptions): string; /** * return a rag color with alpha */ rgba(optios?: RGBAOptions): string; /** * return a hsl color */ hsl(options?: HSLOptions): string; /** * return a hsl color with alpha */ hsla(options?: HSLAOptions): string; /** * return a {@link https://developer.mozilla.org/en-US/docs/Web/CSS/color_value | Color Keyword} */ colorname(): string; /** * return a hex color * @param options - the parmas */ hexcolor(options?: HexColorOptions): string; /** * return a decimal color * @param options - the parmas */ decimalcolor(options?: RGBBaseOptions): number; } /** @public */ export declare interface CoordinatesOptions { maxLat?: number; minLat?: number; maxLong?: number; minLong?: number; fixed?: number; } /** @public */ export declare interface CWordOption extends CCharacterOptions { length?: number; } /** @public */ export declare interface CZodiacOptions { locale?: string; } /** * Random’s database * @public */ export declare type Database = TextDB & WebDB & ColorDB & DateTimeDB; /** @public database for DateTimeRandom */ export declare interface DateTimeDB { weekday: { [index: string]: any[][]; }; month: { [index: string]: any[][]; }; } /** @public */ export declare interface DateTimeOptions extends Interval { /** the format {@link https://date-fns.org/v2.0.1/docs/format | keyword} */ format?: string; } /** * Generator for date * @public */ export declare class DateTimeRandom extends BasicRandom { /** * return a random date which format is yyyy-MM-dd */ database: DateTimeDB; /** * return a random full date {@link https://tools.ietf.org/html/rfc3339#section-5.6 | full-date} * @param options - the params */ date(options?: Interval): string; /** * return a random full time {@link https://tools.ietf.org/html/rfc3339#section-5.6 | full-time} * @param options - the params */ time(options?: TimeOptions): string; /** * return a random date-time (full-data T fulltime) {@link https://tools.ietf.org/html/rfc3339#section-5.6 | date-time} * * @remarks * {@link https://date-fns.org/v2.0.1/docs/format | format} * @param options - the params */ datetime(options?: DateTimeOptions): string; /** * return a random timestamp * @param options - the params */ timestamp(options: Interval): number; /** * return a random weekday * * @example * ```javascript * new DateTimeRandom().weekday({ locale: 'zh-CN' }) // 星期一 * new DateTimeRandom().weekday({ abbr: true }) // Mon. * ``` * @param options - the params * @beta */ weekday(options?: WeekDayOptions): string; /** * return a random month * * @param options - the params * @beta */ month(options?: MonthOptions): string; } declare const _default: Random; export default _default; /** @public */ export declare interface DomainOptions { tld?: string; } /** @public */ export declare interface EmailOptions { domain?: string; length?: number; } /** * The params to generate a float * @public */ export declare interface FloatOptions extends Interval { /** * precision */ fixed?: number; } /** * @public */ export declare interface HexColorOptions extends RGBOptions { /** has prefix or not `#` */ prefix?: boolean; } /** * @public */ export declare interface HSLAOptions extends HSLBaseOPtions { casing?: 'lower' | 'upper'; minA: number; maxA: number; } /** * the params for hls color * @public */ export declare interface HSLBaseOPtions { minH?: number; maxH?: number; minS?: number; maxS?: number; minL?: number; maxL?: number; } /** * @public */ export declare interface HSLOptions extends HSLBaseOPtions { casing?: 'lower' | 'upper'; } /** * @public */ export declare interface Interval { /** * min */ min?: number; /** * max */ max?: number; } /** * The Generator for location * @public */ export declare class LocationRandom extends BasicRandom { /** * return a random latitude * @param options - the params */ latitude(options?: FloatOptions): number; /** * return a random longtitude * @param options - the params */ longtitude(options?: FloatOptions): number; /** * return a random coordinates * @param options - the params */ coordinates(options?: CoordinatesOptions): string; } /** * @public */ export declare interface MixinOptions { [name: string]: AnyFunc; } /** @public */ export declare interface MonthOptions { locale?: string; abbr?: boolean; } /** @public */ export declare interface ParagraphOptions { /** the counts of sentence in the paragraph */ sentence?: number; } /** @public */ export declare interface Person { /** 性别 */ gender?: 'male' | 'female'; } /** @public */ export declare interface PhoneOptions { /** 是否是手机号码 */ mobile?: boolean; /** 是否格式化 */ formatted?: boolean; } /** * Random constructor * @public */ export declare class Random extends BasicRandom { database: Database; } /** * Random Interface * @public * @remarks {@link BasicRandom} {@link TextRandom} {@link WebRandom} {@link ColorRandom} {@link ChAddressRandom} */ export declare interface Random extends TextRandom, WebRandom, ColorRandom, LocationRandom, DateTimeRandom, ChAddressRandom { /** * 所有database的合并 */ database: Database; } /** @public */ export declare type RandomFunc = () => number; /** * @public */ export declare interface RGBAOptions extends RGBBaseOptions { casing?: 'lower' | 'upper'; minA: number; maxA: number; } /** * * @public */ export declare interface RGBBaseOptions { grayscale?: boolean; min?: number; max?: number; minR?: number; maxR?: number; minG?: number; maxG?: number; minB?: number; maxB?: number; } /** * @public */ export declare interface RGBOptions extends RGBBaseOptions { /** the case */ casing?: 'lower' | 'upper'; } /** @public */ export declare interface SentenceOptions { /** the counts of word */ words?: number; punctuation?: boolean | string; } /** * @public */ export declare interface StringOptions extends CharacterOptions { length?: number; } /** * @public */ export declare interface SyllableOptions { capitalize?: boolean; length?: number; } /** * TextRandom's database * @public */ export declare interface TextDB { character: { lower: string; upper: string; number: string; symbol: string; }; cCharacter: { chars: string; }; syllable: { consonants: string; vowels: string; }; sentence: { punctuations: string; }; hexs: string; cfirst: string[]; clast: any; firstNames: { male: string[]; female: string[]; }; lastNames: string[]; cZodiac: { [lang: string]: string[]; }; } /** * Generator for string * @public */ export declare class TextRandom extends BasicRandom { database: TextDB; /** * Return a random char * * @param options - */ character(options?: CharacterOptions): string; /** * Return a random string * * @param options - * * @public */ string(options?: StringOptions): string; /** * Return a random syllable * @param options - the params * @internal */ syllable(options?: SyllableOptions): string; /** * return a random world * @param options - the params */ word(options?: WordOptions): string; /** * return a random sentence * @param options - the params */ sentence(options?: SentenceOptions): string; /** * return a random paragraph * @param options - the params */ paragraph(options?: ParagraphOptions): string; /** * return a random english name * * @param options - the params */ name(options?: Person): string; /** * return a random english last name */ lastname(): string; /** * return a random english first name * @param options - the params */ firstname(options?: Person): string; /** * return a random chinese name * @param options - the params */ cname(options?: Person): string; /** * return a random chinese first name */ cfirstname(): string; /** * return a random chinese last name * @param options - the params */ clastname(options?: CLastNameOptions): string; /** * return a random chinese character */ ccharacter(options?: CCharacterOptions): string; /** * return a random chinese word * @param options - the params */ cword(options?: CWordOption): string; /** * return a random chinese sentence * @param options - the params */ csentence(options?: Interval): string; /** * return a random chinese paragraph * @param options - the params */ cparagraph(options?: Interval): string; /** * return a random phone number * @param options - the params */ phone(options?: PhoneOptions): string; /** * return a random chinese zodiac * @param options - the params * * @example * ```javascript * const R = new TextRandom(); * const cZodiacCn = R.cZodiac(); // '鼠', '牛', '虎'... * const cZodiacEn = R.cZodiac({ locale: 'en-US' }); // 'Rat','OX','Tiger'... * ``` */ cZodiac(options?: CZodiacOptions): string; } /** @public */ export declare interface TimeOptions extends Interval { /** has the time offset */ short?: boolean; } /** @public */ export declare interface UrlOptions extends DomainOptions { protocol?: string; domain?: string; domainPrefix?: string; path?: string; extensions?: string[]; } /** * database for web generator * @public */ export declare interface WebDB { tld: string[]; } /** * Generator for web * @public */ export declare class WebRandom extends TextRandom { database: WebDB & TextDB; /** * Return a random url * @param options - the params */ url(options?: UrlOptions): string; /** * Return a random domain * @param options - the params */ domain(options?: DomainOptions): string; /** * Return a random ip v4 */ ipv4(): string; /** * Return a random ip v6 */ ipv6(): string; /** * Return a random email * @param options - the params */ email(options?: EmailOptions): string; /** * Return a random top-level domain ({@link https://en.wikipedia.org/wiki/Top-level_domain | TLD}) * @remarks 返回database.tlds的一个 */ tld(): string; } /** @public */ export declare interface WeekDayOptions { locale?: string; abbr?: boolean; } /** * @public */ export declare interface WordOptions { syllables?: number; /** 是否大写第一个字母 */ capitalize?: boolean; /** the length of word */ length?: number; } export { }