@coderzz/mocker-data-generator 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/CHANGELOG.md +561 -0
  2. package/LICENSE +21 -0
  3. package/README.md +550 -0
  4. package/build/main/array-includes.d.ts +0 -0
  5. package/build/main/array-includes.js +45 -0
  6. package/build/main/index.d.ts +7 -0
  7. package/build/main/index.js +12 -0
  8. package/build/main/index.spec.d.ts +1 -0
  9. package/build/main/index.spec.js +16 -0
  10. package/build/main/lib/Generator.d.ts +61 -0
  11. package/build/main/lib/Generator.js +134 -0
  12. package/build/main/lib/Mocker.d.ts +22 -0
  13. package/build/main/lib/Mocker.js +76 -0
  14. package/build/main/lib/Schema.d.ts +9 -0
  15. package/build/main/lib/Schema.js +210 -0
  16. package/build/main/lib/types.d.ts +8 -0
  17. package/build/main/lib/types.js +2 -0
  18. package/build/main/lib/utils.d.ts +10 -0
  19. package/build/main/lib/utils.js +222 -0
  20. package/build/main/tests/Generator.db.spec.d.ts +1 -0
  21. package/build/main/tests/Generator.db.spec.js +33 -0
  22. package/build/main/tests/Generator.eval.spec.d.ts +1 -0
  23. package/build/main/tests/Generator.eval.spec.js +21 -0
  24. package/build/main/tests/Generator.function.spec.d.ts +1 -0
  25. package/build/main/tests/Generator.function.spec.js +48 -0
  26. package/build/main/tests/Generator.generator.spec.d.ts +1 -0
  27. package/build/main/tests/Generator.generator.spec.js +187 -0
  28. package/build/main/tests/Generator.hasMany.spec.d.ts +1 -0
  29. package/build/main/tests/Generator.hasMany.spec.js +115 -0
  30. package/build/main/tests/Generator.hasOne.spec.d.ts +1 -0
  31. package/build/main/tests/Generator.hasOne.spec.js +146 -0
  32. package/build/main/tests/Generator.incrementalId.spec.d.ts +1 -0
  33. package/build/main/tests/Generator.incrementalId.spec.js +26 -0
  34. package/build/main/tests/Generator.self.spec.d.ts +1 -0
  35. package/build/main/tests/Generator.self.spec.js +24 -0
  36. package/build/main/tests/Generator.static.spec.d.ts +1 -0
  37. package/build/main/tests/Generator.static.spec.js +15 -0
  38. package/build/main/tests/Generator.values.spec.d.ts +1 -0
  39. package/build/main/tests/Generator.values.spec.js +16 -0
  40. package/build/main/tests/Mocker.build.spec.d.ts +1 -0
  41. package/build/main/tests/Mocker.build.spec.js +196 -0
  42. package/build/main/tests/Mocker.reset.spec.d.ts +1 -0
  43. package/build/main/tests/Mocker.reset.spec.js +17 -0
  44. package/build/main/tests/Mocker.restart.spec.d.ts +1 -0
  45. package/build/main/tests/Mocker.restart.spec.js +24 -0
  46. package/build/main/tests/Mocker.schema.spec.d.ts +1 -0
  47. package/build/main/tests/Mocker.schema.spec.js +18 -0
  48. package/build/main/tests/Mocker.seed.spec.d.ts +1 -0
  49. package/build/main/tests/Mocker.seed.spec.js +42 -0
  50. package/build/main/tests/Schema.Array.spec.d.ts +1 -0
  51. package/build/main/tests/Schema.Array.spec.js +332 -0
  52. package/build/main/tests/Schema.BuildSingle.spec.d.ts +1 -0
  53. package/build/main/tests/Schema.BuildSingle.spec.js +13 -0
  54. package/build/main/tests/mocker.spec.d.ts +1 -0
  55. package/build/main/tests/mocker.spec.js +405 -0
  56. package/build/module/array-includes.js +45 -0
  57. package/build/module/index.js +7 -0
  58. package/build/module/lib/Generator.js +131 -0
  59. package/build/module/lib/Mocker.js +73 -0
  60. package/build/module/lib/Schema.js +207 -0
  61. package/build/module/lib/types.js +1 -0
  62. package/build/module/lib/utils.js +209 -0
  63. package/package.json +130 -0
