fake 5.0.0

An easy to use library and command line for generating fake data like name, number, address, lorem, dates, etc.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# Fake

![Rust](https://github.com/cksac/fake-rs/workflows/Rust/badge.svg)
[![Docs Status](https://docs.rs/fake/badge.svg)](https://docs.rs/fake)
[![Latest Version](https://img.shields.io/crates/v/fake.svg)](https://crates.io/crates/fake)

A Rust library and command line tool for generating fake data in different languages. Currently supports:

| Language              | Code  |
|-----------------------|-------|
| English               | en    |
| French                | fr_fr |
| Arabic                | ar_sa |
| Traditional Chinese   | zh_tw |
| Simplified Chinese    | zh_cn |
| Japanese              | ja_jp |
| Portugese (Brazilian) | pt_br |
| Portugese (Portugal)  | pt_pt |
| German                | de_de |
| Italian               | it_it |
| Dutch                 | nl_nl |
| Turkish               | tr_tr |
| Persian (iran)        | fa_ir |


## Installation

### Library:

```toml
[dependencies]
fake = { version = "5", features = ["derive"] }
```

Available library features:

- `derive`: if you want to use `#[derive(Dummy)]`
- supported crates feature flags:
  - `chrono`
  - `chrono-tz`
  - `http`
  - `ulid`
  - `ferroid`
  - `uuid`
  - `bigdecimal` (via `bigdecimal-rs`)
  - `rust_decimal`
  - `random_color`
  - `geo`
  - `semver`
  - `serde_json`
  - `time`
  - `zerocopy`
  - `glam`
  - `url`
  - `indexmap`
  - `either`
- `always-true-rng`: expose AlwaysTrueRng
- `maybe-non-empty-collections`: allow to use AlwaysTrueRng to generate non-empty collections

### CLI:
`cargo install --features=cli --git https://github.com/cksac/fake-rs.git`

Access cli using `fake` command. Below are the currently available fake generators.

```shell
❯ fake
An easy to use library and command line for generating fake data like name, number, address, lorem, dates, etc.

Usage: fake [OPTIONS] [COMMAND]

Commands:
  CityPrefix            
  CitySuffix            
  CityName              
  CountryName           
  CountryCode           
  StreetSuffix          
  StreetName            
  TimeZone              
  StateName             
  StateAbbr             
  SecondaryAddressType  
  SecondaryAddress      
  ZipCode               
  PostCode              
  BuildingNumber        
  Latitude              
  Longitude             
  Geohash               
  Isbn                  
  Isbn10                
  Isbn13                
  CreditCardNumber      
  CompanySuffix         
  CompanyName           
  Buzzword              
  BuzzwordMiddle        
  BuzzwordTail          
  CatchPhrase           
  BsVerb                
  BsAdj                 
  BsNoun                
  Bs                    
  Profession            
  Industry              
  FreeEmailProvider     
  DomainSuffix          
  FreeEmail             
  SafeEmail             
  Username              
  Password              
  IPv4                  
  IPv6                  
  IP                    
  MACAddress            
  UserAgent             
  Seniority             
  Field                 
  Position              
  Word                  
  Words                 
  Sentence              
  Sentences             
  Paragraph             
  Paragraphs            
  FirstName             
  LastName              
  Title                 
  Suffix                
  Name                  
  NameWithTitle         
  PhoneNumber           
  CellNumber            
  FilePath              
  FileName              
  FileExtension         
  DirPath               
  MimeType              
  Semver                
  SemverStable          
  SemverUnstable        
  CurrencyCode          
  CurrencyName          
  CurrencySymbol        
  Bic                   
  Isin                  
  HexColor              
  RgbColor              
  RgbaColor             
  HslColor              
  HslaColor             
  Color                 
  Time                  
  Date                  
  DateTime              
  RfcStatusCode         
  ValidStatusCode       
  help                  Print this message or the help of the given subcommand(s)

Options:
  -r, --repeat <repeat>  [default: 1]
  -l, --locale <locale>  [default: EN]
  -h, --help             Print help
  -V, --version          Print version

```

## Usage

### In rust code
```rust
use fake::{Dummy, Fake, Faker};
use fake::rand::rngs::StdRng;
use fake::rand::SeedableRng;

#[derive(Debug, Dummy)]
pub struct Foo {
    #[dummy(faker = "1000..2000")]
    order_id: usize,
    customer: String,
    paid: bool,
}

#[derive(Debug, Dummy)]
struct Bar<T> {
    field: Vec<T>,
}

fn main() {
    // type derived Dummy
    let f: Foo = Faker.fake();
    println!("{:?}", f);

    let b: Bar<Foo> = Faker.fake();
    println!("{:?}", b);

    // using `Faker` to generate default fake value of given type
    let tuple = Faker.fake::<(u8, u32, f32)>();
    println!("tuple {:?}", tuple);
    println!("String {:?}", Faker.fake::<String>());

    // types U can used to generate fake value T, if `T: Dummy<U>`
    println!("String {:?}", (8..20).fake::<String>());
    println!("u32 {:?}", (8..20).fake::<u32>());

    // using `faker` module with locales
    use fake::faker::name::raw::*;
    use fake::locales::*;

    let name: String = Name(EN).fake();
    println!("name {:?}", name);

    let name: String = Name(ZH_TW).fake();
    println!("name {:?}", name);

    // using convenient function without providing locale
    use fake::faker::lorem::en::*;
    let words: Vec<String> = Words(3..5).fake();
    println!("words {:?}", words);

    // using macro to generate nested collection
    let name_vec = fake::vec![String as Name(EN); 4, 3..5, 2];
    println!("random nested vec {:?}", name_vec);

    // fixed seed rng
    let seed = [
        1, 0, 0, 0, 23, 0, 0, 0, 200, 1, 0, 0, 210, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0,
    ];
    let ref mut r = StdRng::from_seed(seed);
    for _ in 0..5 {
        let v: usize = Faker.fake_with_rng(r);
        println!("value from fixed seed {}", v);
    }
}
```

## Command line

Generate random name (defaults to EN locale)
```shell
❯ ./fake Name
Generating 1 fakes for EN locale
Theresa Walker
```
Generate 5 chinese random names by mentioning locale to zh_cn
```shell
❯ ./fake -r5 -lzh_cn Name
Generating 5 fakes for ZH_CN locale
何丹华
尹雅瑾
于金福
郭雨珍
龙菲霞
```
Generate 5 random passwords with minimum 10 characters
```shell
❯ ./fake -r5 Password --min 10
Generating 5 fakes for EN locale
Q6eeXHfC3uzSRqtZwB
6fDHAOh3I7Ah77duLL
R8ygoTLmd4i1z1Z
5Uxj3RdEK5O4Af3ow
2XWsGT0lUaDnMZTb7
```
Arguments can be sent to fake generators like password that accept different ranges
```shell
❯ ./fake Password --help
Usage: fake Password [OPTIONS]

Options:
      --max <max>  [default: 20]
      --min <min>  [default: 10]
  -h, --help       Print help
```

# Fakers with locale

## Lorem

```rust
Word();
Words(count: Range<usize>);
Sentence(count: Range<usize>);
Sentences(count: Range<usize>);
Paragraph(count: Range<usize>);
Paragraphs(count: Range<usize>);
```

## Name

```rust
FirstName();
LastName();
Title();
Suffix();
Name();
NameWithTitle();
```

## Number

```rust
Digit();

// Format is a &str such that:
// - `^` will be subsituted by a random number 1-9.
// - `#` will be subsituted by a random number 0-9.
// - Any other character will be left as-is.
NumberWithFormat<'a>(fmt: &'a str);
```

## Boolean

```rust
Boolean(ratio: u8);
```

## Internet

```rust
FreeEmailProvider();
DomainSuffix();
FreeEmail();
SafeEmail();
Username();
Password(len_range: Range<usize>);
IPv4();
IPv6();
IP();
MACAddress();
UserAgent();
```

## HTTP

```rust
RfcStatusCode();
ValidStatusCode();
```

## Color

```rust
HexColor();
RgbColor();
RgbaColor();
HslColor();
HslaColor();
Color();
```

## Company

```rust
CompanySuffix();
CompanyName();
Buzzword();
BuzzwordMiddle();
BuzzwordTail();
CatchPhrase();
BsVerb();
BsAdj();
BsNoun();
Bs();
Profession();
Industry();
```

## Currency

```rust
CurrencyCode();
CurrencyName();
CurrencySymbol();
```

## Creditcard

```rust
CreditCardNumber();
```

## Address

```rust
CityPrefix();
CitySuffix();
CityName();
CountryName();
CountryCode();
StreetSuffix();
StreetName();
TimeZone();
StateName();
StateAbbr();
SecondaryAddressType();
SecondaryAddress();
ZipCode();
PostCode();
BuildingNumber();
Latitude();
Longitude();
Geohash(precision: u8);
```

## Administrative

```rust
HealthInsuranceCode();
```

## Automotive

```rust
LicencePlate();
```

## Barcode

```rust
Isbn();
Isbn13();
Isbn10();
```

## Phone Number

```rust
PhoneNumber();
CellNumber();
```

## Date/Time

```rust
Time();
Date();
DateTime();
Duration();
DateTimeBefore(dt: DateTime<Utc>);
DateTimeAfter(dt: DateTime<Utc>);
DateTimeBetween(start: DateTime<Utc>, end: DateTime<Utc>);
```

## Filesystem

```rust
FilePath();
FileName();
FileExtension();
DirPath();
```

### Finance

```rust
Bic();
Isin();
```

### Ferroid

```rust
FerroidULID();
FerroidTwitterId();
FerroidInstagramId();
FerroidMastodonId();
FerroidDiscordId();
```

### UUID

```rust
UUIDv1();
UUIDv3();
UUIDv4();
UUIDv5();
```

### Decimal

```rust
Decimal();
PositiveDecimal();
NegativeDecimal();
NoDecimalPoints();
```

### Bigdecimal

```rust
BigDecimal();
PositiveBigDecimal();
NegativeBigDecimal();
NoBigDecimalPoints();
```

## Utils
### Either
```rust
use fake::faker::phone_number::en::{CellNumber, PhoneNumber};
use fake::{utils::{either, WrappedVal}, Dummy, Fake, Faker};

#[derive(Debug, Dummy)]
struct Foo {
    #[dummy(faker = "either(PhoneNumber(), CellNumber())", wrapper = "WrappedVal")]
    phone_number: String,
}
```

# LICENSE

This project is licensed under either of

- Apache License, Version 2.0, ([LICENSE-APACHE]LICENSE-APACHE or
  http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT]LICENSE-MIT or
  http://opensource.org/licenses/MIT)

at your option.