UNPKG

8.04 kBMarkdownView Raw
1# faker.js - generate massive amounts of fake data in the browser and node.js
2
3![Faker.js](http://imgur.com/KiinQ.png)
4
5[![Build Status](https://travis-ci.org/Marak/faker.js.svg?branch=master)](https://travis-ci.org/Marak/faker.js)
6
7[![npm version](https://badge.fury.io/js/faker.svg)](http://badge.fury.io/js/faker)
8
9## Demo
10
11[https://cdn.rawgit.com/Marak/faker.js/master/examples/browser/index.html](https://cdn.rawgit.com/Marak/faker.js/master/examples/browser/index.html)
12
13## Hosted API Microservice
14
15[http://faker.hook.io](http://faker.hook.io/)
16 - Supports all Faker API Methods
17 - Full-Featured Microservice
18 - Hosted by [hook.io](http://hook.io)
19
20```bash
21curl http://faker.hook.io?property=name.findName&locale=de
22```
23
24## Usage
25
26### Browser
27
28 <script src = "faker.js" type = "text/javascript"></script>
29 <script>
30 var randomName = faker.name.findName(); // Caitlyn Kerluke
31 var randomEmail = faker.internet.email(); // Rusty@arne.info
32 var randomCard = faker.helpers.createCard(); // random contact card containing many properties
33 </script>
34
35### Node.js
36
37 var faker = require('faker');
38
39 var randomName = faker.name.findName(); // Rowan Nikolaus
40 var randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
41 var randomCard = faker.helpers.createCard(); // random contact card containing many properties
42
43## API
44
45
46### Faker.fake()
47
48faker.js contains a super useful generator method `Faker.fake` for combining faker API methods using a mustache string format.
49
50**Example:**
51
52``` js
53console.log(faker.fake("{{name.lastName}}, {{name.firstName}} {{name.suffix}}"));
54// outputs: "Marks, Dean Sr."
55```
56
57This will interpolate the format string with the value of methods `name.lastName()`, `name.firstName()`, and `name.suffix()`
58
59### JSDoc API Browser
60
61[http://marak.github.io/faker.js/](http://marak.github.io/faker.js/)
62
63### API Methods
64
65* address
66 * zipCode
67 * city
68 * cityPrefix
69 * citySuffix
70 * streetName
71 * streetAddress
72 * streetSuffix
73 * streetPrefix
74 * secondaryAddress
75 * county
76 * country
77 * countryCode
78 * state
79 * stateAbbr
80 * latitude
81 * longitude
82* commerce
83 * color
84 * department
85 * productName
86 * price
87 * productAdjective
88 * productMaterial
89 * product
90* company
91 * suffixes
92 * companyName
93 * companySuffix
94 * catchPhrase
95 * bs
96 * catchPhraseAdjective
97 * catchPhraseDescriptor
98 * catchPhraseNoun
99 * bsAdjective
100 * bsBuzz
101 * bsNoun
102* database
103 * column
104 * type
105 * collation
106 * engine
107* date
108 * past
109 * future
110 * between
111 * recent
112 * month
113 * weekday
114* fake
115* finance
116 * account
117 * accountName
118 * mask
119 * amount
120 * transactionType
121 * currencyCode
122 * currencyName
123 * currencySymbol
124 * bitcoinAddress
125 * iban
126 * bic
127* hacker
128 * abbreviation
129 * adjective
130 * noun
131 * verb
132 * ingverb
133 * phrase
134* helpers
135 * randomize
136 * slugify
137 * replaceSymbolWithNumber
138 * replaceSymbols
139 * shuffle
140 * mustache
141 * createCard
142 * contextualCard
143 * userCard
144 * createTransaction
145* image
146 * image
147 * avatar
148 * imageUrl
149 * abstract
150 * animals
151 * business
152 * cats
153 * city
154 * food
155 * nightlife
156 * fashion
157 * people
158 * nature
159 * sports
160 * technics
161 * transport
162 * dataUri
163* internet
164 * avatar
165 * email
166 * exampleEmail
167 * userName
168 * protocol
169 * url
170 * domainName
171 * domainSuffix
172 * domainWord
173 * ip
174 * ipv6
175 * userAgent
176 * color
177 * mac
178 * password
179* lorem
180 * word
181 * words
182 * sentence
183 * slug
184 * sentences
185 * paragraph
186 * paragraphs
187 * text
188 * lines
189* name
190 * firstName
191 * lastName
192 * findName
193 * jobTitle
194 * prefix
195 * suffix
196 * title
197 * jobDescriptor
198 * jobArea
199 * jobType
200* phone
201 * phoneNumber
202 * phoneNumberFormat
203 * phoneFormats
204* random
205 * number
206 * arrayElement
207 * objectElement
208 * uuid
209 * boolean
210 * word
211 * words
212 * image
213 * locale
214 * alphaNumeric
215* system
216 * fileName
217 * commonFileName
218 * mimeType
219 * commonFileType
220 * commonFileExt
221 * fileType
222 * fileExt
223 * directoryPath
224 * filePath
225 * semver
226
227
228## Localization
229
230As of version `v2.0.0` faker.js has support for multiple localities.
231
232The default language locale is set to English.
233
234Setting a new locale is simple:
235
236```js
237// sets locale to de
238faker.locale = "de";
239```
240
241 * az
242 * cz
243 * de
244 * de_AT
245 * de_CH
246 * en
247 * en_AU
248 * en_BORK
249 * en_CA
250 * en_GB
251 * en_IE
252 * en_IND
253 * en_US
254 * en_au_ocker
255 * es
256 * es_MX
257 * fa
258 * fr
259 * fr_CA
260 * ge
261 * id_ID
262 * it
263 * ja
264 * ko
265 * nb_NO
266 * nep
267 * nl
268 * pl
269 * pt_BR
270 * ru
271 * sk
272 * sv
273 * tr
274 * uk
275 * vi
276 * zh_CN
277 * zh_TW
278
279
280### Individual Localization Packages
281
282As of vesion `v3.0.0` faker.js supports incremental loading of locales.
283
284By default, requiring `faker` will include *all* locale data.
285
286In a production environment, you may only want to include the locale data for a specific set of locales.
287
288```js
289// loads only de locale
290var faker = require('faker/locale/de');
291```
292
293## Setting a randomness seed
294
295If you want consistent results, you can set your own seed:
296
297```js
298faker.seed(123);
299
300var firstRandom = faker.random.number();
301
302// Setting the seed again resets the sequence.
303faker.seed(123);
304
305var secondRandom = faker.random.number();
306
307console.log(firstRandom === secondRandom);
308```
309
310## Tests
311
312 npm install .
313 make test
314
315You can view a code coverage report generated in coverage/lcov-report/index.html.
316
317## Projects Built with faker.js
318
319### Fake JSON Schema
320
321Use faker generators to populate JSON Schema samples.
322See: https://github.com/pateketrueke/json-schema-faker/
323
324### CLI
325
326Run faker generators from Command Line.
327See: https://github.com/lestoni/faker-cli
328
329**Want to see your project added here? Let us know!**
330
331### Meteor
332
333#### Meteor Installation
334
335```
336meteor add practicalmeteor:faker
337```
338
339#### Meteor Usage, both client and server
340
341```js
342var randomName = faker.name.findName(); // Rowan Nikolaus
343var randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
344var randomCard = faker.helpers.createCard(); // random contact card containing many properties
345```
346
347## Building faker.js
348
349faker 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.
350
351```
352npm run-script build
353```
354
355## Building JSDocs
356
357```
358npm run-script doc
359```
360
361## Version Release Schedule
362
363faker.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.
364
365If 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.
366
367## Maintainer
368
369#### Marak Squires
370
371faker.js - Copyright (c) 2017
372Marak Squires
373http://github.com/marak/faker.js/
374
375faker.js was inspired by and has used data definitions from:
376
377 * https://github.com/stympy/faker/ - Copyright (c) 2007-2010 Benjamin Curtis
378 * http://search.cpan.org/~jasonk/Data-Faker-0.07/ - Copyright 2004-2005 by Jason Kohles
379
380Permission is hereby granted, free of charge, to any person obtaining
381a copy of this software and associated documentation files (the
382"Software"), to deal in the Software without restriction, including
383without limitation the rights to use, copy, modify, merge, publish,
384distribute, sublicense, and/or sell copies of the Software, and to
385permit persons to whom the Software is furnished to do so, subject to
386the following conditions:
387
388The above copyright notice and this permission notice shall be
389included in all copies or substantial portions of the Software.
390
391THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
392EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
393MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
394NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
395LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
396OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
397WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
398
399