faker 1.0.0 → 6.6.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of faker might be problematic. Click here for more details.

Files changed (60) hide show
  1. package/.eslintrc +54 -0
  2. package/.gitattributes +1 -0
  3. package/.github/FUNDING.yml +12 -0
  4. package/.travis.yml +7 -3
  5. package/.versions +23 -0
  6. package/Readme.md +1 -46
  7. package/package.json +70 -23
  8. package/.jshintrc +0 -87
  9. package/.npmignore +0 -16
  10. package/BUILD/BUILD.js +0 -139
  11. package/BUILD/Mustache.js +0 -296
  12. package/BUILD/docs.js +0 -62
  13. package/BUILD/main.js +0 -60
  14. package/MIT-LICENSE.txt +0 -20
  15. package/Makefile +0 -26
  16. package/examples/bigDataSet.json +0 -1
  17. package/examples/browser_test.html +0 -40
  18. package/examples/dataSet.json +0 -1
  19. package/examples/index.html +0 -77
  20. package/examples/js/faker.js +0 -730
  21. package/examples/js/jquery.js +0 -154
  22. package/examples/js/prettyPrint.js +0 -712
  23. package/examples/library_test.js +0 -9
  24. package/examples/node_generateSet.js +0 -20
  25. package/examples/node_min_test.js +0 -9
  26. package/faker.js +0 -730
  27. package/index.js +0 -31
  28. package/lib/address.js +0 -100
  29. package/lib/company.js +0 -36
  30. package/lib/date.js +0 -42
  31. package/lib/definitions.js +0 -1398
  32. package/lib/helpers.js +0 -124
  33. package/lib/image.js +0 -58
  34. package/lib/internet.js +0 -53
  35. package/lib/lorem.js +0 -45
  36. package/lib/name.js +0 -34
  37. package/lib/phone_number.js +0 -16
  38. package/lib/random.js +0 -106
  39. package/lib/tree.js +0 -69
  40. package/lib/version.js +0 -0
  41. package/logo.png +0 -0
  42. package/minfaker.js +0 -35
  43. package/test/address.unit.js +0 -293
  44. package/test/all.functional.js +0 -47
  45. package/test/browser.unit.html +0 -28
  46. package/test/company.unit.js +0 -110
  47. package/test/date.unit.js +0 -65
  48. package/test/helpers.unit.js +0 -62
  49. package/test/image.unit.js +0 -108
  50. package/test/internet.unit.js +0 -92
  51. package/test/lorem.unit.js +0 -178
  52. package/test/mocha.opts +0 -5
  53. package/test/name.unit.js +0 -87
  54. package/test/phone_number.unit.js +0 -29
  55. package/test/run.js +0 -68
  56. package/test/support/chai.js +0 -3403
  57. package/test/support/sinon-1.5.2.js +0 -4153
  58. package/test/support/walk_dir.js +0 -43
  59. package/test/tree.unit.js +0 -108
  60. /package/{.jshintignore → .eslintignore} +0 -0
