holmes 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/README.md +10 -0
  4. data/Rakefile +1 -0
  5. data/holmes.gemspec +24 -0
  6. data/lib/holmes.rb +38 -0
  7. data/lib/holmes/node_modules/detective/README.markdown +64 -0
  8. data/lib/holmes/node_modules/detective/example/strings.js +6 -0
  9. data/lib/holmes/node_modules/detective/example/strings_src.js +3 -0
  10. data/lib/holmes/node_modules/detective/index.js +65 -0
  11. data/lib/holmes/node_modules/detective/node_modules/burrito/.npmignore +1 -0
  12. data/lib/holmes/node_modules/detective/node_modules/burrito/README.markdown +185 -0
  13. data/lib/holmes/node_modules/detective/node_modules/burrito/browserify.js +4296 -0
  14. data/lib/holmes/node_modules/detective/node_modules/burrito/example/microwave.js +7 -0
  15. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/bs.js +4832 -0
  16. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/index.html +14 -0
  17. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/main.js +17 -0
  18. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/server.js +12 -0
  19. data/lib/holmes/node_modules/detective/node_modules/burrito/example/wrap.js +7 -0
  20. data/lib/holmes/node_modules/detective/node_modules/burrito/index.html +8 -0
  21. data/lib/holmes/node_modules/detective/node_modules/burrito/index.js +208 -0
  22. data/lib/holmes/node_modules/detective/node_modules/burrito/main.js +11 -0
  23. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/.bin/uglifyjs +317 -0
  24. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/.npmignore +1 -0
  25. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/LICENSE +24 -0
  26. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/README.markdown +237 -0
  27. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/json.js +16 -0
  28. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/leaves.js +15 -0
  29. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/negative.js +8 -0
  30. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/scrub.js +10 -0
  31. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/stringify.js +38 -0
  32. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/index.js +267 -0
  33. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/main.js +10 -0
  34. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/package.json +18 -0
  35. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/circular.js +115 -0
  36. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/date.js +35 -0
  37. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/equal.js +220 -0
  38. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/instance.js +17 -0
  39. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/interface.js +42 -0
  40. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/json.js +47 -0
  41. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/keys.js +29 -0
  42. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/leaves.js +21 -0
  43. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/lib/deep_equal.js +92 -0
  44. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/mutability.js +252 -0
  45. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/negative.js +20 -0
  46. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/obj.js +15 -0
  47. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/siblings.js +35 -0
  48. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/stop.js +41 -0
  49. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/stringify.js +36 -0
  50. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/subexpr.js +34 -0
  51. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/super_deep.js +55 -0
  52. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/.npmignore +4 -0
  53. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/README.html +888 -0
  54. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/README.org +463 -0
  55. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/bin/uglifyjs +317 -0
  56. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/docstyle.css +75 -0
  57. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/object-ast.js +75 -0
  58. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/parse-js.js +1341 -0
  59. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/process.js +1949 -0
  60. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/squeeze-more.js +51 -0
  61. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/package.json +22 -0
  62. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/beautify.js +28 -0
  63. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/testparser.js +402 -0
  64. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array1.js +1 -0
  65. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array2.js +1 -0
  66. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array3.js +1 -0
  67. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array4.js +1 -0
  68. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/assignment.js +1 -0
  69. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/concatstring.js +1 -0
  70. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/const.js +1 -0
  71. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/empty-blocks.js +1 -0
  72. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/forstatement.js +1 -0
  73. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/if.js +1 -0
  74. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/ifreturn.js +1 -0
  75. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/ifreturn2.js +1 -0
  76. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue10.js +1 -0
  77. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue11.js +1 -0
  78. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue13.js +1 -0
  79. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue14.js +1 -0
  80. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue16.js +1 -0
  81. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue17.js +1 -0
  82. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue20.js +1 -0
  83. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue21.js +1 -0
  84. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue25.js +1 -0
  85. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue27.js +1 -0
  86. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue28.js +1 -0
  87. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue29.js +1 -0
  88. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue30.js +1 -0
  89. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue34.js +1 -0
  90. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue4.js +1 -0
  91. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue48.js +1 -0
  92. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue50.js +1 -0
  93. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue53.js +1 -0
  94. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue54.1.js +1 -0
  95. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue68.js +1 -0
  96. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue69.js +1 -0
  97. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue9.js +1 -0
  98. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/mangle.js +1 -0
  99. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/strict-equals.js +1 -0
  100. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/var.js +1 -0
  101. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/with.js +1 -0
  102. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array1.js +3 -0
  103. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array2.js +4 -0
  104. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array3.js +4 -0
  105. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array4.js +6 -0
  106. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/assignment.js +20 -0
  107. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/concatstring.js +3 -0
  108. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/const.js +5 -0
  109. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/empty-blocks.js +4 -0
  110. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/forstatement.js +10 -0
  111. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/if.js +6 -0
  112. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/ifreturn.js +9 -0
  113. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/ifreturn2.js +16 -0
  114. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue10.js +1 -0
  115. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue11.js +3 -0
  116. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue13.js +1 -0
  117. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue14.js +1 -0
  118. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue16.js +1 -0
  119. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue17.js +4 -0
  120. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue20.js +1 -0
  121. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue21.js +6 -0
  122. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue25.js +7 -0
  123. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue27.js +1 -0
  124. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue28.js +3 -0
  125. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue29.js +1 -0
  126. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue30.js +3 -0
  127. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue34.js +3 -0
  128. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue4.js +3 -0
  129. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue48.js +1 -0
  130. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue50.js +9 -0
  131. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue53.js +1 -0
  132. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue54.1.js +3 -0
  133. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue68.js +5 -0
  134. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue69.js +1 -0
  135. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue9.js +4 -0
  136. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/mangle.js +5 -0
  137. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/strict-equals.js +3 -0
  138. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/var.js +3 -0
  139. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/with.js +2 -0
  140. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/scripts.js +55 -0
  141. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/hoist.js +33 -0
  142. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/instrument.js +97 -0
  143. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/instrument2.js +138 -0
  144. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/test.js +16 -0
  145. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/uglify-js.js +17 -0
  146. data/lib/holmes/node_modules/detective/node_modules/burrito/package.json +43 -0
  147. data/lib/holmes/node_modules/detective/node_modules/burrito/server.js +4 -0
  148. data/lib/holmes/node_modules/detective/node_modules/burrito/test/ast.js +29 -0
  149. data/lib/holmes/node_modules/detective/node_modules/burrito/test/err.js +47 -0
  150. data/lib/holmes/node_modules/detective/node_modules/burrito/test/fail.js +8 -0
  151. data/lib/holmes/node_modules/detective/node_modules/burrito/test/fail/src.js +60 -0
  152. data/lib/holmes/node_modules/detective/node_modules/burrito/test/label.js +110 -0
  153. data/lib/holmes/node_modules/detective/node_modules/burrito/test/microwave.js +33 -0
  154. data/lib/holmes/node_modules/detective/node_modules/burrito/test/parent.js +26 -0
  155. data/lib/holmes/node_modules/detective/node_modules/burrito/test/wrap.js +157 -0
  156. data/lib/holmes/node_modules/detective/package.json +39 -0
  157. data/lib/holmes/node_modules/detective/test/both.js +10 -0
  158. data/lib/holmes/node_modules/detective/test/files/both.js +4 -0
  159. data/lib/holmes/node_modules/detective/test/files/nested.js +22 -0
  160. data/lib/holmes/node_modules/detective/test/files/strings.js +13 -0
  161. data/lib/holmes/node_modules/detective/test/files/word.js +13 -0
  162. data/lib/holmes/node_modules/detective/test/nested.js +8 -0
  163. data/lib/holmes/node_modules/detective/test/strings.js +8 -0
  164. data/lib/holmes/node_modules/detective/test/word.js +11 -0
  165. data/lib/holmes/require.js +5 -0
  166. data/lib/holmes/runner.js +20 -0
  167. data/lib/holmes/version.rb +3 -0
  168. metadata +223 -0
