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
|
# faker.js - generate massive amounts of fake data in the browser and node.js

[](https://travis-ci.org/Marak/faker.js)
[](http://badge.fury.io/js/faker)
## Demo
[https://cdn.rawgit.com/Marak/faker.js/master/examples/browser/index.html](https://cdn.rawgit.com/Marak/faker.js/master/examples/browser/index.html)
## Hosted API Microservice
[http://faker.hook.io](http://faker.hook.io/)
- Supports all Faker API Methods
- Full-Featured Microservice
- Hosted by [hook.io](http://hook.io)
```bash
curl http://faker.hook.io?property=name.findName&locale=de
```
## Usage
### Browser
<script src = "faker.js" type = "text/javascript"></script>
<script>
var randomName = faker.name.findName(); // Caitlyn Kerluke
var randomEmail = faker.internet.email(); // [email protected]
var randomCard = faker.helpers.createCard(); // random contact card containing many properties
</script>
### Node.js
var faker = require('faker');
var randomName = faker.name.findName(); // Rowan Nikolaus
var randomEmail = faker.internet.email(); // [email protected]
var randomCard = faker.helpers.createCard(); // random contact card containing many properties
## API
### Faker.fake()
faker.js contains a super useful generator method `Faker.fake` for combining faker API methods using a mustache string format.
**Example:**
{{=<% %>=}}
``` js
console.log(faker.fake("{{name.lastName}}, {{name.firstName}} {{name.suffix}}"));
// outputs: "Marks, Dean Sr."
```
<%={{ }}=%>
This will interpolate the format string with the value of methods `name.lastName()`, `name.firstName()`, and `name.suffix()`
### JSDoc API Browser
[http://marak.github.io/faker.js/](http://marak.github.io/faker.js/)
### API Methods
{{{API}}}
## Localization
As of version `v2.0.0` faker.js has support for multiple localities.
The default language locale is set to English.
Setting a new locale is simple:
```js
// sets locale to de
faker.locale = "de";
```
{{LOCALES}}
### Individual Localization Packages
As of vesion `v3.0.0` faker.js supports incremental loading of locales.
By default, requiring `faker` will include *all* locale data.
In a production environment, you may only want to include the locale data for a specific set of locales.
```js
// loads only de locale
var faker = require('faker/locale/de');
```
## Setting a randomness seed
If you want consistent results, you can set your own seed:
```js
faker.seed(123);
var firstRandom = faker.random.number();
// Setting the seed again resets the sequence.
faker.seed(123);
var secondRandom = faker.random.number();
console.log(firstRandom === secondRandom);
```
## Tests
npm install .
make test
You can view a code coverage report generated in coverage/lcov-report/index.html.
## Projects Built with faker.js
### Fake JSON Schema
Use faker generators to populate JSON Schema samples.
See: https://github.com/pateketrueke/json-schema-faker/
### CLI
Run faker generators from Command Line.
See: https://github.com/lestoni/faker-cli
**Want to see your project added here? Let us know!**
### Meteor
#### Meteor Installation
```
meteor add practicalmeteor:faker
```
#### Meteor Usage, both client and server
```js
var randomName = faker.name.findName(); // Rowan Nikolaus
var randomEmail = faker.internet.email(); // [email protected]
var randomCard = faker.helpers.createCard(); // random contact card containing many properties
```
## Building faker.js
faker uses [gulp](http://gulpjs.com/) to automate it's build process. Running the following build command will generate new browser builds, documentation, and code examples for the project.
```
npm run-script build
```
## Building JSDocs
```
npm run-script doc
```
## Version Release Schedule
faker.js is a popular project used by many organizations and individuals in production settings. Major and Minor version releases are generally on a monthly schedule. Bugs fixes are addressed by severity and fixed as soon as possible.
If you require the absolute latest version of `faker.js` the `master` branch @ http://github.com/marak/faker.js/ should always be up to date and working.
## Maintainer
#### Marak Squires
faker.js - Copyright (c) 2017
Marak Squires
http://github.com/marak/faker.js/
faker.js was inspired by and has used data definitions from:
* https://github.com/stympy/faker/ - Copyright (c) 2007-2010 Benjamin Curtis
* http://search.cpan.org/~jasonk/Data-Faker-0.07/ - Copyright 2004-2005 by Jason Kohles
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|