@@ -1,293 +0,0 @@
1
- if (typeof module !== 'undefined') {
2
- var assert = require('assert');
3
- var sinon = require('sinon');
4
- var faker = require('../index');
5
- }
6
-
7
- describe("address.js", function () {
8
- describe("city()", function () {
9
- beforeEach(function () {
10
- sinon.spy(faker.random, 'city_prefix');
11
- sinon.spy(faker.random, 'first_name');
12
- sinon.spy(faker.random, 'last_name');
13
- sinon.spy(faker.random, 'city_suffix');
14
- });
15
-
16
- afterEach(function () {
17
- faker.random.number.restore();
18
- faker.random.city_prefix.restore();
19
- faker.random.first_name.restore();
20
- faker.random.last_name.restore();
21
- faker.random.city_suffix.restore();
22
- });
23
-
24
- it("occasionally returns prefix + first name + suffix", function () {
25
- sinon.stub(faker.random, 'number').returns(0);
26
-
27
- var city = faker.Address.city();
28
- assert.ok(city);
29
-
30
- assert.ok(faker.random.city_prefix.calledOnce);
31
- assert.ok(faker.random.first_name.calledOnce);
32
- assert.ok(faker.random.city_suffix.calledOnce);
33
- });
34
-
35
- it("occasionally returns prefix + first name", function () {
36
- sinon.stub(faker.random, 'number').returns(1);
37
-
38
- var city = faker.Address.city();
39
- assert.ok(city);
40
-
41
- assert.ok(faker.random.city_prefix.calledOnce);
42
- assert.ok(faker.random.first_name.calledOnce);
43
- assert.ok(!faker.random.city_suffix.called);
44
- });
45
-
46
- it("occasionally returns first name + suffix", function () {
47
- sinon.stub(faker.random, 'number').returns(2);
48
-
49
- var city = faker.Address.city();
50
- assert.ok(city);
51
-
52
- assert.ok(!faker.random.city_prefix.called);
53
- assert.ok(faker.random.first_name.calledOnce);
54
- assert.ok(faker.random.city_suffix.calledOnce);
55
- });
56
-
57
- it("occasionally returns last name + suffix", function () {
58
- sinon.stub(faker.random, 'number').returns(3);
59
-
60
- var city = faker.Address.city();
61
- assert.ok(city);
62
-
63
- assert.ok(!faker.random.city_prefix.called);
64
- assert.ok(!faker.random.first_name.called);
65
- assert.ok(faker.random.last_name.calledOnce);
66
- assert.ok(faker.random.city_suffix.calledOnce);
67
- });
68
- });
69
-
70
- describe("streetName()", function () {
71
- beforeEach(function () {
72
- sinon.spy(faker.random, 'first_name');
73
- sinon.spy(faker.random, 'last_name');
74
- sinon.spy(faker.random, 'street_suffix');
75
- });
76
-
77
- afterEach(function () {
78
- faker.random.number.restore();
79
- faker.random.first_name.restore();
80
- faker.random.last_name.restore();
81
- faker.random.street_suffix.restore();
82
- });
83
-
84
- it("occasionally returns last name + suffix", function () {
85
- sinon.stub(faker.random, 'number').returns(0);
86
-
87
- var street_name = faker.Address.streetName();
88
- assert.ok(street_name);
89
-
90
- assert.ok(!faker.random.first_name.called);
91
- assert.ok(faker.random.last_name.calledOnce);
92
- assert.ok(faker.random.street_suffix.calledOnce);
93
- });
94
-
95
- it("occasionally returns first name + suffix", function () {
96
- sinon.stub(faker.random, 'number').returns(1);
97
-
98
- var street_name = faker.Address.streetName();
99
- assert.ok(street_name);
100
-
101
- assert.ok(faker.random.first_name.calledOnce);
102
- assert.ok(!faker.random.last_name.called);
103
- assert.ok(faker.random.street_suffix.calledOnce);
104
- });
105
- });
106
-
107
- describe("streetAddress()", function () {
108
- beforeEach(function () {
109
- sinon.spy(faker.Address, 'streetName');
110
- sinon.spy(faker.Address, 'secondaryAddress');
111
- });
112
-
113
- afterEach(function () {
114
- faker.Address.streetName.restore();
115
- faker.Address.secondaryAddress.restore();
116
- });
117
-
118
- it("occasionally returns a 5-digit street number", function () {
119
- sinon.stub(faker.random, 'number').returns(0);
120
- var address = faker.Address.streetAddress();
121
- var parts = address.split(' ');
122
-
123
- assert.equal(parts[0].length, 5);
124
- assert.ok(faker.Address.streetName.called);
125
-
126
- faker.random.number.restore();
127
- });
128
-
129
- it("occasionally returns a 4-digit street number", function () {
130
- sinon.stub(faker.random, 'number').returns(1);
131
- var address = faker.Address.streetAddress();
132
- var parts = address.split(' ');
133
-
134
- assert.equal(parts[0].length, 4);
135
- assert.ok(faker.Address.streetName.called);
136
-
137
- faker.random.number.restore();
138
- });
139
-
140
- it("occasionally returns a 3-digit street number", function () {
141
- sinon.stub(faker.random, 'number').returns(2);
142
- var address = faker.Address.streetAddress();
143
- var parts = address.split(' ');
144
-
145
- assert.equal(parts[0].length, 3);
146
- assert.ok(faker.Address.streetName.called);
147
- assert.ok(!faker.Address.secondaryAddress.called);
148
-
149
- faker.random.number.restore();
150
- });
151
-
152
- context("when useFulladdress is true", function () {
153
- it("adds a secondary address to the result", function () {
154
- var address = faker.Address.streetAddress(true);
155
- var parts = address.split(' ');
156
-
157
- assert.ok(faker.Address.secondaryAddress.called);
158
- });
159
- });
160
- });
161
-
162
- describe("secondaryAddress()", function () {
163
- it("randomly chooses an Apt or Suite number", function () {
164
- sinon.spy(faker.random, 'array_element');
165
-
166
- var address = faker.Address.secondaryAddress();
167
-
168
- var expected_array = [
169
- 'Apt. ###',
170
- 'Suite ###'
171
- ];
172
-
173
- assert.ok(address);
174
- assert.ok(faker.random.array_element.calledWith(expected_array));
175
- faker.random.array_element.restore();
176
- });
177
- });
178
-
179
- describe("brState()", function () {
180
- beforeEach(function () {
181
- sinon.spy(faker.random, 'br_state_abbr');
182
- sinon.spy(faker.random, 'br_state');
183
- });
184
-
185
- afterEach(function () {
186
- faker.random.br_state_abbr.restore();
187
- faker.random.br_state.restore();
188
- });
189
-
190
- context("when useAbbr is true", function () {
191
- it("returns a br_state_abbr", function () {
192
- var state = faker.Address.brState(true);
193
-
194
- assert.ok(state);
195
- assert.ok(faker.random.br_state_abbr.called);
196
- assert.ok(!faker.random.br_state.called);
197
- });
198
- });
199
-
200
- context("when useAbbr is not set", function () {
201
- it("returns a br_state", function () {
202
- var state = faker.Address.brState();
203
-
204
- assert.ok(state);
205
- assert.ok(!faker.random.br_state_abbr.called);
206
- assert.ok(faker.random.br_state.called);
207
- });
208
- });
209
- });
210
-
211
- describe("ukCounty()", function () {
212
- it("returns random uk_county", function () {
213
- sinon.spy(faker.random, 'uk_county');
214
- var county = faker.Address.ukCounty();
215
- assert.ok(county);
216
- assert.ok(faker.random.uk_county.called);
217
- faker.random.uk_county.restore();
218
- });
219
- });
220
-
221
- describe("ukCountry()", function () {
222
- it("returns random uk_country", function () {
223
- sinon.spy(faker.random, 'uk_country');
224
- var country = faker.Address.ukCountry();
225
- assert.ok(country);
226
- assert.ok(faker.random.uk_country.called);
227
- faker.random.uk_country.restore();
228
- });
229
- });
230
-
231
- describe("usState()", function () {
232
- beforeEach(function () {
233
- sinon.spy(faker.random, 'us_state_abbr');
234
- sinon.spy(faker.random, 'us_state');
235
- });
236
-
237
- afterEach(function () {
238
- faker.random.us_state_abbr.restore();
239
- faker.random.us_state.restore();
240
- });
241
-
242
- context("when useAbus is true", function () {
243
- it("returns a us_state_abbr", function () {
244
- var state = faker.Address.usState(true);
245
-
246
- assert.ok(state);
247
- assert.ok(faker.random.us_state_abbr.called);
248
- assert.ok(!faker.random.us_state.called);
249
- });
250
- });
251
-
252
- context("when useAbus is not set", function () {
253
- it("returns a us_state", function () {
254
- var state = faker.Address.usState();
255
-
256
- assert.ok(state);
257
- assert.ok(!faker.random.us_state_abbr.called);
258
- assert.ok(faker.random.us_state.called);
259
- });
260
- });
261
- });
262
-
263
- describe("latitude()", function () {
264
- it("returns random latitude", function () {
265
- for (var i = 0; i < 100; i++) {
266
- sinon.spy(faker.random, 'number');
267
- var latitude = faker.Address.latitude();
268
- assert.ok(typeof latitude === 'string');
269
- var latitude_float = parseFloat(latitude);
270
- assert.ok(latitude_float >= -90.0);
271
- assert.ok(latitude_float <= 90.0);
272
- assert.ok(faker.random.number.called);
273
- faker.random.number.restore();
274
- }
275
- });
276
- });
277
-
278
- describe("longitude()", function () {
279
- it("returns random longitude", function () {
280
- for (var i = 0; i < 100; i++) {
281
- sinon.spy(faker.random, 'number');
282
- var longitude = faker.Address.longitude();
283
- assert.ok(typeof longitude === 'string');
284
- var longitude_float = parseFloat(longitude);
285
- assert.ok(longitude_float >= -180.0);
286
- assert.ok(longitude_float <= 180.0);
287
- assert.ok(faker.random.number.called);
288
- faker.random.number.restore();
289
- }
290
- });
291
- });
292
-
293
- });
@@ -1,47 +0,0 @@
1
- if (typeof module !== 'undefined') {
2
- var assert = require('assert');
3
- var sinon = require('sinon');
4
- var faker = require('../index');
5
- }
6
-
7
- // Basic smoke tests to make sure each method is at least implemented and returns a string.
8
-
9
- var modules = {
10
- Address: [
11
- 'city', 'streetName', 'streetAddress', 'secondaryAddress',
12
- 'brState', 'ukCountry', 'ukCounty', 'usState', 'zipCode'
13
- ],
14
-
15
- Company: ['companyName', 'companySuffix', 'catchPhrase', 'bs'],
16
-
17
- Internet: ['email', 'userName', 'domainName', 'domainWord', 'ip'],
18
-
19
- Lorem: ['words', 'sentence', 'sentences', 'paragraph', 'paragraphs'],
20
-
21
- Name: ['firstName', 'lastName', 'findName'],
22
-
23
- PhoneNumber: ['phoneNumber']
24
- };
25
-
26
- describe("functional tests", function () {
27
- Object.keys(modules).forEach(function (module) {
28
- describe(module, function () {
29
- modules[module].forEach(function (meth) {
30
- it(meth + "()", function () {
31
- var result = faker[module][meth]();
32
- assert.ok(result);
33
- });
34
- });
35
- });
36
- });
37
-
38
- describe("Address", function () {
39
- it("zipCodeFormat()", function () {
40
- var result = faker.Address.zipCodeFormat(0);
41
- assert.ok(!result.match(/-/));
42
-
43
- result = faker.Address.zipCodeFormat(1);
44
- assert.ok(result.match(/-/));
45
- });
46
- });
47
- });
@@ -1,28 +0,0 @@
1
- <html>
2
- <head>
3
- <meta charset="utf-8">
4
- <title>Mocha Tests</title>
5
- <link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
6
- </head>
7
- <body>
8
- <div id="mocha"></div>
9
- <script src="../node_modules/mocha/mocha.js"></script>
10
- <script src="../faker.js"></script>
11
- <script src="./support/chai.js"></script>
12
- <script src="./support/sinon-1.5.2.js"></script>
13
- <script>assert = chai.assert;</script>
14
- <script>mocha.setup('bdd');</script>
15
- <script src="all.functional.js"></script>
16
- <script src="address.unit.js"></script>
17
- <script src="company.unit.js"></script>
18
- <script src="helpers.unit.js"></script>
19
- <script src="internet.unit.js"></script>
20
- <script src="lorem.unit.js"></script>
21
- <script src="name.unit.js"></script>
22
- <script src="phone_number.unit.js"></script>
23
- <script>
24
- mocha.run();
25
- </script>
26
- </body>
27
- </html>
28
-
@@ -1,110 +0,0 @@
1
- if (typeof module !== 'undefined') {
2
- var assert = require('assert');
3
- var sinon = require('sinon');
4
- var faker = require('../index');
5
- }
6
-
7
- describe("company.js", function () {
8
- describe("companyName()", function () {
9
- it("lets you specify the type of name to return", function () {
10
- sinon.spy(faker.random, 'number');
11
- var name = faker.Company.companyName(1);
12
-
13
- assert.ok(name.match(/-/));
14
-
15
- assert.ok(!faker.random.number.called);
16
- faker.random.number.restore();
17
- });
18
-
19
- it("sometimes returns three last names", function () {
20
- sinon.spy(faker.random, 'last_name');
21
- sinon.stub(faker.random, 'number').returns(2);
22
- var name = faker.Company.companyName();
23
- var parts = name.split(' ');
24
-
25
- assert.strictEqual(parts.length, 4); // account for word 'and'
26
- assert.ok(faker.random.last_name.calledThrice);
27
-
28
- faker.random.number.restore();
29
- faker.random.last_name.restore();
30
- });
31
-
32
- it("sometimes returns two last names separated by a hyphen", function () {
33
- sinon.spy(faker.random, 'last_name');
34
- sinon.stub(faker.random, 'number').returns(1);
35
- var name = faker.Company.companyName();
36
- var parts = name.split('-');
37
-
38
- assert.ok(parts.length >= 2);
39
- assert.ok(faker.random.last_name.calledTwice);
40
-
41
- faker.random.number.restore();
42
- faker.random.last_name.restore();
43
- });
44
-
45
- it("sometimes returns a last name with a company suffix", function () {
46
- sinon.spy(faker.Company, 'companySuffix');
47
- sinon.spy(faker.random, 'last_name');
48
- sinon.stub(faker.random, 'number').returns(0);
49
- var name = faker.Company.companyName();
50
- var parts = name.split(' ');
51
-
52
- assert.ok(parts.length >= 2);
53
- assert.ok(faker.random.last_name.calledOnce);
54
- assert.ok(faker.Company.companySuffix.calledOnce);
55
-
56
- faker.random.number.restore();
57
- faker.random.last_name.restore();
58
- faker.Company.companySuffix.restore();
59
- });
60
- });
61
-
62
- describe("companySuffix()", function () {
63
- it("returns random value from company.suffixes array", function () {
64
- var suffix = faker.Company.companySuffix();
65
- assert.ok(faker.Company.suffixes().indexOf(suffix) !== -1);
66
- });
67
- });
68
-
69
- describe("catchPhrase()", function () {
70
- it("returns phrase comprising of a catch phrase adjective, descriptor, and noun", function () {
71
- sinon.spy(faker.random, 'array_element');
72
- sinon.spy(faker.random, 'catch_phrase_adjective');
73
- sinon.spy(faker.random, 'catch_phrase_descriptor');
74
- sinon.spy(faker.random, 'catch_phrase_noun');
75
- var phrase = faker.Company.catchPhrase();
76
-
77
- assert.ok(phrase.split(' ').length >= 3);
78
- assert.ok(faker.random.array_element.calledThrice);
79
- assert.ok(faker.random.catch_phrase_adjective.calledOnce);
80
- assert.ok(faker.random.catch_phrase_descriptor.calledOnce);
81
- assert.ok(faker.random.catch_phrase_noun.calledOnce);
82
-
83
- faker.random.array_element.restore();
84
- faker.random.catch_phrase_adjective.restore();
85
- faker.random.catch_phrase_descriptor.restore();
86
- faker.random.catch_phrase_noun.restore();
87
- });
88
- });
89
-
90
- describe("bs()", function () {
91
- it("returns phrase comprising of a BS adjective, buzz, and noun", function () {
92
- sinon.spy(faker.random, 'array_element');
93
- sinon.spy(faker.random, 'bs_adjective');
94
- sinon.spy(faker.random, 'bs_buzz');
95
- sinon.spy(faker.random, 'bs_noun');
96
- var bs = faker.Company.bs();
97
-
98
- assert.ok(typeof bs === 'string');
99
- assert.ok(faker.random.array_element.calledThrice);
100
- assert.ok(faker.random.bs_adjective.calledOnce);
101
- assert.ok(faker.random.bs_buzz.calledOnce);
102
- assert.ok(faker.random.bs_noun.calledOnce);
103
-
104
- faker.random.array_element.restore();
105
- faker.random.bs_adjective.restore();
106
- faker.random.bs_buzz.restore();
107
- faker.random.bs_noun.restore();
108
- });
109
- });
110
- });
package/test/date.unit.js DELETED
@@ -1,65 +0,0 @@
1
- if (typeof module !== 'undefined') {
2
- var assert = require('assert');
3
- var sinon = require('sinon');
4
- var faker = require('../index');
5
- }
6
-
7
- describe("date.js", function () {
8
- describe("past()", function () {
9
- it("returns a date N years into the past", function () {
10
-
11
- var date = faker.Date.past(75);
12
- assert.ok(Date.parse(date) < new Date());
13
- });
14
-
15
- it("returns a date N years before the date given", function () {
16
-
17
- var refDate = new Date(2120, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
18
-
19
- var date = Date.parse(faker.Date.past(75, refDate.toJSON()));
20
-
21
- assert.ok(date < refDate && date > new Date()); // date should be before date given but after the current time
22
- });
23
-
24
- });
25
-
26
- describe("future()", function () {
27
- it("returns a date N years into the future", function () {
28
-
29
- var date = faker.Date.future(75);
30
-
31
- assert.ok(Date.parse(date) > new Date());
32
- });
33
-
34
- it("returns a date N years after the date given", function () {
35
-
36
- var refDate = new Date(1880, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
37
-
38
- var date = Date.parse(faker.Date.future(75, refDate.toJSON()));
39
-
40
- assert.ok(date > refDate && date < new Date()); // date should be after the date given, but before the current time
41
- });
42
- });
43
-
44
- describe("recent()", function () {
45
- it("returns a date N days from the recent past", function () {
46
-
47
- var date = faker.Date.recent(30);
48
-
49
- assert.ok(Date.parse(date) < new Date());
50
- });
51
-
52
- });
53
-
54
- describe("between()", function () {
55
- it("returns a random date between the dates given", function () {
56
-
57
- var from = new Date(1990, 5, 7, 9, 11, 0, 0);
58
- var to = new Date(2000, 6, 8, 10, 12, 0, 0);
59
-
60
- var date = Date.parse(faker.Date.between(from, to));
61
-
62
- assert.ok(date > from && date < to);
63
- });
64
- });
65
- });
@@ -1,62 +0,0 @@
1
- if (typeof module !== 'undefined') {
2
- var assert = require('assert');
3
- var sinon = require('sinon');
4
- var faker = require('../index');
5
- }
6
-
7
- describe("helpers.js", function () {
8
- describe("replaceSymbolWithNumber()", function () {
9
- context("when no symbol passed in", function () {
10
- it("uses '#' by default", function () {
11
- var num = faker.Helpers.replaceSymbolWithNumber('#AB');
12
- assert.ok(num.match(/\dAB/));
13
- });
14
- });
15
-
16
- context("when symbol passed in", function () {
17
- it("replaces that symbol with integers", function () {
18
- var num = faker.Helpers.replaceSymbolWithNumber('#AB', 'A');
19
- assert.ok(num.match(/#\dB/));
20
- });
21
- });
22
- });
23
-
24
- describe("slugify()", function () {
25
- it("removes unwanted characters from URI string", function () {
26
- assert.equal(faker.Helpers.slugify("Aiden.Harªann"), "Aiden.Harann");
27
- assert.equal(faker.Helpers.slugify("d'angelo.net"), "dangelo.net");
28
- });
29
- });
30
-
31
- describe("createCard()", function () {
32
- it("returns an object", function () {
33
- var card = faker.Helpers.createCard();
34
- assert.ok(typeof card === 'object');
35
- });
36
- });
37
-
38
- describe("userCard()", function () {
39
- it("returns an object", function () {
40
- var card = faker.Helpers.userCard();
41
- assert.ok(typeof card === 'object');
42
- });
43
- });
44
-
45
- // Make sure we keep this function for backward-compatibility.
46
- describe("randomNumber()", function () {
47
- it("returns an integer", function () {
48
- var num = faker.Helpers.randomNumber();
49
- assert.ok(typeof num === 'number');
50
- });
51
- });
52
-
53
- // Make sure we keep this function for backward-compatibility.
54
- describe("randomize()", function () {
55
- it("returns a random element from an array", function () {
56
- var arr = ['a', 'b', 'c'];
57
- var elem = faker.Helpers.randomize(arr);
58
- assert.ok(elem);
59
- assert.ok(arr.indexOf(elem) !== -1);
60
- });
61
- });
62
- });