@@ -0,0 +1,47 @@
1
+ var assert = require('assert');
2
+ var Traverse = require('../');
3
+
4
+ exports['json test'] = function () {
5
+ var id = 54;
6
+ var callbacks = {};
7
+ var obj = { moo : function () {}, foo : [2,3,4, function () {}] };
8
+
9
+ var scrubbed = Traverse(obj).map(function (x) {
10
+ if (typeof x === 'function') {
11
+ callbacks[id] = { id : id, f : x, path : this.path };
12
+ this.update('[Function]');
13
+ id++;
14
+ }
15
+ });
16
+
17
+ assert.equal(
18
+ scrubbed.moo, '[Function]',
19
+ 'obj.moo replaced with "[Function]"'
20
+ );
21
+
22
+ assert.equal(
23
+ scrubbed.foo[3], '[Function]',
24
+ 'obj.foo[3] replaced with "[Function]"'
25
+ );
26
+
27
+ assert.deepEqual(scrubbed, {
28
+ moo : '[Function]',
29
+ foo : [ 2, 3, 4, "[Function]" ]
30
+ }, 'Full JSON string matches');
31
+
32
+ assert.deepEqual(
33
+ typeof obj.moo, 'function',
34
+ 'Original obj.moo still a function'
35
+ );
36
+
37
+ assert.deepEqual(
38
+ typeof obj.foo[3], 'function',
39
+ 'Original obj.foo[3] still a function'
40
+ );
41
+
42
+ assert.deepEqual(callbacks, {
43
+ 54: { id: 54, f : obj.moo, path: [ 'moo' ] },
44
+ 55: { id: 55, f : obj.foo[3], path: [ 'foo', '3' ] },
45
+ }, 'Check the generated callbacks list');
46
+ };
47
+
@@ -0,0 +1,29 @@
1
+ var assert = require('assert');
2
+ var Traverse = require('../');
3
+
4
+ exports['sort test'] = function () {
5
+ var acc = [];
6
+ Traverse({
7
+ a: 30,
8
+ b: 22,
9
+ id: 9
10
+ }).forEach(function (node) {
11
+ if ((! Array.isArray(node)) && typeof node === 'object') {
12
+ this.before(function(node) {
13
+ this.keys = Object.keys(node);
14
+ this.keys.sort(function(a, b) {
15
+ a = [a === "id" ? 0 : 1, a];
16
+ b = [b === "id" ? 0 : 1, b];
17
+ return a < b ? -1 : a > b ? 1 : 0;
18
+ });
19
+ });
20
+ }
21
+ if (this.isLeaf) acc.push(node);
22
+ });
23
+
24
+ assert.equal(
25
+ acc.join(' '),
26
+ '9 30 22',
27
+ 'Traversal in a custom order'
28
+ );
29
+ };
@@ -0,0 +1,21 @@
1
+ var assert = require('assert');
2
+ var Traverse = require('../');
3
+
4
+ exports['leaves test'] = function () {
5
+ var acc = [];
6
+ Traverse({
7
+ a : [1,2,3],
8
+ b : 4,
9
+ c : [5,6],
10
+ d : { e : [7,8], f : 9 }
11
+ }).forEach(function (x) {
12
+ if (this.isLeaf) acc.push(x);
13
+ });
14
+
15
+ assert.equal(
16
+ acc.join(' '),
17
+ '1 2 3 4 5 6 7 8 9',
18
+ 'Traversal in the right(?) order'
19
+ );
20
+ };
21
+
@@ -0,0 +1,92 @@
1
+ var traverse = require('../../');
2
+
3
+ module.exports = function (a, b) {
4
+ if (arguments.length !== 2) {
5
+ throw new Error(
6
+ 'deepEqual requires exactly two objects to compare against'
7
+ );
8
+ }
9
+
10
+ var equal = true;
11
+ var node = b;
12
+
13
+ traverse(a).forEach(function (y) {
14
+ var notEqual = (function () {
15
+ equal = false;
16
+ //this.stop();
17
+ return undefined;
18
+ }).bind(this);
19
+
20
+ //if (node === undefined || node === null) return notEqual();
21
+
22
+ if (!this.isRoot) {
23
+ /*
24
+ if (!Object.hasOwnProperty.call(node, this.key)) {
25
+ return notEqual();
26
+ }
27
+ */
28
+ if (typeof node !== 'object') return notEqual();
29
+ node = node[this.key];
30
+ }
31
+
32
+ var x = node;
33
+
34
+ this.post(function () {
35
+ node = x;
36
+ });
37
+
38
+ var toS = function (o) {
39
+ return Object.prototype.toString.call(o);
40
+ };
41
+
42
+ if (this.circular) {
43
+ if (traverse(b).get(this.circular.path) !== x) notEqual();
44
+ }
45
+ else if (typeof x !== typeof y) {
46
+ notEqual();
47
+ }
48
+ else if (x === null || y === null || x === undefined || y === undefined) {
49
+ if (x !== y) notEqual();
50
+ }
51
+ else if (x.__proto__ !== y.__proto__) {
52
+ notEqual();
53
+ }
54
+ else if (x === y) {
55
+ // nop
56
+ }
57
+ else if (typeof x === 'function') {
58
+ if (x instanceof RegExp) {
59
+ // both regexps on account of the __proto__ check
60
+ if (x.toString() != y.toString()) notEqual();
61
+ }
62
+ else if (x !== y) notEqual();
63
+ }
64
+ else if (typeof x === 'object') {
65
+ if (toS(y) === '[object Arguments]'
66
+ || toS(x) === '[object Arguments]') {
67
+ if (toS(x) !== toS(y)) {
68
+ notEqual();
69
+ }
70
+ }
71
+ else if (x instanceof Date || y instanceof Date) {
72
+ if (!(x instanceof Date) || !(y instanceof Date)
73
+ || x.getTime() !== y.getTime()) {
74
+ notEqual();
75
+ }
76
+ }
77
+ else {
78
+ var kx = Object.keys(x);
79
+ var ky = Object.keys(y);
80
+ if (kx.length !== ky.length) return notEqual();
81
+ for (var i = 0; i < kx.length; i++) {
82
+ var k = kx[i];
83
+ if (!Object.hasOwnProperty.call(y, k)) {
84
+ notEqual();
85
+ }
86
+ }
87
+ }
88
+ }
89
+ });
90
+
91
+ return equal;
92
+ };
@@ -0,0 +1,252 @@
1
+ var assert = require('assert');
2
+ var Traverse = require('../');
3
+ var deepEqual = require('./lib/deep_equal');
4
+
5
+ exports.mutate = function () {
6
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
7
+ var res = Traverse(obj).forEach(function (x) {
8
+ if (typeof x === 'number' && x % 2 === 0) {
9
+ this.update(x * 10);
10
+ }
11
+ });
12
+ assert.deepEqual(obj, res);
13
+ assert.deepEqual(obj, { a : 1, b : 20, c : [ 3, 40 ] });
14
+ };
15
+
16
+ exports.mutateT = function () {
17
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
18
+ var res = Traverse.forEach(obj, function (x) {
19
+ if (typeof x === 'number' && x % 2 === 0) {
20
+ this.update(x * 10);
21
+ }
22
+ });
23
+ assert.deepEqual(obj, res);
24
+ assert.deepEqual(obj, { a : 1, b : 20, c : [ 3, 40 ] });
25
+ };
26
+
27
+ exports.map = function () {
28
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
29
+ var res = Traverse(obj).map(function (x) {
30
+ if (typeof x === 'number' && x % 2 === 0) {
31
+ this.update(x * 10);
32
+ }
33
+ });
34
+ assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
35
+ assert.deepEqual(res, { a : 1, b : 20, c : [ 3, 40 ] });
36
+ };
37
+
38
+ exports.mapT = function () {
39
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
40
+ var res = Traverse.map(obj, function (x) {
41
+ if (typeof x === 'number' && x % 2 === 0) {
42
+ this.update(x * 10);
43
+ }
44
+ });
45
+ assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
46
+ assert.deepEqual(res, { a : 1, b : 20, c : [ 3, 40 ] });
47
+ };
48
+
49
+ exports.clone = function () {
50
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
51
+ var res = Traverse(obj).clone();
52
+ assert.deepEqual(obj, res);
53
+ assert.ok(obj !== res);
54
+ obj.a ++;
55
+ assert.deepEqual(res.a, 1);
56
+ obj.c.push(5);
57
+ assert.deepEqual(res.c, [ 3, 4 ]);
58
+ };
59
+
60
+ exports.cloneT = function () {
61
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
62
+ var res = Traverse.clone(obj);
63
+ assert.deepEqual(obj, res);
64
+ assert.ok(obj !== res);
65
+ obj.a ++;
66
+ assert.deepEqual(res.a, 1);
67
+ obj.c.push(5);
68
+ assert.deepEqual(res.c, [ 3, 4 ]);
69
+ };
70
+
71
+ exports.reduce = function () {
72
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
73
+ var res = Traverse(obj).reduce(function (acc, x) {
74
+ if (this.isLeaf) acc.push(x);
75
+ return acc;
76
+ }, []);
77
+ assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
78
+ assert.deepEqual(res, [ 1, 2, 3, 4 ]);
79
+ };
80
+
81
+ exports.reduceInit = function () {
82
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
83
+ var res = Traverse(obj).reduce(function (acc, x) {
84
+ if (this.isRoot) assert.fail('got root');
85
+ return acc;
86
+ });
87
+ assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
88
+ assert.deepEqual(res, obj);
89
+ };
90
+
91
+ exports.remove = function () {
92
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
93
+ Traverse(obj).forEach(function (x) {
94
+ if (this.isLeaf && x % 2 == 0) this.remove();
95
+ });
96
+
97
+ assert.deepEqual(obj, { a : 1, c : [ 3 ] });
98
+ };
99
+
100
+ exports.removeNoStop = function() {
101
+ var obj = { a : 1, b : 2, c : { d: 3, e: 4 }, f: 5 };
102
+
103
+ var keys = [];
104
+ Traverse(obj).forEach(function (x) {
105
+ keys.push(this.key)
106
+ if (this.key == 'c') this.remove();
107
+ });
108
+
109
+ assert.deepEqual(keys, [undefined, 'a', 'b', 'c', 'd', 'e', 'f'])
110
+ }
111
+
112
+ exports.removeStop = function() {
113
+ var obj = { a : 1, b : 2, c : { d: 3, e: 4 }, f: 5 };
114
+
115
+ var keys = [];
116
+ Traverse(obj).forEach(function (x) {
117
+ keys.push(this.key)
118
+ if (this.key == 'c') this.remove(true);
119
+ });
120
+
121
+ assert.deepEqual(keys, [undefined, 'a', 'b', 'c', 'f'])
122
+ }
123
+
124
+ exports.removeMap = function () {
125
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
126
+ var res = Traverse(obj).map(function (x) {
127
+ if (this.isLeaf && x % 2 == 0) this.remove();
128
+ });
129
+
130
+ assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
131
+ assert.deepEqual(res, { a : 1, c : [ 3 ] });
132
+ };
133
+
134
+ exports.delete = function () {
135
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
136
+ Traverse(obj).forEach(function (x) {
137
+ if (this.isLeaf && x % 2 == 0) this.delete();
138
+ });
139
+
140
+ assert.ok(!deepEqual(
141
+ obj, { a : 1, c : [ 3, undefined ] }
142
+ ));
143
+
144
+ assert.ok(deepEqual(
145
+ obj, { a : 1, c : [ 3 ] }
146
+ ));
147
+
148
+ assert.ok(!deepEqual(
149
+ obj, { a : 1, c : [ 3, null ] }
150
+ ));
151
+ };
152
+
153
+ exports.deleteNoStop = function() {
154
+ var obj = { a : 1, b : 2, c : { d: 3, e: 4 } };
155
+
156
+ var keys = [];
157
+ Traverse(obj).forEach(function (x) {
158
+ keys.push(this.key)
159
+ if (this.key == 'c') this.delete();
160
+ });
161
+
162
+ assert.deepEqual(keys, [undefined, 'a', 'b', 'c', 'd', 'e'])
163
+ }
164
+
165
+ exports.deleteStop = function() {
166
+ var obj = { a : 1, b : 2, c : { d: 3, e: 4 } };
167
+
168
+ var keys = [];
169
+ Traverse(obj).forEach(function (x) {
170
+ keys.push(this.key)
171
+ if (this.key == 'c') this.delete(true);
172
+ });
173
+
174
+ assert.deepEqual(keys, [undefined, 'a', 'b', 'c'])
175
+ }
176
+
177
+ exports.deleteRedux = function () {
178
+ var obj = { a : 1, b : 2, c : [ 3, 4, 5 ] };
179
+ Traverse(obj).forEach(function (x) {
180
+ if (this.isLeaf && x % 2 == 0) this.delete();
181
+ });
182
+
183
+ assert.ok(!deepEqual(
184
+ obj, { a : 1, c : [ 3, undefined, 5 ] }
185
+ ));
186
+
187
+ assert.ok(deepEqual(
188
+ obj, { a : 1, c : [ 3 ,, 5 ] }
189
+ ));
190
+
191
+ assert.ok(!deepEqual(
192
+ obj, { a : 1, c : [ 3, null, 5 ] }
193
+ ));
194
+
195
+ assert.ok(!deepEqual(
196
+ obj, { a : 1, c : [ 3, 5 ] }
197
+ ));
198
+ };
199
+
200
+ exports.deleteMap = function () {
201
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
202
+ var res = Traverse(obj).map(function (x) {
203
+ if (this.isLeaf && x % 2 == 0) this.delete();
204
+ });
205
+
206
+ assert.ok(deepEqual(
207
+ obj,
208
+ { a : 1, b : 2, c : [ 3, 4 ] }
209
+ ));
210
+
211
+ var xs = [ 3, 4 ];
212
+ delete xs[1];
213
+
214
+ assert.ok(deepEqual(
215
+ res, { a : 1, c : xs }
216
+ ));
217
+
218
+ assert.ok(deepEqual(
219
+ res, { a : 1, c : [ 3, ] }
220
+ ));
221
+
222
+ assert.ok(deepEqual(
223
+ res, { a : 1, c : [ 3 ] }
224
+ ));
225
+ };
226
+
227
+ exports.deleteMapRedux = function () {
228
+ var obj = { a : 1, b : 2, c : [ 3, 4, 5 ] };
229
+ var res = Traverse(obj).map(function (x) {
230
+ if (this.isLeaf && x % 2 == 0) this.delete();
231
+ });
232
+
233
+ assert.ok(deepEqual(
234
+ obj,
235
+ { a : 1, b : 2, c : [ 3, 4, 5 ] }
236
+ ));
237
+
238
+ var xs = [ 3, 4, 5 ];
239
+ delete xs[1];
240
+
241
+ assert.ok(deepEqual(
242
+ res, { a : 1, c : xs }
243
+ ));
244
+
245
+ assert.ok(!deepEqual(
246
+ res, { a : 1, c : [ 3, 5 ] }
247
+ ));
248
+
249
+ assert.ok(deepEqual(
250
+ res, { a : 1, c : [ 3 ,, 5 ] }
251
+ ));
252
+ };
@@ -0,0 +1,20 @@
1
+ var Traverse = require('../');
2
+ var assert = require('assert');
3
+
4
+ exports['negative update test'] = function () {
5
+ var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
6
+ var fixed = Traverse.map(obj, function (x) {
7
+ if (x < 0) this.update(x + 128);
8
+ });
9
+
10
+ assert.deepEqual(fixed,
11
+ [ 5, 6, 125, [ 7, 8, 126, 1 ], { f: 10, g: 115 } ],
12
+ 'Negative values += 128'
13
+ );
14
+
15
+ assert.deepEqual(obj,
16
+ [ 5, 6, -3, [ 7, 8, -2, 1 ], { f: 10, g: -13 } ],
17
+ 'Original references not modified'
18
+ );
19
+ }
20
+