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,24 @@
1
+ Copyright 2010 James Halliday (mail@substack.net)
2
+
3
+ This project is free software released under the MIT/X11 license:
4
+ http://www.opensource.org/licenses/mit-license.php
5
+
6
+ Copyright 2010 James Halliday (mail@substack.net)
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
@@ -0,0 +1,237 @@
1
+ traverse
2
+ ========
3
+
4
+ Traverse and transform objects by visiting every node on a recursive walk.
5
+
6
+ examples
7
+ ========
8
+
9
+ transform negative numbers in-place
10
+ -----------------------------------
11
+
12
+ negative.js
13
+
14
+ ````javascript
15
+ var traverse = require('traverse');
16
+ var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
17
+
18
+ traverse(obj).forEach(function (x) {
19
+ if (x < 0) this.update(x + 128);
20
+ });
21
+
22
+ console.dir(obj);
23
+ ````
24
+
25
+ Output:
26
+
27
+ [ 5, 6, 125, [ 7, 8, 126, 1 ], { f: 10, g: 115 } ]
28
+
29
+ collect leaf nodes
30
+ ------------------
31
+
32
+ leaves.js
33
+
34
+ ````javascript
35
+ var traverse = require('traverse');
36
+
37
+ var obj = {
38
+ a : [1,2,3],
39
+ b : 4,
40
+ c : [5,6],
41
+ d : { e : [7,8], f : 9 },
42
+ };
43
+
44
+ var leaves = traverse(obj).reduce(function (acc, x) {
45
+ if (this.isLeaf) acc.push(x);
46
+ return acc;
47
+ }, []);
48
+
49
+ console.dir(leaves);
50
+ ````
51
+
52
+ Output:
53
+
54
+ [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
55
+
56
+ scrub circular references
57
+ -------------------------
58
+
59
+ scrub.js:
60
+
61
+ ````javascript
62
+ var traverse = require('traverse');
63
+
64
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
65
+ obj.c.push(obj);
66
+
67
+ var scrubbed = traverse(obj).map(function (x) {
68
+ if (this.circular) this.remove()
69
+ });
70
+ console.dir(scrubbed);
71
+ ````
72
+
73
+ output:
74
+
75
+ { a: 1, b: 2, c: [ 3, 4 ] }
76
+
77
+ context
78
+ =======
79
+
80
+ Each method that takes a callback has a context (its `this` object) with these
81
+ attributes:
82
+
83
+ this.node
84
+ ---------
85
+
86
+ The present node on the recursive walk
87
+
88
+ this.path
89
+ ---------
90
+
91
+ An array of string keys from the root to the present node
92
+
93
+ this.parent
94
+ -----------
95
+
96
+ The context of the node's parent.
97
+ This is `undefined` for the root node.
98
+
99
+ this.key
100
+ --------
101
+
102
+ The name of the key of the present node in its parent.
103
+ This is `undefined` for the root node.
104
+
105
+ this.isRoot, this.notRoot
106
+ -------------------------
107
+
108
+ Whether the present node is the root node
109
+
110
+ this.isLeaf, this.notLeaf
111
+ -------------------------
112
+
113
+ Whether or not the present node is a leaf node (has no children)
114
+
115
+ this.level
116
+ ----------
117
+
118
+ Depth of the node within the traversal
119
+
120
+ this.circular
121
+ -------------
122
+
123
+ If the node equals one of its parents, the `circular` attribute is set to the
124
+ context of that parent and the traversal progresses no deeper.
125
+
126
+ this.update(value, stopHere=false)
127
+ ----------------------------------
128
+
129
+ Set a new value for the present node.
130
+
131
+ All the elements in `value` will be recursively traversed unless `stopHere` is
132
+ true.
133
+
134
+ this.remove(stopHere=false)
135
+ -------------
136
+
137
+ Remove the current element from the output. If the node is in an Array it will
138
+ be spliced off. Otherwise it will be deleted from its parent.
139
+
140
+ this.delete(stopHere=false)
141
+ -------------
142
+
143
+ Delete the current element from its parent in the output. Calls `delete` even on
144
+ Arrays.
145
+
146
+ this.before(fn)
147
+ ---------------
148
+
149
+ Call this function before any of the children are traversed.
150
+
151
+ You can assign into `this.keys` here to traverse in a custom order.
152
+
153
+ this.after(fn)
154
+ --------------
155
+
156
+ Call this function after any of the children are traversed.
157
+
158
+ this.pre(fn)
159
+ ------------
160
+
161
+ Call this function before each of the children are traversed.
162
+
163
+ this.post(fn)
164
+ -------------
165
+
166
+ Call this function after each of the children are traversed.
167
+
168
+ methods
169
+ =======
170
+
171
+ .map(fn)
172
+ --------
173
+
174
+ Execute `fn` for each node in the object and return a new object with the
175
+ results of the walk. To update nodes in the result use `this.update(value)`.
176
+
177
+ .forEach(fn)
178
+ ------------
179
+
180
+ Execute `fn` for each node in the object but unlike `.map()`, when
181
+ `this.update()` is called it updates the object in-place.
182
+
183
+ .reduce(fn, acc)
184
+ ----------------
185
+
186
+ For each node in the object, perform a
187
+ [left-fold](http://en.wikipedia.org/wiki/Fold_(higher-order_function))
188
+ with the return value of `fn(acc, node)`.
189
+
190
+ If `acc` isn't specified, `acc` is set to the root object for the first step
191
+ and the root element is skipped.
192
+
193
+ .paths()
194
+ --------
195
+
196
+ Return an `Array` of every possible non-cyclic path in the object.
197
+ Paths are `Array`s of string keys.
198
+
199
+ .nodes()
200
+ --------
201
+
202
+ Return an `Array` of every node in the object.
203
+
204
+ .clone()
205
+ --------
206
+
207
+ Create a deep clone of the object.
208
+
209
+ install
210
+ =======
211
+
212
+ Using [npm](http://npmjs.org) do:
213
+
214
+ $ npm install traverse
215
+
216
+ test
217
+ ====
218
+
219
+ Using [expresso](http://github.com/visionmedia/expresso) do:
220
+
221
+ $ expresso
222
+
223
+ 100% wahoo, your stuff is not broken!
224
+
225
+ in the browser
226
+ ==============
227
+
228
+ Use [browserify](https://github.com/substack/node-browserify) to run traverse in
229
+ the browser.
230
+
231
+ traverse has been tested and works with:
232
+
233
+ * Internet Explorer 5.5, 6.0, 7.0, 8.0, 9.0
234
+ * Firefox 3.5
235
+ * Chrome 6.0
236
+ * Opera 10.6
237
+ * Safari 5.0
@@ -0,0 +1,16 @@
1
+ var traverse = require('traverse');
2
+
3
+ var id = 54;
4
+ var callbacks = {};
5
+ var obj = { moo : function () {}, foo : [2,3,4, function () {}] };
6
+
7
+ var scrubbed = traverse(obj).map(function (x) {
8
+ if (typeof x === 'function') {
9
+ callbacks[id] = { id : id, f : x, path : this.path };
10
+ this.update('[Function]');
11
+ id++;
12
+ }
13
+ });
14
+
15
+ console.dir(scrubbed);
16
+ console.dir(callbacks);
@@ -0,0 +1,15 @@
1
+ var traverse = require('traverse');
2
+
3
+ var obj = {
4
+ a : [1,2,3],
5
+ b : 4,
6
+ c : [5,6],
7
+ d : { e : [7,8], f : 9 },
8
+ };
9
+
10
+ var leaves = traverse(obj).reduce(function (acc, x) {
11
+ if (this.isLeaf) acc.push(x);
12
+ return acc;
13
+ }, []);
14
+
15
+ console.dir(leaves);
@@ -0,0 +1,8 @@
1
+ var traverse = require('traverse');
2
+ var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
3
+
4
+ traverse(obj).forEach(function (x) {
5
+ if (x < 0) this.update(x + 128);
6
+ });
7
+
8
+ console.dir(obj);
@@ -0,0 +1,10 @@
1
+ // scrub out circular references
2
+ var traverse = require('traverse');
3
+
4
+ var obj = { a : 1, b : 2, c : [ 3, 4 ] };
5
+ obj.c.push(obj);
6
+
7
+ var scrubbed = traverse(obj).map(function (x) {
8
+ if (this.circular) this.remove()
9
+ });
10
+ console.dir(scrubbed);
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ var traverse = require('traverse');
3
+
4
+ var obj = [ 'five', 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
5
+
6
+ var s = '';
7
+ traverse(obj).forEach(function to_s (node) {
8
+ if (Array.isArray(node)) {
9
+ this.before(function () { s += '[' });
10
+ this.post(function (child) {
11
+ if (!child.isLast) s += ',';
12
+ });
13
+ this.after(function () { s += ']' });
14
+ }
15
+ else if (typeof node == 'object') {
16
+ this.before(function () { s += '{' });
17
+ this.pre(function (x, key) {
18
+ to_s(key);
19
+ s += ':';
20
+ });
21
+ this.post(function (child) {
22
+ if (!child.isLast) s += ',';
23
+ });
24
+ this.after(function () { s += '}' });
25
+ }
26
+ else if (typeof node == 'string') {
27
+ s += '"' + node.toString().replace(/"/g, '\\"') + '"';
28
+ }
29
+ else if (typeof node == 'function') {
30
+ s += 'null';
31
+ }
32
+ else {
33
+ s += node.toString();
34
+ }
35
+ });
36
+
37
+ console.log('JSON.stringify: ' + JSON.stringify(obj));
38
+ console.log('this stringify: ' + s);
@@ -0,0 +1,267 @@
1
+ module.exports = Traverse;
2
+ function Traverse (obj) {
3
+ if (!(this instanceof Traverse)) return new Traverse(obj);
4
+ this.value = obj;
5
+ }
6
+
7
+ Traverse.prototype.get = function (ps) {
8
+ var node = this.value;
9
+ for (var i = 0; i < ps.length; i ++) {
10
+ var key = ps[i];
11
+ if (!Object.hasOwnProperty.call(node, key)) {
12
+ node = undefined;
13
+ break;
14
+ }
15
+ node = node[key];
16
+ }
17
+ return node;
18
+ };
19
+
20
+ Traverse.prototype.set = function (ps, value) {
21
+ var node = this.value;
22
+ for (var i = 0; i < ps.length - 1; i ++) {
23
+ var key = ps[i];
24
+ if (!Object.hasOwnProperty.call(node, key)) node[key] = {};
25
+ node = node[key];
26
+ }
27
+ node[ps[i]] = value;
28
+ return value;
29
+ };
30
+
31
+ Traverse.prototype.map = function (cb) {
32
+ return walk(this.value, cb, true);
33
+ };
34
+
35
+ Traverse.prototype.forEach = function (cb) {
36
+ this.value = walk(this.value, cb, false);
37
+ return this.value;
38
+ };
39
+
40
+ Traverse.prototype.reduce = function (cb, init) {
41
+ var skip = arguments.length === 1;
42
+ var acc = skip ? this.value : init;
43
+ this.forEach(function (x) {
44
+ if (!this.isRoot || !skip) {
45
+ acc = cb.call(this, acc, x);
46
+ }
47
+ });
48
+ return acc;
49
+ };
50
+
51
+ Traverse.prototype.paths = function () {
52
+ var acc = [];
53
+ this.forEach(function (x) {
54
+ acc.push(this.path);
55
+ });
56
+ return acc;
57
+ };
58
+
59
+ Traverse.prototype.nodes = function () {
60
+ var acc = [];
61
+ this.forEach(function (x) {
62
+ acc.push(this.node);
63
+ });
64
+ return acc;
65
+ };
66
+
67
+ Traverse.prototype.clone = function () {
68
+ var parents = [], nodes = [];
69
+
70
+ return (function clone (src) {
71
+ for (var i = 0; i < parents.length; i++) {
72
+ if (parents[i] === src) {
73
+ return nodes[i];
74
+ }
75
+ }
76
+
77
+ if (typeof src === 'object' && src !== null) {
78
+ var dst = copy(src);
79
+
80
+ parents.push(src);
81
+ nodes.push(dst);
82
+
83
+ forEach(Object_keys(src), function (key) {
84
+ dst[key] = clone(src[key]);
85
+ });
86
+
87
+ parents.pop();
88
+ nodes.pop();
89
+ return dst;
90
+ }
91
+ else {
92
+ return src;
93
+ }
94
+ })(this.value);
95
+ };
96
+
97
+ function walk (root, cb, immutable) {
98
+ var path = [];
99
+ var parents = [];
100
+ var alive = true;
101
+
102
+ return (function walker (node_) {
103
+ var node = immutable ? copy(node_) : node_;
104
+ var modifiers = {};
105
+
106
+ var keepGoing = true;
107
+
108
+ var state = {
109
+ node : node,
110
+ node_ : node_,
111
+ path : [].concat(path),
112
+ parent : parents[parents.length - 1],
113
+ parents : parents,
114
+ key : path.slice(-1)[0],
115
+ isRoot : path.length === 0,
116
+ level : path.length,
117
+ circular : null,
118
+ update : function (x, stopHere) {
119
+ if (!state.isRoot) {
120
+ state.parent.node[state.key] = x;
121
+ }
122
+ state.node = x;
123
+ if (stopHere) keepGoing = false;
124
+ },
125
+ 'delete' : function (stopHere) {
126
+ delete state.parent.node[state.key];
127
+ if (stopHere) keepGoing = false;
128
+ },
129
+ remove : function (stopHere) {
130
+ if (Array_isArray(state.parent.node)) {
131
+ state.parent.node.splice(state.key, 1);
132
+ }
133
+ else {
134
+ delete state.parent.node[state.key];
135
+ }
136
+ if (stopHere) keepGoing = false;
137
+ },
138
+ keys : null,
139
+ before : function (f) { modifiers.before = f },
140
+ after : function (f) { modifiers.after = f },
141
+ pre : function (f) { modifiers.pre = f },
142
+ post : function (f) { modifiers.post = f },
143
+ stop : function () { alive = false },
144
+ block : function () { keepGoing = false }
145
+ };
146
+
147
+ if (!alive) return state;
148
+
149
+ if (typeof node === 'object' && node !== null) {
150
+ state.keys = Object_keys(node);
151
+
152
+ state.isLeaf = state.keys.length == 0;
153
+
154
+ for (var i = 0; i < parents.length; i++) {
155
+ if (parents[i].node_ === node_) {
156
+ state.circular = parents[i];
157
+ break;
158
+ }
159
+ }
160
+ }
161
+ else {
162
+ state.isLeaf = true;
163
+ }
164
+
165
+ state.notLeaf = !state.isLeaf;
166
+ state.notRoot = !state.isRoot;
167
+
168
+ // use return values to update if defined
169
+ var ret = cb.call(state, state.node);
170
+ if (ret !== undefined && state.update) state.update(ret);
171
+
172
+ if (modifiers.before) modifiers.before.call(state, state.node);
173
+
174
+ if (!keepGoing) return state;
175
+
176
+ if (typeof state.node == 'object'
177
+ && state.node !== null && !state.circular) {
178
+ parents.push(state);
179
+
180
+ forEach(state.keys, function (key, i) {
181
+ path.push(key);
182
+
183
+ if (modifiers.pre) modifiers.pre.call(state, state.node[key], key);
184
+
185
+ var child = walker(state.node[key]);
186
+ if (immutable && Object.hasOwnProperty.call(state.node, key)) {
187
+ state.node[key] = child.node;
188
+ }
189
+
190
+ child.isLast = i == state.keys.length - 1;
191
+ child.isFirst = i == 0;
192
+
193
+ if (modifiers.post) modifiers.post.call(state, child);
194
+
195
+ path.pop();
196
+ });
197
+ parents.pop();
198
+ }
199
+
200
+ if (modifiers.after) modifiers.after.call(state, state.node);
201
+
202
+ return state;
203
+ })(root).node;
204
+ }
205
+
206
+ function copy (src) {
207
+ if (typeof src === 'object' && src !== null) {
208
+ var dst;
209
+
210
+ if (Array_isArray(src)) {
211
+ dst = [];
212
+ }
213
+ else if (src instanceof Date) {
214
+ dst = new Date(src);
215
+ }
216
+ else if (src instanceof Boolean) {
217
+ dst = new Boolean(src);
218
+ }
219
+ else if (src instanceof Number) {
220
+ dst = new Number(src);
221
+ }
222
+ else if (src instanceof String) {
223
+ dst = new String(src);
224
+ }
225
+ else if (Object.create && Object.getPrototypeOf) {
226
+ dst = Object.create(Object.getPrototypeOf(src));
227
+ }
228
+ else if (src.__proto__ || src.constructor.prototype) {
229
+ var proto = src.__proto__ || src.constructor.prototype || {};
230
+ var T = function () {};
231
+ T.prototype = proto;
232
+ dst = new T;
233
+ if (!dst.__proto__) dst.__proto__ = proto;
234
+ }
235
+
236
+ forEach(Object_keys(src), function (key) {
237
+ dst[key] = src[key];
238
+ });
239
+ return dst;
240
+ }
241
+ else return src;
242
+ }
243
+
244
+ var Object_keys = Object.keys || function keys (obj) {
245
+ var res = [];
246
+ for (var key in obj) res.push(key)
247
+ return res;
248
+ };
249
+
250
+ var Array_isArray = Array.isArray || function isArray (xs) {
251
+ return Object.prototype.toString.call(xs) === '[object Array]';
252
+ };
253
+
254
+ var forEach = function (xs, fn) {
255
+ if (xs.forEach) return xs.forEach(fn)
256
+ else for (var i = 0; i < xs.length; i++) {
257
+ fn(xs[i], i, xs);
258
+ }
259
+ };
260
+
261
+ forEach(Object_keys(Traverse.prototype), function (key) {
262
+ Traverse[key] = function (obj) {
263
+ var args = [].slice.call(arguments, 1);
264
+ var t = Traverse(obj);
265
+ return t[key].apply(t, args);
266
+ };
267
+ });