faker 1.0.0

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 (56) hide show
  1. package/.jshintignore +3 -0
  2. package/.jshintrc +87 -0
  3. package/.npmignore +16 -0
  4. package/.travis.yml +5 -0
  5. package/BUILD/BUILD.js +139 -0
  6. package/BUILD/Mustache.js +296 -0
  7. package/BUILD/docs.js +62 -0
  8. package/BUILD/main.js +60 -0
  9. package/MIT-LICENSE.txt +20 -0
  10. package/Makefile +26 -0
  11. package/Readme.md +46 -0
  12. package/examples/bigDataSet.json +1 -0
  13. package/examples/browser_test.html +40 -0
  14. package/examples/dataSet.json +1 -0
  15. package/examples/index.html +77 -0
  16. package/examples/js/faker.js +730 -0
  17. package/examples/js/jquery.js +154 -0
  18. package/examples/js/prettyPrint.js +712 -0
  19. package/examples/library_test.js +9 -0
  20. package/examples/node_generateSet.js +20 -0
  21. package/examples/node_min_test.js +9 -0
  22. package/faker.js +730 -0
  23. package/index.js +31 -0
  24. package/lib/address.js +100 -0
  25. package/lib/company.js +36 -0
  26. package/lib/date.js +42 -0
  27. package/lib/definitions.js +1398 -0
  28. package/lib/helpers.js +124 -0
  29. package/lib/image.js +58 -0
  30. package/lib/internet.js +53 -0
  31. package/lib/lorem.js +45 -0
  32. package/lib/name.js +34 -0
  33. package/lib/phone_number.js +16 -0
  34. package/lib/random.js +106 -0
  35. package/lib/tree.js +69 -0
  36. package/lib/version.js +0 -0
  37. package/logo.png +0 -0
  38. package/minfaker.js +35 -0
  39. package/package.json +25 -0
  40. package/test/address.unit.js +293 -0
  41. package/test/all.functional.js +47 -0
  42. package/test/browser.unit.html +28 -0
  43. package/test/company.unit.js +110 -0
  44. package/test/date.unit.js +65 -0
  45. package/test/helpers.unit.js +62 -0
  46. package/test/image.unit.js +108 -0
  47. package/test/internet.unit.js +92 -0
  48. package/test/lorem.unit.js +178 -0
  49. package/test/mocha.opts +5 -0
  50. package/test/name.unit.js +87 -0
  51. package/test/phone_number.unit.js +29 -0
  52. package/test/run.js +68 -0
  53. package/test/support/chai.js +3403 -0
  54. package/test/support/sinon-1.5.2.js +4153 -0
  55. package/test/support/walk_dir.js +43 -0
  56. package/test/tree.unit.js +108 -0
@@ -0,0 +1,43 @@
1
+ var fs = require('fs');
2
+
3
+ var methods = {
4
+ walk: function (dir, validation_function, cb) {
5
+ if (arguments.length === 2) {
6
+ cb = validation_function;
7
+ validation_function = null;
8
+ }
9
+
10
+ var results = [];
11
+ fs.readdir(dir, function (err, list) {
12
+ if (err) { return cb(err); }
13
+
14
+ var pending = list.length;
15
+
16
+ if (!pending) { return cb(null, results); }
17
+
18
+ list.forEach(function (file) {
19
+ file = dir + '/' + file;
20
+ fs.stat(file, function (err, stat) {
21
+ if (stat && stat.isDirectory()) {
22
+ methods.walk(file, validation_function, function (err, res) {
23
+ results = results.concat(res);
24
+ if (!--pending) { cb(null, results); }
25
+ });
26
+ } else {
27
+ if (typeof validation_function === 'function') {
28
+ if (validation_function(file)) {
29
+ results.push(file);
30
+ }
31
+ } else {
32
+ results.push(file);
33
+ }
34
+
35
+ if (!--pending) { cb(null, results); }
36
+ }
37
+ });
38
+ });
39
+ });
40
+ }
41
+ };
42
+
43
+ module.exports = methods;
@@ -0,0 +1,108 @@
1
+ if (typeof module !== 'undefined') {
2
+ var assert = require('assert');
3
+ var sinon = require('sinon');
4
+ var faker = require('../index');
5
+ }
6
+
7
+ describe("tree.js", function () {
8
+ describe("createTree()", function () {
9
+
10
+ var proto = {
11
+ "firstname": "faker.random.first_name()",
12
+ "children": "__RECURSE__"
13
+ };
14
+
15
+ it("requires the width to be at least one", function () {
16
+ sinon.spy(faker.Tree, 'createTree');
17
+
18
+ try {
19
+ faker.Tree.createTree(0, 0, {});
20
+ }
21
+ catch (e) {
22
+ }
23
+
24
+ assert.ok(faker.Tree.createTree.threw);
25
+
26
+ faker.Tree.createTree.restore();
27
+ });
28
+
29
+ it("requires that the object passed in should not be null", function () {
30
+ sinon.spy(faker.Tree, 'createTree');
31
+
32
+ try {
33
+ faker.Tree.createTree(1, 1, null);
34
+ }
35
+ catch (e) {
36
+ }
37
+
38
+ assert.ok(faker.Tree.createTree.threw);
39
+
40
+ faker.Tree.createTree.restore();
41
+
42
+ });
43
+
44
+ it("can create a trivial tree with one node", function () {
45
+ sinon.spy(faker.random, 'first_name');
46
+
47
+ var tree = faker.Tree.createTree(0, 1, proto);
48
+
49
+ assert.ok(faker.random.first_name.calledOnce);
50
+
51
+ assert.ok(tree.children == null);
52
+
53
+ faker.random.first_name.restore();
54
+ });
55
+
56
+ it("can create a deep tree with one node at each level", function () {
57
+ sinon.spy(faker.random, 'first_name');
58
+ var tree = faker.Tree.createTree(2, 1, proto);
59
+
60
+ assert.ok(faker.random.first_name.calledThrice);
61
+
62
+ assert.ok(tree.firstname);
63
+ assert.ok(tree.children[0].firstname);
64
+ assert.ok(tree.children[0].children[0].firstname);
65
+
66
+ faker.random.first_name.restore();
67
+ });
68
+
69
+ it("can create a basic N-tree", function () {
70
+ var n = 3;
71
+ sinon.spy(faker.random, 'first_name');
72
+ var tree = faker.Tree.createTree(1, n, proto);
73
+
74
+ assert.ok(faker.random.first_name.callCount == 4);
75
+
76
+ assert.ok(tree.firstname);
77
+ assert.ok(tree.children[0].firstname);
78
+ assert.ok(tree.children[1].firstname);
79
+ assert.ok(tree.children[2].firstname);
80
+
81
+ faker.random.first_name.restore();
82
+ });
83
+
84
+ it("can create a full N-tree", function () {
85
+ var n = 3;
86
+ sinon.spy(faker.random, 'first_name');
87
+ var tree = faker.Tree.createTree(2, n, proto);
88
+
89
+ assert.ok(faker.random.first_name.callCount == 13);
90
+
91
+ faker.random.first_name.restore();
92
+ });
93
+
94
+ it("can accept a function for the width", function () {
95
+ var widthFuncCalled = 0;
96
+ var widthFunc = function () {
97
+ widthFuncCalled = widthFuncCalled + 1;
98
+ return 2;
99
+ };
100
+
101
+ var tree = faker.Tree.createTree(2, widthFunc, proto);
102
+ assert.equal(widthFuncCalled, 3);
103
+
104
+
105
+ });
106
+
107
+ });
108
+ });