package/README.md ADDED
@@ -0,0 +1,550 @@
1
+ # mocker-data-generator [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Im%20testing%20mocker-data-generator%20is%20awesome!&via=danibram&url=http://bit.ly/2ziE8qT&hashtags=mock,javascript,developers)
2
+
3
+ [![npm version](https://img.shields.io/npm/v/mocker-data-generator.svg?style=flat-square)][npm-home-module][![GitHub license](https://img.shields.io/npm/dt/mocker-data-generator.svg?style=flat-square)][npm-home-module]
4
+
5
+ [![Linux Build status][travis-badge]][travis-link][![Windows Build status][appveyor-badge]][appveyor-link][![Codecov coverage][codecov-badge]][codecov-link][![Codecov coverage][coveralls-badge]][coveralls-link]
6
+
7
+ [![GitHub license](https://img.shields.io/github/license/danibram/mocker-data-generator.svg?style=flat-square)][npm-home-module][![Awesome license](https://img.shields.io/badge/bateries-included-orange.svg?style=flat-square)][npm-home-module]
8
+
9
+ [![Support link][paypal-badge]][paypal-link]
10
+
11
+ A simplified way to generate massive mock data based on a schema, using the awesome fake/random data generators like ([Faker-JS](https://fakerjs.dev/), ChanceJs, CasualJs and RandExpJs), all in one tool to generate your fake data for testing.
12
+
13
+ Now the library has been migrated 100% to typescript typing are included.
14
+
15
+ You can test online here: [https://danibram.github.io/mocker-data-generator/](https://danibram.github.io/mocker-data-generator/)
16
+
17
+ ## Getting started
18
+
19
+ Install the module and the awesome generator you want:
20
+ `npm install mocker-data-generator @faker-js/faker`
21
+
22
+ Import it
23
+
24
+ ```javascript
25
+ var mocker = require('mocker-data-generator').default // (vanilla way)
26
+ var { faker } = require('@faker-js/faker')
27
+
28
+
29
+ // or
30
+
31
+ import mocker from 'mocker-data-generator' // (ES6 or Typescript way)
32
+ import { faker } from '@faker-js/faker'
33
+ ```
34
+
35
+ Then use it:
36
+
37
+ ```javascript
38
+ var user = {
39
+ firstName: {
40
+ faker: 'person.firstName()'
41
+ },
42
+ lastName: {
43
+ faker: 'person.lastName()'
44
+ },
45
+ country: {
46
+ faker: 'location.country()'
47
+ },
48
+ createdAt: {
49
+ faker: 'date.past()'
50
+ },
51
+ username: {
52
+ function: function () {
53
+ return (
54
+ this.object.lastName.substring(0, 5) +
55
+ this.object.firstName.substring(0, 3) +
56
+ Math.floor(Math.random() * 10)
57
+ )
58
+ }
59
+ }
60
+ }
61
+ var group = {
62
+ description: {
63
+ faker: 'lorem.paragraph()'
64
+ },
65
+ users: [
66
+ {
67
+ function: function () {
68
+ return this.generators.faker.helpers.arrayElement(this.db.user)
69
+ .username
70
+ },
71
+ length: 10,
72
+ fixedLength: false
73
+ }
74
+ ]
75
+ }
76
+ var conditionalField = {
77
+ type: {
78
+ values: ['HOUSE', 'CAR', 'MOTORBIKE']
79
+ },
80
+ 'object.type=="HOUSE",location': {
81
+ faker: 'location.city()'
82
+ },
83
+ 'object.type=="CAR"||object.type=="MOTORBIKE",speed': {
84
+ faker: 'number.int()'
85
+ }
86
+ }
87
+
88
+ // Using traditional callback Style
89
+
90
+ mocker()
91
+ .addGenerator('faker', faker)
92
+ .schema('user', user, 2)
93
+ .schema('group', group, 2)
94
+ .schema('conditionalField', conditionalField, 2)
95
+ .build(function (error, data) {
96
+ if (error) {
97
+ throw error
98
+ }
99
+ console.log(util.inspect(data, { depth: 10 }))
100
+
101
+ // This returns an object
102
+ // {
103
+ // user:[array of users],
104
+ // group: [array of groups],
105
+ // conditionalField: [array of conditionalFields]
106
+ // }
107
+ })
108
+
109
+ // Using promises
110
+
111
+ mocker()
112
+ .addGenerator('faker', faker)
113
+ .schema('user', user, 2)
114
+ .schema('group', group, 2)
115
+ .schema('conditionalField', conditionalField, 2)
116
+ .build()
117
+ .then(
118
+ data => {
119
+ console.log(util.inspect(data, { depth: 10 }))
120
+ // This returns an object
121
+ // {
122
+ // user:[array of users],
123
+ // group: [array of groups],
124
+ // conditionalField: [array of conditionalFields]
125
+ // }
126
+ },
127
+ err => console.error(err)
128
+ )
129
+
130
+ // Synchronously
131
+
132
+ // This returns an object
133
+ // {
134
+ // user:[array of users],
135
+ // group: [array of groups],
136
+ // conditionalField: [array of conditionalFields]
137
+ // }
138
+ var data = mocker()
139
+ .addGenerator('faker', faker)
140
+ .schema('user', user, 2)
141
+ .schema('group', group, 2)
142
+ .schema('conditionalField', conditionalField, 2)
143
+ .buildSync()
144
+
145
+ console.log(util.inspect(data, { depth: 10 }))
146
+ ```
147
+ NOTE:
148
+ For the demo above you will also need to import util i.e.
149
+ `var util = require('util') or import util from 'util'`
150
+
151
+ ## Documentation
152
+
153
+ Data generation goes with model based composed by generators, the generators can have access to the data generated and to the entity generated. **_Generators run synchronously, take care of the related entities!!_**
154
+
155
+ ### Methods
156
+
157
+ * **_addGenerator(name, generator, runFn)_**: Add a new generator, now generators are not included in the package, so you have to add whathever generator you want.
158
+
159
+ * name (String): key of the generator this should match with the key in the schema.
160
+ * generator (library): Library if the generator
161
+ * runFN (function) (Optional) (generator: any, input: any) => any : It compose a exec function for the selected generator, only for custom generators, see randexp in the examples folder
162
+
163
+ * **_schema(name, schema, generationType)_**: Add a new schema, you must specify this params:
164
+
165
+ * name (String): Name of the schema.
166
+ * schema (JSON): The schema you define
167
+ * generationType (integer or JSON): In this field you specify how you will generate this schema. 3 ways:
168
+ * Integer to specify how many objects of this schema you want.
169
+ * JSON with this object `{max: '<maximunValues>'}` you can also optionally pass min `{max: '<maximunValues>', min: '<minimumValues>'`, this will generate a range of objects of this schema, between (0 and max) or (min and max) randomly.
170
+ * JSON with this object `{uniqueField: '<yourUniqueField>'}` this means that this field (<yourUniqueField>) is an array and you want to generate entities with this unique values
171
+
172
+ * **_reset()_**: Clean the internal DB.
173
+ * **_restart()_**: Clean the internal DB and all the schemas inside.
174
+ * **_build(callback)_**: This methods start to produce the data and wrap it to the callback function, the callback funtion have 2 parameters, error and data generated.
175
+ - **_buildSync()_**: Synchronous version of `build(callback)`. Returns generated data or throws an error.
176
+
177
+ ### Schema definition
178
+
179
+ #### Every schema should contains the specified fields. Key can be 2 types:
180
+
181
+ * **_Normal string_** key: indicates the key.
182
+ * **_Commaseparated string_** key: indicates that there is a conditional, before the comma you must specify a conditional (you have all level fields generated in this moment), then you must specify the field if the conditional is true see the example.
183
+
184
+ #### Inside every value you can put:
185
+
186
+ * **_static_**: For fixed fields
187
+
188
+ ```javascript
189
+ {
190
+ static: 'hello im fixed field'
191
+ }
192
+ ```
193
+
194
+ * **_self_**: get himself object, and evaluate the string, so you can get calculated fields.
195
+
196
+ * **_eval_** (Optional): Also now you can pass, eval to true, to use like in versions < 2.6.0
197
+
198
+
199
+ ```javascript
200
+ {
201
+ self: 'id'
202
+ } //will get the id of the generated entity
203
+
204
+ {
205
+ self: 'id',
206
+ eval: true
207
+ } // will get the first user id
208
+ ```
209
+
210
+ * **_db_**: get the db, and evaluate the string, so you can access to this entities.
211
+
212
+ * **_eval_** (Optional): Also now you can pass, fast to true, eval to true, to use like in versions < 2.6.0
213
+
214
+
215
+ ```javascript
216
+ {
217
+ db: 'user[0].id'
218
+ } // will get the first user id
219
+
220
+ {
221
+ db: 'user[0].id',
222
+ eval: true
223
+ } // will get the first user id
224
+ ```
225
+
226
+ * **_eval_**: evaluate the current string, remember that all context are injected (generators, db the actual object). With this eval field, **_you must pass an exactly JSON syntax_**:
227
+
228
+ ```javascript
229
+ {
230
+ eval: 'object.id'
231
+ }
232
+
233
+ // OR
234
+
235
+ {
236
+ eval: 'db.user[0]'
237
+ }
238
+
239
+ // OR
240
+
241
+ {
242
+ eval: 'faker.lorem.words()'
243
+ }
244
+ ```
245
+
246
+ * **_hasOne_**: You can pass 2 parameters:
247
+
248
+ * **_hasOne_**: the name of the related entity, get one random.
249
+ * **_get_** (Optional): String that will be evaluated over the random related entity.
250
+ * **_eval_** (Optional): Only affects if get is passed, the get param only support dotted paths, with eval=true you can use an eval string, this impacts on the performance
251
+
252
+ ```javascript
253
+ {
254
+ hasOne: 'user'
255
+ } // this populate the field with one random user
256
+
257
+ // OR:
258
+
259
+ {
260
+ hasOne: 'user',
261
+ get: 'id'
262
+ } // this populate the field with one id of a random user
263
+
264
+
265
+ // OR:
266
+
267
+ {
268
+ hasOne: 'user',
269
+ get: 'id',
270
+ eval: true
271
+ } // this populate the field with one id of a random user with eval string
272
+ ```
273
+
274
+ * **_hasMany_**: You can pass 4 parameters:
275
+
276
+ * **_hasMany_**: the name of the related entity, get one random.
277
+ * **_amount_** (Optional): Fixed number of related entities to get.
278
+ * **_min_** (Optional): Minimum entities to get, buy default is 1, if you want the chance to have empty arrays please specify min to 0.
279
+ * **_max_** (Optional): Maximum entities to get.
280
+ * **_get_** (Optional): String that will be evaluated over the random related entity.
281
+ * **_eval_** (Optional): Get will only support dotted paths, with eval= true you can get from an evaluable string
282
+ * **_unique_** (Optional): hasMany will get unique values from the entity (Make sure that you have many unique data in the source)
283
+
284
+ ```javascript
285
+ // In this case we will get 1 user (hasMany)
286
+ {
287
+ hasMany: 'user'
288
+ } // this populate the field with one random user
289
+
290
+ // OR:
291
+
292
+
293
+ {
294
+ hasMany: 'user',
295
+ amount: 1, //optional
296
+ } // In this case we will get 1 (amount) user (hasMany)
297
+
298
+ // OR:
299
+
300
+ {
301
+ hasMany: 'user',
302
+ max: 3 // optional
303
+ } // In this case we will get as max 3 (max) users (hasMany)
304
+
305
+ // OR:
306
+
307
+
308
+ {
309
+ hasMany: 'user',
310
+ min: 1 //optional
311
+ max: 3 //optional
312
+ } // In this case we will get bettween min 1 (min) and max 3 (max) users (hasMany)
313
+
314
+ // OR:
315
+
316
+ {
317
+ hasMany: 'user',
318
+ get: 'id'
319
+ } // In this case we will get the id (get) from 1 random user (hasMany)
320
+ ```
321
+
322
+ * **_incrementalId_**: For incremental numeric ids, pass the start number to increment. If you put incrementalId = true it takes from 0 the ids.
323
+
324
+ ```javascript
325
+ {
326
+ incrementalId: 0
327
+ }
328
+ ```
329
+
330
+ * **_function_**: No params are passed, only context (`this`), in this you have `{db, object, faker, chance}`, and you can use faker or chance functions, object (the specified model), db (actual data generated)
331
+
332
+ ```javascript
333
+ { function: function(){
334
+
335
+ // this.db
336
+ // this.object
337
+ // this.generators
338
+
339
+ return yourValue
340
+ } }
341
+
342
+ // OR:
343
+
344
+ { function(){
345
+
346
+ // this.db
347
+ // this.object
348
+ // this.generators
349
+
350
+ return yourValue
351
+ } }
352
+ ```
353
+
354
+ * **_[Array]_**: you can pass an array that indicates an array of data you can create, passing in the first field the generator (function, faker, or array(not Tested)), and in the second field pass a config object (length, fixedLentgh)
355
+
356
+ * **_length_**: to know how many values
357
+ * **_fixedLength_** (Optional): true to create always same amount of values in the array, false to generate a random number between 0 and 'length' value. False by default.
358
+ * **_concat_** (Optional): An stringuified array ex: '[object.id, db.users.id]'. This should be an evaluable string to concat with the array that are generating. Also takes in mind that if you have a fixedLength, should not increase the length.
359
+ * **_strictConcat_** (Optional): true to remove duplicates in the concatenated string array, when it is calculated. False by default.
360
+
361
+ ```javascript
362
+ [{
363
+ // Any generator
364
+ // Faker
365
+ [name of the generator injected]: 'path inside the generator'
366
+ // If faker is injected with .addGenerator('faker', faker) then you can use:
367
+ faker: 'helpers.arrayElement(db.users).userId'
368
+ // Function that has included index, length and self that refers at the actual array generation
369
+ function: function (index, length, self){ return /**/ }
370
+
371
+ // Array config
372
+ length: 10,
373
+ fixedLength: true
374
+
375
+ // Concat
376
+ concat: '[db.users[0].userId, db.users[1].userId]'
377
+ strictConcat: true
378
+ }]
379
+ ```
380
+
381
+ ### Custom generators
382
+
383
+ It happens!Mocker now is independant of the generators so I hope this will give you more freedom. This is an example that you can check on the examples folder, where 2 generators are used:
384
+
385
+ ```javascript
386
+ var mocker = require('../build/main').default
387
+ var { faker } = require('@faker-js/faker')
388
+ var Randexp = require('randexp')
389
+ var util = require('util')
390
+
391
+ var user = {
392
+ firstName: {
393
+ faker: 'person.firstName()'
394
+ },
395
+ notes: {
396
+ randexp: /hello+ (world|to you)/
397
+ }
398
+ }
399
+
400
+ mocker()
401
+ .addGenerator('faker', faker)
402
+ .addGenerator('randexp', Randexp, function (generator, input) {
403
+ return new generator(input).gen()
404
+ })
405
+ .schema('user', user, 2)
406
+ .build(function (error, data) {
407
+ if (error) {
408
+ throw error
409
+ }
410
+ console.log(util.inspect(data, { depth: 10 }))
411
+ })
412
+ ```
413
+
414
+ ### Optional fields
415
+
416
+ * **_[virtual]_**: Boolean, if you pass this option, this mean that this field will not appear at the output entity. But you can use during the generation.
417
+
418
+ ```javascript
419
+ {
420
+ // Any generator
421
+ // Faker
422
+ [name of the generator injected]: 'path inside the generator'
423
+ // If faker is injected with .addGenerator('faker', faker) then you can use:
424
+ faker: 'helpers.arrayElement(db.users).userId'
425
+ // Static
426
+ static: 'any static field'
427
+ // Function
428
+ function: function (){ return /**/ }
429
+
430
+ // With the virtual option
431
+ virtual: true
432
+
433
+ }
434
+ ```
435
+
436
+ ### Data generation
437
+
438
+ Initialize mocker with the config, and then generate any entity with promises style, use generate function that accepts the name of the model and the amount of data to generate. Like the example:
439
+
440
+ ```javascript
441
+ mocker()
442
+ .addGenerator('faker', faker)
443
+ .schema('user', user, 2)
444
+ .schema('group', group, 2)
445
+ .schema('conditionalField', conditionalField, 2)
446
+ .build(function(err, data) {
447
+ console.log(util.inspect(data, { depth: 10 }))
448
+ // This returns an object
449
+ // {
450
+ // user:[array of users],
451
+ // group: [array of groups],
452
+ // conditionalField: [array of conditionalFields]
453
+ // }
454
+ })
455
+ ```
456
+
457
+ You can also pass instead of the number, an object with the a config, from now `{uniqueField}`. If this field exists tells to the generator that instead of init a fixed length of data, generate an amount of data depending of the values of the field you will specify. You have 2 way to deal with this, check the examples See the output of this example:
458
+
459
+ ```javascript
460
+ //
461
+ // First way, using an 'values' embedded object
462
+ //
463
+
464
+ var cat = {
465
+ name: {
466
+ values: ['txuri', 'pitxi', 'kitty']
467
+ }
468
+ }
469
+ var m = mocker()
470
+ .addGenerator('faker', faker)
471
+ .schema('cat', cat, 10)
472
+ .schema('cat2', cat, { uniqueField: 'name' })
473
+ .build(function(err, data) {
474
+ console.log(util.inspect(data, { depth: 10 }))
475
+ })
476
+
477
+ //
478
+ // Second way, without 'values' embedded.
479
+ //
480
+
481
+ var cat = {
482
+ name: ['txuri', 'pitxi', 'kitty']
483
+ }
484
+ var m = mocker()
485
+ .addGenerator('faker', faker)
486
+ .schema('cat', cat, 10)
487
+ .schema('cat2', cat, { uniqueField: 'name' })
488
+ .build(function(err, data) {
489
+ console.log(util.inspect(data, { depth: 10 }))
490
+ })
491
+ ```
492
+
493
+ ### _eval_ Option (Beta):
494
+
495
+ In version >= 2.6.0, eval option was introduced to run mocker-data-generator like olders versions, so by default is running without eval: `faker`, `chance`, `casual`, `hasMany`, `hasOne`, `db` and `self`. This means that this methods loose habilities, when eval is not passed, but this are the speed results with eval active (old way) and without (new way)
496
+
497
+ ```
498
+ faker eval old: 0.969ms
499
+ faker now: 0.215ms
500
+ chance eval old: 0.559ms
501
+ chance now: 0.099ms
502
+ casual eval old: 0.360ms
503
+ casual now: 0.026ms
504
+ ```
505
+
506
+ ### More, Coming soon
507
+
508
+ ## Online API
509
+
510
+ You can visit the repo url here: [https://github.com/danibram/mocker-api-tester](https://github.com/danibram/mocker-api-tester)
511
+
512
+ Or visit the api directly: [https://mocker-api.herokuapp.com/](https://mocker-api.herokuapp.com/)
513
+
514
+ ## Development
515
+
516
+ Run `npm install;npm run dev` to watch the project, webpack compile the code automatically. Run `npm build` to build the normal and minified version.
517
+
518
+ ## Why not use json-schema-faker?
519
+
520
+ json-schema-faker is awesome and works really nice, but i need a simplified and fast way to generate mock data for my projects, so i created this.
521
+
522
+ ## Credits
523
+
524
+ I couldn't do this without this awesome libraries, so thanks to all:
525
+
526
+ * Faker: [[https://github.com/faker-js/faker](https://github.com/faker-js/faker)]
527
+ * Chance: [[https://github.com/victorquinn/chancejs](https://github.com/victorquinn/chancejs)]
528
+ * Casual: [[https://github.com/boo1ean/casual](https://github.com/boo1ean/casual)]
529
+ * RandExpJs: [[https://github.com/fent/randexp.js](https://github.com/fent/randexp.js)]
530
+ * typescript-starter: [[https://github.com/bitjson/typescript-starter](https://github.com/bitjson/typescript-starter)]
531
+
532
+ ## License
533
+
534
+ Licensed under the MIT license. 2022
535
+
536
+ [paypal-badge]: https://img.shields.io/badge/❤%20support-paypal-blue.svg?style=flat-square
537
+ [paypal-link]: https://www.paypal.me/danibram
538
+ [https://github.com/faker-js/faker]: https://github.com/faker-js/faker
539
+ [https://github.com/victorquinn/chancejs]: https://github.com/victorquinn/chancejs
540
+ [https://github.com/boo1ean/casual]: https://github.com/boo1ean/casual
541
+ [https://github.com/fent/randexp.js]: https://github.com/fent/randexp.js
542
+ [coveralls-link]: https://coveralls.io/github/danibram/mocker-data-generator
543
+ [coveralls-badge]: https://img.shields.io/coveralls/danibram/mocker-data-generator.svg?style=flat-square&label=coveralls%20coverage
544
+ [codecov-badge]: https://img.shields.io/codecov/c/github/danibram/mocker-data-generator.svg?style=flat-square&label=codecov%20coverage
545
+ [codecov-link]: https://codecov.io/github/danibram/mocker-data-generator
546
+ [npm-home-module]: https://www.npmjs.com/package/mocker-data-generator
547
+ [appveyor-badge]: https://img.shields.io/appveyor/ci/danibram/mocker-data-generator.svg?style=flat-square&label=windows
548
+ [appveyor-link]: https://ci.appveyor.com/project/danibram/mocker-data-generator
549
+ [travis-link]: https://travis-ci.org/danibram/mocker-data-generator
550
+ [travis-badge]: https://img.shields.io/travis/danibram/mocker-data-generator.svg?style=flat-square&label=linux
File without changes
@@ -0,0 +1,45 @@
1
+ if (!Array.prototype.includes) {
2
+ Object.defineProperty(Array.prototype, 'includes', {
3
+ value: function (searchElement, fromIndex) {
4
+ // 1. Let O be ? ToObject(this value).
5
+ if (this == null) {
6
+ throw new TypeError('"this" is null or not defined');
7
+ }
8
+ var o = Object(this);
9
+ // 2. Let len be ? ToLength(? Get(O, "length")).
10
+ var len = o.length >>> 0;
11
+ // 3. If len is 0, return false.
12
+ if (len === 0) {
13
+ return false;
14
+ }
15
+ // 4. Let n be ? ToInteger(fromIndex).
16
+ // (If fromIndex is undefined, this step produces the value 0.)
17
+ var n = fromIndex | 0;
18
+ // 5. If n ≥ 0, then
19
+ // a. Let k be n.
20
+ // 6. Else n < 0,
21
+ // a. Let k be len + n.
22
+ // b. If k < 0, let k be 0.
23
+ var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
24
+ function sameValueZero(x, y) {
25
+ return (x === y ||
26
+ (typeof x === 'number' &&
27
+ typeof y === 'number' &&
28
+ isNaN(x) &&
29
+ isNaN(y)));
30
+ }
31
+ // 7. Repeat, while k < len
32
+ while (k < len) {
33
+ // a. Let elementK be the result of ? Get(O, ! ToString(k)).
34
+ // b. If SameValueZero(searchElement, elementK) is true, return true.
35
+ // c. Increase k by 1.
36
+ if (sameValueZero(o[k], searchElement)) {
37
+ return true;
38
+ }
39
+ k++;
40
+ }
41
+ // 8. Return false
42
+ return false;
43
+ }
44
+ });
45
+ }
@@ -0,0 +1,7 @@
1
+ import './array-includes';
2
+ import { Mocker } from './lib/Mocker';
3
+ export * from './lib/Mocker';
4
+ export * from './lib/Schema';
5
+ export * from './lib/Generator';
6
+ export declare const mocker: (opts?: any) => Mocker;
7
+ export default mocker;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mocker = void 0;
4
+ var tslib_1 = require("tslib");
5
+ require("./array-includes");
6
+ var Mocker_1 = require("./lib/Mocker");
7
+ tslib_1.__exportStar(require("./lib/Mocker"), exports);
8
+ tslib_1.__exportStar(require("./lib/Schema"), exports);
9
+ tslib_1.__exportStar(require("./lib/Generator"), exports);
10
+ var mocker = function (opts) { return new Mocker_1.Mocker(opts); };
11
+ exports.mocker = mocker;
12
+ exports.default = exports.mocker;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var ava_1 = require("ava");
4
+ var _1 = require("./"), lib = _1;
5
+ (0, ava_1.default)('functions can be used without es imports', function (t) {
6
+ t.true(typeof _1.default === 'function');
7
+ t.true(typeof lib.mocker === 'function');
8
+ t.true(typeof lib.Mocker === 'function');
9
+ t.true(typeof lib.Generator === 'function');
10
+ t.true(typeof lib.Schema === 'function');
11
+ });
12
+ (0, ava_1.default)('Mocker: exists all methods', function (t) {
13
+ var m = (0, _1.default)();
14
+ var methods = ['schema', 'build', 'reset', 'restart'];
15
+ methods.forEach(function (method) { return t.true(typeof m[method] === 'function'); });
16
+ });