browsed 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +2 -2
  4. data/README.md +12 -17
  5. data/bin/browse +13 -10
  6. data/lib/browsed.rb +9 -2
  7. data/lib/browsed/browser.rb +82 -0
  8. data/lib/browsed/chrome.rb +21 -12
  9. data/lib/browsed/client.rb +48 -130
  10. data/lib/browsed/constants.rb +7 -1
  11. data/lib/browsed/errors.rb +1 -0
  12. data/lib/browsed/extensions/hash.rb +27 -0
  13. data/lib/browsed/firefox.rb +18 -17
  14. data/lib/browsed/manager.rb +5 -5
  15. data/lib/browsed/{poltergeist.rb → phantomjs.rb} +2 -2
  16. data/lib/browsed/proxies.rb +26 -0
  17. data/lib/browsed/{extensions → proxies}/chrome/proxy_authentication.rb +3 -3
  18. data/lib/browsed/proxies/proxy-chain-server/node_modules/.bin/portastic +1 -0
  19. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/LICENSE +21 -0
  20. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/README.md +57 -0
  21. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/changelog.md +1 -0
  22. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.js +3824 -0
  23. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.min.js +31 -0
  24. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.js +5666 -0
  25. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.min.js +31 -0
  26. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/any.js +21 -0
  27. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/assert.js +55 -0
  28. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/async.js +165 -0
  29. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bind.js +67 -0
  30. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bluebird.js +11 -0
  31. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/call_get.js +123 -0
  32. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/cancel.js +129 -0
  33. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/catch_filter.js +42 -0
  34. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/context.js +69 -0
  35. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/debuggability.js +934 -0
  36. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/direct_resolve.js +46 -0
  37. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/each.js +30 -0
  38. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/errors.js +116 -0
  39. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/es5.js +80 -0
  40. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/filter.js +12 -0
  41. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/finally.js +146 -0
  42. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/generators.js +223 -0
  43. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/join.js +168 -0
  44. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/map.js +168 -0
  45. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/method.js +55 -0
  46. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeback.js +51 -0
  47. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeify.js +58 -0
  48. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise.js +789 -0
  49. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise_array.js +185 -0
  50. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promisify.js +314 -0
  51. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/props.js +118 -0
  52. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/queue.js +73 -0
  53. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/race.js +49 -0
  54. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/reduce.js +172 -0
  55. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/schedule.js +62 -0
  56. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/settle.js +43 -0
  57. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/some.js +148 -0
  58. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/synchronous_inspection.js +103 -0
  59. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/thenables.js +86 -0
  60. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/timers.js +93 -0
  61. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/using.js +226 -0
  62. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/util.js +389 -0
  63. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/package.json +102 -0
  64. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/CHANGELOG.md +408 -0
  65. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/LICENSE +22 -0
  66. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/Readme.md +428 -0
  67. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/index.js +1224 -0
  68. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/package.json +70 -0
  69. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/typings/index.d.ts +310 -0
  70. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.coveralls.yml +1 -0
  71. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.eslintrc +11 -0
  72. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.npmignore +9 -0
  73. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.travis.yml +14 -0
  74. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/CHANGELOG.md +362 -0
  75. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/LICENSE +19 -0
  76. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/Makefile +50 -0
  77. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/README.md +312 -0
  78. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/component.json +19 -0
  79. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/karma.conf.js +70 -0
  80. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/node.js +1 -0
  81. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/package.json +88 -0
  82. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/browser.js +185 -0
  83. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/debug.js +202 -0
  84. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/index.js +10 -0
  85. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/inspector-log.js +15 -0
  86. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/node.js +248 -0
  87. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/index.js +152 -0
  88. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/license.md +21 -0
  89. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/package.json +69 -0
  90. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/readme.md +51 -0
  91. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/LICENSE +13 -0
  92. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/README.md +148 -0
  93. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/bin/portastic +65 -0
  94. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/history.md +7 -0
  95. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/index.js +4 -0
  96. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/monitor.js +59 -0
  97. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/portastic.js +167 -0
  98. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/LICENSE +21 -0
  99. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/README.md +677 -0
  100. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/changelog.md +1730 -0
  101. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.js +4892 -0
  102. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.min.js +31 -0
  103. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/any.js +21 -0
  104. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/assert.js +55 -0
  105. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/async.js +150 -0
  106. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bind.js +72 -0
  107. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bluebird.js +11 -0
  108. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/call_get.js +123 -0
  109. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/cancel.js +48 -0
  110. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/captured_trace.js +493 -0
  111. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/catch_filter.js +66 -0
  112. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/context.js +38 -0
  113. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/debuggability.js +162 -0
  114. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/direct_resolve.js +63 -0
  115. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/each.js +12 -0
  116. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/errors.js +111 -0
  117. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/es5.js +80 -0
  118. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/filter.js +12 -0
  119. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/finally.js +98 -0
  120. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/generators.js +136 -0
  121. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/join.js +107 -0
  122. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/map.js +133 -0
  123. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/method.js +44 -0
  124. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js +59 -0
  125. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/progress.js +76 -0
  126. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise.js +759 -0
  127. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_array.js +142 -0
  128. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_resolver.js +123 -0
  129. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promisify.js +307 -0
  130. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/props.js +79 -0
  131. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/queue.js +90 -0
  132. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/race.js +47 -0
  133. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/reduce.js +148 -0
  134. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/schedule.js +35 -0
  135. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/settle.js +40 -0
  136. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/some.js +125 -0
  137. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/synchronous_inspection.js +94 -0
  138. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/thenables.js +84 -0
  139. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/timers.js +64 -0
  140. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/using.js +213 -0
  141. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/util.js +321 -0
  142. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/package.json +103 -0
  143. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/package.json +69 -0
  144. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/CHANGELOG.md +109 -0
  145. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/LICENSE +201 -0
  146. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/README.md +278 -0
  147. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/anonymize_proxy.js +100 -0
  148. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_base.js +319 -0
  149. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_custom_response.js +96 -0
  150. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_forward.js +173 -0
  151. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_chain.js +132 -0
  152. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_direct.js +89 -0
  153. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_tcp_chain.js +271 -0
  154. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/index.js +26 -0
  155. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/run_locally.js +66 -0
  156. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/server.js +595 -0
  157. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel.js +138 -0
  158. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/testing_tcp_service.js +37 -0
  159. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tools.js +220 -0
  160. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/package.json +104 -0
  161. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/LICENSE +23 -0
  162. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/README.md +28 -0
  163. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/package.json +81 -0
  164. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js +5 -0
  165. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js.map +1 -0
  166. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore.js +1692 -0
  167. data/lib/browsed/proxies/proxy-chain-server/package-lock.json +63 -0
  168. data/lib/browsed/proxies/proxy-chain-server/package.json +15 -0
  169. data/lib/browsed/proxies/proxy-chain-server/server.js +25 -0
  170. data/lib/browsed/proxies/proxy_chain.rb +36 -0
  171. data/lib/browsed/version.rb +1 -1
  172. metadata +160 -4
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Detect Electron renderer process, which is node, but we should
3
+ * treat as a browser.
4
+ */
5
+
6
+ if (typeof process !== 'undefined' && process.type === 'renderer') {
7
+ module.exports = require('./browser.js');
8
+ } else {
9
+ module.exports = require('./node.js');
10
+ }
@@ -0,0 +1,15 @@
1
+ module.exports = inspectorLog;
2
+
3
+ // black hole
4
+ const nullStream = new (require('stream').Writable)();
5
+ nullStream._write = () => {};
6
+
7
+ /**
8
+ * Outputs a `console.log()` to the Node.js Inspector console *only*.
9
+ */
10
+ function inspectorLog() {
11
+ const stdout = console._stdout;
12
+ console._stdout = nullStream;
13
+ console.log.apply(console, arguments);
14
+ console._stdout = stdout;
15
+ }
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Module dependencies.
3
+ */
4
+
5
+ var tty = require('tty');
6
+ var util = require('util');
7
+
8
+ /**
9
+ * This is the Node.js implementation of `debug()`.
10
+ *
11
+ * Expose `debug()` as the module.
12
+ */
13
+
14
+ exports = module.exports = require('./debug');
15
+ exports.init = init;
16
+ exports.log = log;
17
+ exports.formatArgs = formatArgs;
18
+ exports.save = save;
19
+ exports.load = load;
20
+ exports.useColors = useColors;
21
+
22
+ /**
23
+ * Colors.
24
+ */
25
+
26
+ exports.colors = [6, 2, 3, 4, 5, 1];
27
+
28
+ /**
29
+ * Build up the default `inspectOpts` object from the environment variables.
30
+ *
31
+ * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
32
+ */
33
+
34
+ exports.inspectOpts = Object.keys(process.env).filter(function (key) {
35
+ return /^debug_/i.test(key);
36
+ }).reduce(function (obj, key) {
37
+ // camel-case
38
+ var prop = key
39
+ .substring(6)
40
+ .toLowerCase()
41
+ .replace(/_([a-z])/g, function (_, k) { return k.toUpperCase() });
42
+
43
+ // coerce string value into JS value
44
+ var val = process.env[key];
45
+ if (/^(yes|on|true|enabled)$/i.test(val)) val = true;
46
+ else if (/^(no|off|false|disabled)$/i.test(val)) val = false;
47
+ else if (val === 'null') val = null;
48
+ else val = Number(val);
49
+
50
+ obj[prop] = val;
51
+ return obj;
52
+ }, {});
53
+
54
+ /**
55
+ * The file descriptor to write the `debug()` calls to.
56
+ * Set the `DEBUG_FD` env variable to override with another value. i.e.:
57
+ *
58
+ * $ DEBUG_FD=3 node script.js 3>debug.log
59
+ */
60
+
61
+ var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
62
+
63
+ if (1 !== fd && 2 !== fd) {
64
+ util.deprecate(function(){}, 'except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)')()
65
+ }
66
+
67
+ var stream = 1 === fd ? process.stdout :
68
+ 2 === fd ? process.stderr :
69
+ createWritableStdioStream(fd);
70
+
71
+ /**
72
+ * Is stdout a TTY? Colored output is enabled when `true`.
73
+ */
74
+
75
+ function useColors() {
76
+ return 'colors' in exports.inspectOpts
77
+ ? Boolean(exports.inspectOpts.colors)
78
+ : tty.isatty(fd);
79
+ }
80
+
81
+ /**
82
+ * Map %o to `util.inspect()`, all on a single line.
83
+ */
84
+
85
+ exports.formatters.o = function(v) {
86
+ this.inspectOpts.colors = this.useColors;
87
+ return util.inspect(v, this.inspectOpts)
88
+ .split('\n').map(function(str) {
89
+ return str.trim()
90
+ }).join(' ');
91
+ };
92
+
93
+ /**
94
+ * Map %o to `util.inspect()`, allowing multiple lines if needed.
95
+ */
96
+
97
+ exports.formatters.O = function(v) {
98
+ this.inspectOpts.colors = this.useColors;
99
+ return util.inspect(v, this.inspectOpts);
100
+ };
101
+
102
+ /**
103
+ * Adds ANSI color escape codes if enabled.
104
+ *
105
+ * @api public
106
+ */
107
+
108
+ function formatArgs(args) {
109
+ var name = this.namespace;
110
+ var useColors = this.useColors;
111
+
112
+ if (useColors) {
113
+ var c = this.color;
114
+ var prefix = ' \u001b[3' + c + ';1m' + name + ' ' + '\u001b[0m';
115
+
116
+ args[0] = prefix + args[0].split('\n').join('\n' + prefix);
117
+ args.push('\u001b[3' + c + 'm+' + exports.humanize(this.diff) + '\u001b[0m');
118
+ } else {
119
+ args[0] = new Date().toUTCString()
120
+ + ' ' + name + ' ' + args[0];
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Invokes `util.format()` with the specified arguments and writes to `stream`.
126
+ */
127
+
128
+ function log() {
129
+ return stream.write(util.format.apply(util, arguments) + '\n');
130
+ }
131
+
132
+ /**
133
+ * Save `namespaces`.
134
+ *
135
+ * @param {String} namespaces
136
+ * @api private
137
+ */
138
+
139
+ function save(namespaces) {
140
+ if (null == namespaces) {
141
+ // If you set a process.env field to null or undefined, it gets cast to the
142
+ // string 'null' or 'undefined'. Just delete instead.
143
+ delete process.env.DEBUG;
144
+ } else {
145
+ process.env.DEBUG = namespaces;
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Load `namespaces`.
151
+ *
152
+ * @return {String} returns the previously persisted debug modes
153
+ * @api private
154
+ */
155
+
156
+ function load() {
157
+ return process.env.DEBUG;
158
+ }
159
+
160
+ /**
161
+ * Copied from `node/src/node.js`.
162
+ *
163
+ * XXX: It's lame that node doesn't expose this API out-of-the-box. It also
164
+ * relies on the undocumented `tty_wrap.guessHandleType()` which is also lame.
165
+ */
166
+
167
+ function createWritableStdioStream (fd) {
168
+ var stream;
169
+ var tty_wrap = process.binding('tty_wrap');
170
+
171
+ // Note stream._type is used for test-module-load-list.js
172
+
173
+ switch (tty_wrap.guessHandleType(fd)) {
174
+ case 'TTY':
175
+ stream = new tty.WriteStream(fd);
176
+ stream._type = 'tty';
177
+
178
+ // Hack to have stream not keep the event loop alive.
179
+ // See https://github.com/joyent/node/issues/1726
180
+ if (stream._handle && stream._handle.unref) {
181
+ stream._handle.unref();
182
+ }
183
+ break;
184
+
185
+ case 'FILE':
186
+ var fs = require('fs');
187
+ stream = new fs.SyncWriteStream(fd, { autoClose: false });
188
+ stream._type = 'fs';
189
+ break;
190
+
191
+ case 'PIPE':
192
+ case 'TCP':
193
+ var net = require('net');
194
+ stream = new net.Socket({
195
+ fd: fd,
196
+ readable: false,
197
+ writable: true
198
+ });
199
+
200
+ // FIXME Should probably have an option in net.Socket to create a
201
+ // stream from an existing fd which is writable only. But for now
202
+ // we'll just add this hack and set the `readable` member to false.
203
+ // Test: ./node test/fixtures/echo.js < /etc/passwd
204
+ stream.readable = false;
205
+ stream.read = null;
206
+ stream._type = 'pipe';
207
+
208
+ // FIXME Hack to have stream not keep the event loop alive.
209
+ // See https://github.com/joyent/node/issues/1726
210
+ if (stream._handle && stream._handle.unref) {
211
+ stream._handle.unref();
212
+ }
213
+ break;
214
+
215
+ default:
216
+ // Probably an error on in uv_guess_handle()
217
+ throw new Error('Implement me. Unknown stream file type!');
218
+ }
219
+
220
+ // For supporting legacy API we put the FD here.
221
+ stream.fd = fd;
222
+
223
+ stream._isStdio = true;
224
+
225
+ return stream;
226
+ }
227
+
228
+ /**
229
+ * Init logic for `debug` instances.
230
+ *
231
+ * Create a new `inspectOpts` object in case `useColors` is set
232
+ * differently for a particular `debug` instance.
233
+ */
234
+
235
+ function init (debug) {
236
+ debug.inspectOpts = {};
237
+
238
+ var keys = Object.keys(exports.inspectOpts);
239
+ for (var i = 0; i < keys.length; i++) {
240
+ debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Enable namespaces listed in `process.env.DEBUG` initially.
246
+ */
247
+
248
+ exports.enable(load());
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Helpers.
3
+ */
4
+
5
+ var s = 1000;
6
+ var m = s * 60;
7
+ var h = m * 60;
8
+ var d = h * 24;
9
+ var y = d * 365.25;
10
+
11
+ /**
12
+ * Parse or format the given `val`.
13
+ *
14
+ * Options:
15
+ *
16
+ * - `long` verbose formatting [false]
17
+ *
18
+ * @param {String|Number} val
19
+ * @param {Object} [options]
20
+ * @throws {Error} throw an error if val is not a non-empty string or a number
21
+ * @return {String|Number}
22
+ * @api public
23
+ */
24
+
25
+ module.exports = function(val, options) {
26
+ options = options || {};
27
+ var type = typeof val;
28
+ if (type === 'string' && val.length > 0) {
29
+ return parse(val);
30
+ } else if (type === 'number' && isNaN(val) === false) {
31
+ return options.long ? fmtLong(val) : fmtShort(val);
32
+ }
33
+ throw new Error(
34
+ 'val is not a non-empty string or a valid number. val=' +
35
+ JSON.stringify(val)
36
+ );
37
+ };
38
+
39
+ /**
40
+ * Parse the given `str` and return milliseconds.
41
+ *
42
+ * @param {String} str
43
+ * @return {Number}
44
+ * @api private
45
+ */
46
+
47
+ function parse(str) {
48
+ str = String(str);
49
+ if (str.length > 100) {
50
+ return;
51
+ }
52
+ var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
53
+ str
54
+ );
55
+ if (!match) {
56
+ return;
57
+ }
58
+ var n = parseFloat(match[1]);
59
+ var type = (match[2] || 'ms').toLowerCase();
60
+ switch (type) {
61
+ case 'years':
62
+ case 'year':
63
+ case 'yrs':
64
+ case 'yr':
65
+ case 'y':
66
+ return n * y;
67
+ case 'days':
68
+ case 'day':
69
+ case 'd':
70
+ return n * d;
71
+ case 'hours':
72
+ case 'hour':
73
+ case 'hrs':
74
+ case 'hr':
75
+ case 'h':
76
+ return n * h;
77
+ case 'minutes':
78
+ case 'minute':
79
+ case 'mins':
80
+ case 'min':
81
+ case 'm':
82
+ return n * m;
83
+ case 'seconds':
84
+ case 'second':
85
+ case 'secs':
86
+ case 'sec':
87
+ case 's':
88
+ return n * s;
89
+ case 'milliseconds':
90
+ case 'millisecond':
91
+ case 'msecs':
92
+ case 'msec':
93
+ case 'ms':
94
+ return n;
95
+ default:
96
+ return undefined;
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Short format for `ms`.
102
+ *
103
+ * @param {Number} ms
104
+ * @return {String}
105
+ * @api private
106
+ */
107
+
108
+ function fmtShort(ms) {
109
+ if (ms >= d) {
110
+ return Math.round(ms / d) + 'd';
111
+ }
112
+ if (ms >= h) {
113
+ return Math.round(ms / h) + 'h';
114
+ }
115
+ if (ms >= m) {
116
+ return Math.round(ms / m) + 'm';
117
+ }
118
+ if (ms >= s) {
119
+ return Math.round(ms / s) + 's';
120
+ }
121
+ return ms + 'ms';
122
+ }
123
+
124
+ /**
125
+ * Long format for `ms`.
126
+ *
127
+ * @param {Number} ms
128
+ * @return {String}
129
+ * @api private
130
+ */
131
+
132
+ function fmtLong(ms) {
133
+ return plural(ms, d, 'day') ||
134
+ plural(ms, h, 'hour') ||
135
+ plural(ms, m, 'minute') ||
136
+ plural(ms, s, 'second') ||
137
+ ms + ' ms';
138
+ }
139
+
140
+ /**
141
+ * Pluralization helper.
142
+ */
143
+
144
+ function plural(ms, n, name) {
145
+ if (ms < n) {
146
+ return;
147
+ }
148
+ if (ms < n * 1.5) {
149
+ return Math.floor(ms / n) + ' ' + name;
150
+ }
151
+ return Math.ceil(ms / n) + ' ' + name + 's';
152
+ }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Zeit, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.