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