1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | declare namespace Chance {
|
13 | type Seed = number | string;
|
14 |
|
15 | interface Seeded {
|
16 | seed: Seed;
|
17 | }
|
18 |
|
19 | interface ChanceStatic {
|
20 | (): Chance;
|
21 | (...seed: Seed[]): Chance;
|
22 | (generator: () => any): Chance;
|
23 |
|
24 | new (): Chance;
|
25 | new (...seed: Seed[]): Chance;
|
26 | new (generator: () => any): Chance;
|
27 | }
|
28 |
|
29 | type FalsyType = false | null | undefined | 0 | typeof NaN | '';
|
30 | interface FalsyOptions {
|
31 | pool: FalsyType[];
|
32 | }
|
33 |
|
34 | interface Chance extends Seeded {
|
35 |
|
36 | bool(opts?: {likelihood: number}): boolean;
|
37 | character(opts?: Partial<CharacterOptions>): string;
|
38 |
|
39 | falsy(ops?: FalsyOptions): FalsyType;
|
40 | floating(opts?: Options): number;
|
41 | integer(opts?: Partial<IntegerOptions>): number;
|
42 | letter(opts?: Options): string;
|
43 | natural(opts?: Options): number;
|
44 | string(opts?: Partial<StringOptions>): string;
|
45 | template(template: string): string;
|
46 |
|
47 |
|
48 | paragraph(opts?: Options): string;
|
49 | sentence(opts?: Partial<SentenceOptions>): string;
|
50 | syllable(opts?: Options): string;
|
51 | word(opts?: Partial<WordOptions>): string;
|
52 |
|
53 |
|
54 | age(opts?: Options): number;
|
55 | gender(): string;
|
56 | birthday(): Date;
|
57 | birthday(opts?: Options): Date | string;
|
58 | cf(opts?: Options): string;
|
59 | cpf(opts?: { formatted: boolean }): string;
|
60 | first(opts?: Partial<FirstNameOptions>): string;
|
61 | last(opts?: LastNameOptions): string;
|
62 | name(opts?: Partial<NameOptions>): string;
|
63 | name_prefix(opts?: Partial<PrefixOptions>): string;
|
64 | name_suffix(opts?: SuffixOptions): string;
|
65 | prefix(opts?: Partial<PrefixOptions>): string;
|
66 | ssn(opts?: Options): string;
|
67 | suffix(opts?: SuffixOptions): string;
|
68 |
|
69 |
|
70 | animal(opts?: Options): string;
|
71 |
|
72 |
|
73 | android_id(): string;
|
74 | apple_token(): string;
|
75 | bb_pin(): string;
|
76 | wp7_anid(): string;
|
77 | wp8_anid2(): string;
|
78 |
|
79 |
|
80 | avatar(opts?: Options): string;
|
81 | color(opts?: Options): string;
|
82 | company(): string;
|
83 | domain(opts?: Options): string;
|
84 | email(opts?: Partial<EmailOptions>): string;
|
85 | fbid(): string;
|
86 | google_analytics(): string;
|
87 | hashtag(): string;
|
88 | ip(): string;
|
89 | ipv6(): string;
|
90 | klout(): string;
|
91 | profession(opts?: Options): string;
|
92 | tld(): string;
|
93 | twitter(): string;
|
94 | url(opts?: Partial<UrlOptions>): string;
|
95 | mac_address(opts?: Partial<MacOptions>): string;
|
96 |
|
97 |
|
98 | address(opts?: Options): string;
|
99 | altitude(opts?: Options): number;
|
100 | areacode(): string;
|
101 | city(): string;
|
102 | coordinates(opts?: Options): string;
|
103 | country(opts?: Options): string;
|
104 | depth(opts?: Options): number;
|
105 | geohash(opts?: Options): string;
|
106 | latitude(opts?: Options): number;
|
107 | locale(opts?: {region: true}): string;
|
108 | locales(opts?: {region: true}): string[];
|
109 | longitude(opts?: Options): number;
|
110 | phone(opts?: Options): string;
|
111 | postcode(): string;
|
112 | postal(): string;
|
113 | province(opts?: Options): string;
|
114 | state(opts?: Options): string;
|
115 | street(opts?: Options): string;
|
116 | zip(opts?: Options): string;
|
117 |
|
118 |
|
119 | ampm(): string;
|
120 | date(): Date;
|
121 | date(opts: DateOptions): Date | string;
|
122 | hammertime(): number;
|
123 | hour(opts?: Options): number;
|
124 | millisecond(): number;
|
125 | minute(): number;
|
126 | month(): string;
|
127 | month(opts: Options): Month;
|
128 | second(): number;
|
129 | timestamp(): number;
|
130 | timezone(): Timezone;
|
131 | weekday(opts: Options): 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday';
|
132 | year(opts?: Options): string;
|
133 |
|
134 |
|
135 | cc(opts?: Options): string;
|
136 | cc_type(): string;
|
137 | cc_type(opts: Options): string | CreditCardType;
|
138 | currency(): Currency;
|
139 | currency_pair(): [Currency, Currency];
|
140 | dollar(opts?: Options): string;
|
141 | euro(opts?: Options): string;
|
142 | exp(): string;
|
143 | exp(opts: Options): string | CreditCardExpiration;
|
144 | exp_month(opts?: Options): string;
|
145 | exp_year(opts?: Options): string;
|
146 |
|
147 |
|
148 | capitalize(str: string): string;
|
149 | mixin(desc: MixinDescriptor): any;
|
150 | pad(num: number, width: number, padChar?: string): string;
|
151 | |
152 |
|
153 |
|
154 | pick<T>(arr: T[]): T;
|
155 | pickone<T>(arr: T[]): T;
|
156 | |
157 |
|
158 |
|
159 | pick<T>(arr: T[], count: number): T[];
|
160 | pickset<T>(arr: T[], count?: number): T[];
|
161 | set: Setter;
|
162 | shuffle<T>(arr: T[]): T[];
|
163 |
|
164 |
|
165 | coin(): string;
|
166 | d4(): number;
|
167 | d6(): number;
|
168 | d8(): number;
|
169 | d10(): number;
|
170 | d12(): number;
|
171 | d20(): number;
|
172 | d30(): number;
|
173 | d100(): number;
|
174 | guid(options?: { version: 4 | 5 }): string;
|
175 | hash(opts?: Options): string;
|
176 | n<T>(generator: () => T, count: number): T[];
|
177 | n<T, O extends Options>(generator: (options: O) => T, count: number, options: O): T[];
|
178 | normal(opts?: Options): number;
|
179 | radio(opts?: Options): string;
|
180 | rpg(dice: string): number[];
|
181 | rpg(dice: string, opts?: Options): number[] | number;
|
182 | tv(opts?: Options): string;
|
183 | unique<T>(generator: () => T, count: number): T[];
|
184 | unique<T, O extends UniqueOptions<T>>(generator: (options: O) => T, count: number, options: O): T[];
|
185 | weighted<T>(values: T[], weights: number[]): T;
|
186 |
|
187 | // "Hidden"
|
188 | cc_types(): CreditCardType[];
|
189 | mersenne_twister(seed?: Seed): any; // API return type not defined in docs
|
190 | months(): Month[];
|
191 | name_prefixes(): Name[];
|
192 | provinces(): Name[];
|
193 | states(): Name[];
|
194 | street_suffix(): Name;
|
195 | street_suffixes(): Name[];
|
196 | }
|
197 |
|
198 | // A more rigorous approach might be to produce
|
199 | // the correct options interfaces for each method
|
200 | interface Options {
|
201 | [id: string]: any;
|
202 | }
|
203 |
|
204 | interface WordOptions {
|
205 | length: number;
|
206 | syllables: number;
|
207 | capitalize: boolean;
|
208 | }
|
209 |
|
210 | interface CharacterOptions {
|
211 | casing: 'upper' | 'lower';
|
212 | pool: string;
|
213 | alpha: boolean;
|
214 | numeric: boolean;
|
215 | symbols: boolean;
|
216 | }
|
217 |
|
218 | type StringOptions = CharacterOptions & { length: number } ;
|
219 |
|
220 | interface UrlOptions {
|
221 | protocol: string;
|
222 | domain: string;
|
223 | domain_prefix: string;
|
224 | path: string;
|
225 | extensions: string[];
|
226 | }
|
227 |
|
228 | interface MacOptions {
|
229 | separator: string;
|
230 | networkVersion: boolean;
|
231 | }
|
232 |
|
233 | interface IntegerOptions {
|
234 | min: number;
|
235 | max: number;
|
236 | }
|
237 |
|
238 | type FirstNameNationalities = 'en' | 'it';
|
239 | type LastNameNationalities = FirstNameNationalities | 'nl' | 'uk' | 'de' | 'jp' | 'es' | 'fr' | '*';
|
240 |
|
241 | interface FullNameOptions {
|
242 | middle: boolean;
|
243 | middle_initial: boolean;
|
244 | prefix: boolean;
|
245 | suffix: boolean;
|
246 | }
|
247 |
|
248 | interface FirstNameOptions {
|
249 | gender: 'male' | 'female';
|
250 | nationality: FirstNameNationalities;
|
251 | }
|
252 |
|
253 | interface LastNameOptions {
|
254 | nationality: LastNameNationalities;
|
255 | }
|
256 |
|
257 | interface SuffixOptions {
|
258 | full: boolean;
|
259 | }
|
260 |
|
261 | type PrefixOptions = { gender: 'male' | 'female' | 'all' } & SuffixOptions;
|
262 |
|
263 | type NameOptions = FullNameOptions & FirstNameOptions & LastNameOptions & PrefixOptions;
|
264 |
|
265 | interface EmailOptions {
|
266 | length: number;
|
267 | domain: string;
|
268 | }
|
269 |
|
270 | interface SentenceOptions {
|
271 | words: number;
|
272 | punctuation: '.' | '?' | ';' | '!' | ':' | boolean;
|
273 | }
|
274 |
|
275 | interface DateOptions {
|
276 | string?: boolean | undefined;
|
277 | american?: boolean | undefined;
|
278 | year?: number | undefined;
|
279 | month?: number | undefined;
|
280 | day?: number | undefined;
|
281 | min?: Date | undefined;
|
282 | max?: Date | undefined;
|
283 | }
|
284 |
|
285 | type UniqueOptions<T> = { comparator?: ((array: T[], value: T) => boolean) | undefined } & Options;
|
286 |
|
287 | interface Month {
|
288 | name: string;
|
289 | short_name: string;
|
290 | numeric: string;
|
291 | }
|
292 |
|
293 | interface CreditCardType {
|
294 | name: string;
|
295 | short_name: string;
|
296 | prefix: string;
|
297 | length: number;
|
298 | }
|
299 |
|
300 | interface Currency {
|
301 | code: string;
|
302 | name: string;
|
303 | }
|
304 |
|
305 | interface CreditCardExpiration {
|
306 | month: string;
|
307 | year: string;
|
308 | }
|
309 |
|
310 | interface MixinDescriptor {
|
311 | [id: string]: (...args: any[]) => any;
|
312 | }
|
313 |
|
314 | interface Setter {
|
315 | (key: "firstNames", values: string[]): any;
|
316 | (key: "lastNames", values: string[]): any;
|
317 | (key: "provinces", values: string[]): any;
|
318 | (key: "us_states_and_dc", values: string[]): any;
|
319 | (key: "territories", values: string[]): any;
|
320 | (key: "armed_forces", values: string[]): any;
|
321 | (key: "street_suffixes", values: string[]): any;
|
322 | (key: "months", values: string[]): any;
|
323 | (key: "cc_types", values: string[]): any;
|
324 | (key: "currency_types", values: string[]): any;
|
325 | <T>(key: string, values: T[]): any;
|
326 | }
|
327 |
|
328 | interface Name {
|
329 | name: string;
|
330 | abbreviation: string;
|
331 | }
|
332 |
|
333 | interface Timezone {
|
334 | name: string;
|
335 | abbr: string;
|
336 | offset: number;
|
337 | isdst: boolean;
|
338 | text: string;
|
339 | utc: string[];
|
340 | }
|
341 | }
|
342 |
|
343 | declare module "chance" {
|
344 | interface ExportedChance extends Chance.ChanceStatic {
|
345 | Chance: ExportedChance;
|
346 | }
|
347 | var Chance: ExportedChance;
|
348 |
|
349 | export = Chance;
|
350 | }
|