mute.js.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>Code coverage report for mute.js</title>
  5. <meta charset="utf-8" />
  6. <link rel="stylesheet" href="../prettify.css" />
  7. <link rel="stylesheet" href="../base.css" />
  8. <meta name="viewport" content="width=device-width, initial-scale=1">
  9. <style type='text/css'>
  10. .coverage-summary .sorter {
  11. background-image: url(../sort-arrow-sprite.png);
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div class='wrapper'>
  17. <div class='pad1'>
  18. <h1>
  19. <a href="../index.html">all files</a> / <a href="index.html">__root__/</a> mute.js
  20. </h1>
  21. <div class='clearfix'>
  22. <div class='fl pad1y space-right2'>
  23. <span class="strong">77.03% </span>
  24. <span class="quiet">Statements</span>
  25. <span class='fraction'>57/74</span>
  26. </div>
  27. <div class='fl pad1y space-right2'>
  28. <span class="strong">57.14% </span>
  29. <span class="quiet">Branches</span>
  30. <span class='fraction'>28/49</span>
  31. </div>
  32. <div class='fl pad1y space-right2'>
  33. <span class="strong">93.33% </span>
  34. <span class="quiet">Functions</span>
  35. <span class='fraction'>14/15</span>
  36. </div>
  37. <div class='fl pad1y space-right2'>
  38. <span class="strong">79.1% </span>
  39. <span class="quiet">Lines</span>
  40. <span class='fraction'>53/67</span>
  41. </div>
  42. </div>
  43. </div>
  44. <div class='status-line medium'></div>
  45. <pre><table class="coverage">
  46. <tr><td class="line-count quiet">1
  47. 2
  48. 3
  49. 4
  50. 5
  51. 6
  52. 7
  53. 8
  54. 9
  55. 10
  56. 11
  57. 12
  58. 13
  59. 14
  60. 15
  61. 16
  62. 17
  63. 18
  64. 19
  65. 20
  66. 21
  67. 22
  68. 23
  69. 24
  70. 25
  71. 26
  72. 27
  73. 28
  74. 29
  75. 30
  76. 31
  77. 32
  78. 33
  79. 34
  80. 35
  81. 36
  82. 37
  83. 38
  84. 39
  85. 40
  86. 41
  87. 42
  88. 43
  89. 44
  90. 45
  91. 46
  92. 47
  93. 48
  94. 49
  95. 50
  96. 51
  97. 52
  98. 53
  99. 54
  100. 55
  101. 56
  102. 57
  103. 58
  104. 59
  105. 60
  106. 61
  107. 62
  108. 63
  109. 64
  110. 65
  111. 66
  112. 67
  113. 68
  114. 69
  115. 70
  116. 71
  117. 72
  118. 73
  119. 74
  120. 75
  121. 76
  122. 77
  123. 78
  124. 79
  125. 80
  126. 81
  127. 82
  128. 83
  129. 84
  130. 85
  131. 86
  132. 87
  133. 88
  134. 89
  135. 90
  136. 91
  137. 92
  138. 93
  139. 94
  140. 95
  141. 96
  142. 97
  143. 98
  144. 99
  145. 100
  146. 101
  147. 102
  148. 103
  149. 104
  150. 105
  151. 106
  152. 107
  153. 108
  154. 109
  155. 110
  156. 111
  157. 112
  158. 113
  159. 114
  160. 115
  161. 116
  162. 117
  163. 118
  164. 119
  165. 120
  166. 121
  167. 122
  168. 123
  169. 124
  170. 125
  171. 126
  172. 127
  173. 128
  174. 129
  175. 130
  176. 131
  177. 132
  178. 133
  179. 134
  180. 135
  181. 136
  182. 137
  183. 138
  184. 139
  185. 140
  186. 141
  187. 142
  188. 143
  189. 144
  190. 145
  191. 146</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1×</span>
  192. <span class="cline-any cline-neutral">&nbsp;</span>
  193. <span class="cline-any cline-yes">1×</span>
  194. <span class="cline-any cline-neutral">&nbsp;</span>
  195. <span class="cline-any cline-neutral">&nbsp;</span>
  196. <span class="cline-any cline-neutral">&nbsp;</span>
  197. <span class="cline-any cline-yes">1×</span>
  198. <span class="cline-any cline-yes">7×</span>
  199. <span class="cline-any cline-yes">7×</span>
  200. <span class="cline-any cline-yes">7×</span>
  201. <span class="cline-any cline-yes">7×</span>
  202. <span class="cline-any cline-yes">7×</span>
  203. <span class="cline-any cline-yes">7×</span>
  204. <span class="cline-any cline-neutral">&nbsp;</span>
  205. <span class="cline-any cline-neutral">&nbsp;</span>
  206. <span class="cline-any cline-neutral">&nbsp;</span>
  207. <span class="cline-any cline-neutral">&nbsp;</span>
  208. <span class="cline-any cline-yes">7×</span>
  209. <span class="cline-any cline-yes">7×</span>
  210. <span class="cline-any cline-neutral">&nbsp;</span>
  211. <span class="cline-any cline-neutral">&nbsp;</span>
  212. <span class="cline-any cline-yes">1×</span>
  213. <span class="cline-any cline-neutral">&nbsp;</span>
  214. <span class="cline-any cline-yes">1×</span>
  215. <span class="cline-any cline-neutral">&nbsp;</span>
  216. <span class="cline-any cline-neutral">&nbsp;</span>
  217. <span class="cline-any cline-neutral">&nbsp;</span>
  218. <span class="cline-any cline-neutral">&nbsp;</span>
  219. <span class="cline-any cline-yes">1×</span>
  220. <span class="cline-any cline-yes">10×</span>
  221. <span class="cline-any cline-neutral">&nbsp;</span>
  222. <span class="cline-any cline-neutral">&nbsp;</span>
  223. <span class="cline-any cline-yes">1×</span>
  224. <span class="cline-any cline-yes">6×</span>
  225. <span class="cline-any cline-neutral">&nbsp;</span>
  226. <span class="cline-any cline-neutral">&nbsp;</span>
  227. <span class="cline-any cline-yes">1×</span>
  228. <span class="cline-any cline-neutral">&nbsp;</span>
  229. <span class="cline-any cline-neutral">&nbsp;</span>
  230. <span class="cline-any cline-neutral">&nbsp;</span>
  231. <span class="cline-any cline-neutral">&nbsp;</span>
  232. <span class="cline-any cline-neutral">&nbsp;</span>
  233. <span class="cline-any cline-neutral">&nbsp;</span>
  234. <span class="cline-any cline-yes">1×</span>
  235. <span class="cline-any cline-yes">5×</span>
  236. <span class="cline-any cline-neutral">&nbsp;</span>
  237. <span class="cline-any cline-neutral">&nbsp;</span>
  238. <span class="cline-any cline-yes">1×</span>
  239. <span class="cline-any cline-neutral">&nbsp;</span>
  240. <span class="cline-any cline-neutral">&nbsp;</span>
  241. <span class="cline-any cline-neutral">&nbsp;</span>
  242. <span class="cline-any cline-neutral">&nbsp;</span>
  243. <span class="cline-any cline-neutral">&nbsp;</span>
  244. <span class="cline-any cline-neutral">&nbsp;</span>
  245. <span class="cline-any cline-yes">1×</span>
  246. <span class="cline-any cline-yes">8×</span>
  247. <span class="cline-any cline-neutral">&nbsp;</span>
  248. <span class="cline-any cline-neutral">&nbsp;</span>
  249. <span class="cline-any cline-neutral">&nbsp;</span>
  250. <span class="cline-any cline-neutral">&nbsp;</span>
  251. <span class="cline-any cline-neutral">&nbsp;</span>
  252. <span class="cline-any cline-neutral">&nbsp;</span>
  253. <span class="cline-any cline-yes">1×</span>
  254. <span class="cline-any cline-yes">2×</span>
  255. <span class="cline-any cline-neutral">&nbsp;</span>
  256. <span class="cline-any cline-neutral">&nbsp;</span>
  257. <span class="cline-any cline-neutral">&nbsp;</span>
  258. <span class="cline-any cline-neutral">&nbsp;</span>
  259. <span class="cline-any cline-neutral">&nbsp;</span>
  260. <span class="cline-any cline-neutral">&nbsp;</span>
  261. <span class="cline-any cline-neutral">&nbsp;</span>
  262. <span class="cline-any cline-yes">1×</span>
  263. <span class="cline-any cline-neutral">&nbsp;</span>
  264. <span class="cline-any cline-yes">5×</span>
  265. <span class="cline-any cline-neutral">&nbsp;</span>
  266. <span class="cline-any cline-neutral">&nbsp;</span>
  267. <span class="cline-any cline-neutral">&nbsp;</span>
  268. <span class="cline-any cline-neutral">&nbsp;</span>
  269. <span class="cline-any cline-yes">1×</span>
  270. <span class="cline-any cline-neutral">&nbsp;</span>
  271. <span class="cline-any cline-yes">5×</span>
  272. <span class="cline-any cline-neutral">&nbsp;</span>
  273. <span class="cline-any cline-neutral">&nbsp;</span>
  274. <span class="cline-any cline-neutral">&nbsp;</span>
  275. <span class="cline-any cline-neutral">&nbsp;</span>
  276. <span class="cline-any cline-neutral">&nbsp;</span>
  277. <span class="cline-any cline-yes">1×</span>
  278. <span class="cline-any cline-yes">2×</span>
  279. <span class="cline-any cline-yes">2×</span>
  280. <span class="cline-any cline-neutral">&nbsp;</span>
  281. <span class="cline-any cline-neutral">&nbsp;</span>
  282. <span class="cline-any cline-yes">1×</span>
  283. <span class="cline-any cline-yes">2×</span>
  284. <span class="cline-any cline-neutral">&nbsp;</span>
  285. <span class="cline-any cline-neutral">&nbsp;</span>
  286. <span class="cline-any cline-yes">1×</span>
  287. <span class="cline-any cline-yes">2×</span>
  288. <span class="cline-any cline-neutral">&nbsp;</span>
  289. <span class="cline-any cline-neutral">&nbsp;</span>
  290. <span class="cline-any cline-yes">1×</span>
  291. <span class="cline-any cline-yes">25×</span>
  292. <span class="cline-any cline-yes">13×</span>
  293. <span class="cline-any cline-yes">8×</span>
  294. <span class="cline-any cline-no">&nbsp;</span>
  295. <span class="cline-any cline-no">&nbsp;</span>
  296. <span class="cline-any cline-no">&nbsp;</span>
  297. <span class="cline-any cline-no">&nbsp;</span>
  298. <span class="cline-any cline-neutral">&nbsp;</span>
  299. <span class="cline-any cline-no">&nbsp;</span>
  300. <span class="cline-any cline-no">&nbsp;</span>
  301. <span class="cline-any cline-neutral">&nbsp;</span>
  302. <span class="cline-any cline-yes">8×</span>
  303. <span class="cline-any cline-neutral">&nbsp;</span>
  304. <span class="cline-any cline-no">&nbsp;</span>
  305. <span class="cline-any cline-no">&nbsp;</span>
  306. <span class="cline-any cline-no">&nbsp;</span>
  307. <span class="cline-any cline-neutral">&nbsp;</span>
  308. <span class="cline-any cline-yes">8×</span>
  309. <span class="cline-any cline-neutral">&nbsp;</span>
  310. <span class="cline-any cline-neutral">&nbsp;</span>
  311. <span class="cline-any cline-yes">20×</span>
  312. <span class="cline-any cline-neutral">&nbsp;</span>
  313. <span class="cline-any cline-neutral">&nbsp;</span>
  314. <span class="cline-any cline-yes">1×</span>
  315. <span class="cline-any cline-yes">2×</span>
  316. <span class="cline-any cline-yes">2×</span>
  317. <span class="cline-any cline-no">&nbsp;</span>
  318. <span class="cline-any cline-neutral">&nbsp;</span>
  319. <span class="cline-any cline-yes">2×</span>
  320. <span class="cline-any cline-neutral">&nbsp;</span>
  321. <span class="cline-any cline-neutral">&nbsp;</span>
  322. <span class="cline-any cline-yes">2×</span>
  323. <span class="cline-any cline-yes">2×</span>
  324. <span class="cline-any cline-neutral">&nbsp;</span>
  325. <span class="cline-any cline-neutral">&nbsp;</span>
  326. <span class="cline-any cline-yes">3×</span>
  327. <span class="cline-any cline-no">&nbsp;</span>
  328. <span class="cline-any cline-no">&nbsp;</span>
  329. <span class="cline-any cline-no">&nbsp;</span>
  330. <span class="cline-any cline-no">&nbsp;</span>
  331. <span class="cline-any cline-neutral">&nbsp;</span>
  332. <span class="cline-any cline-neutral">&nbsp;</span>
  333. <span class="cline-any cline-yes">1×</span>
  334. <span class="cline-any cline-yes">1×</span>
  335. <span class="cline-any cline-yes">1×</span>
  336. <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">var Stream = require('stream')
  337. &nbsp;
  338. module.exports = MuteStream
  339. &nbsp;
  340. // var out = new MuteStream(process.stdout)
  341. // argument auto-pipes
  342. function MuteStream (opts) {
  343. Stream.apply(this)
  344. opts = opts || {}
  345. this.writable = this.readable = true
  346. this.muted = false
  347. this.on('pipe', this._onpipe)
  348. this.replace = opts.replace
  349. &nbsp;
  350. // For readline-type situations
  351. // This much at the start of a line being redrawn after a ctrl char
  352. // is seen (such as backspace) won't be redrawn as the replacement
  353. this._prompt = opts.prompt || null
  354. this._hadControl = false
  355. }
  356. &nbsp;
  357. MuteStream.prototype = Object.create(Stream.prototype)
  358. &nbsp;
  359. Object.defineProperty(MuteStream.prototype, 'constructor', {
  360. value: MuteStream,
  361. enumerable: false
  362. })
  363. &nbsp;
  364. MuteStream.prototype.mute = function () {
  365. this.muted = true
  366. }
  367. &nbsp;
  368. MuteStream.prototype.unmute = function () {
  369. this.muted = false
  370. }
  371. &nbsp;
  372. Object.defineProperty(MuteStream.prototype, '_onpipe', {
  373. value: onPipe,
  374. enumerable: false,
  375. writable: true,
  376. configurable: true
  377. })
  378. &nbsp;
  379. function onPipe (src) {
  380. this._src = src
  381. }
  382. &nbsp;
  383. Object.defineProperty(MuteStream.prototype, 'isTTY', {
  384. get: getIsTTY,
  385. set: setIsTTY,
  386. enumerable: true,
  387. configurable: true
  388. })
  389. &nbsp;
  390. function getIsTTY () {
  391. return( (this._dest) ? this._dest.isTTY
  392. : (this._src) ? this._src.isTTY
  393. : false
  394. )
  395. }
  396. &nbsp;
  397. // basically just get replace the getter/setter with a regular value
  398. function setIsTTY (isTTY) {
  399. Object.defineProperty(this, 'isTTY', {
  400. value: isTTY,
  401. enumerable: true,
  402. writable: true,
  403. configurable: true
  404. })
  405. }
  406. &nbsp;
  407. Object.defineProperty(MuteStream.prototype, 'rows', {
  408. get: function () {
  409. return( this._dest ? this._dest.rows
  410. : this._src ? <span class="branch-0 cbranch-no" title="branch not covered" >this._src.rows</span>
  411. : undefined )
  412. }, enumerable: true, configurable: true })
  413. &nbsp;
  414. Object.defineProperty(MuteStream.prototype, 'columns', {
  415. get: function () {
  416. return( this._dest ? this._dest.columns
  417. : this._src ? <span class="branch-0 cbranch-no" title="branch not covered" >this._src.columns</span>
  418. : undefined )
  419. }, enumerable: true, configurable: true })
  420. &nbsp;
  421. &nbsp;
  422. MuteStream.prototype.pipe = function (dest, options) {
  423. this._dest = dest
  424. return Stream.prototype.pipe.call(this, dest, options)
  425. }
  426. &nbsp;
  427. MuteStream.prototype.pause = function () {
  428. <span class="missing-if-branch" title="else path not taken" >E</span>if (this._src) return this._src.pause()
  429. }
  430. &nbsp;
  431. MuteStream.prototype.resume = function () {
  432. <span class="missing-if-branch" title="else path not taken" >E</span>if (this._src) return this._src.resume()
  433. }
  434. &nbsp;
  435. MuteStream.prototype.write = function (c) {
  436. if (this.muted) {
  437. if (!this.replace) return true
  438. <span class="missing-if-branch" title="if path not taken" >I</span>if (c.match(/^\u001b/)) {
  439. <span class="cstat-no" title="statement not covered" > if(c.indexOf(this._prompt) === 0) {</span>
  440. <span class="cstat-no" title="statement not covered" > c = c.substr(this._prompt.length);</span>
  441. <span class="cstat-no" title="statement not covered" > c = c.replace(/./g, this.replace);</span>
  442. <span class="cstat-no" title="statement not covered" > c = this._prompt + c;</span>
  443. }
  444. <span class="cstat-no" title="statement not covered" > this._hadControl = true</span>
  445. <span class="cstat-no" title="statement not covered" > return this.emit('data', c)</span>
  446. } else {
  447. <span class="missing-if-branch" title="if path not taken" >I</span>if (this._prompt &amp;&amp; <span class="branch-1 cbranch-no" title="branch not covered" >this._hadControl </span>&amp;&amp;
  448. <span class="branch-2 cbranch-no" title="branch not covered" > c.indexOf(this._prompt) === 0)</span> {
  449. <span class="cstat-no" title="statement not covered" > this._hadControl = false</span>
  450. <span class="cstat-no" title="statement not covered" > this.emit('data', this._prompt)</span>
  451. <span class="cstat-no" title="statement not covered" > c = c.substr(this._prompt.length)</span>
  452. }
  453. c = c.toString().replace(/./g, this.replace)
  454. }
  455. }
  456. this.emit('data', c)
  457. }
  458. &nbsp;
  459. MuteStream.prototype.end = function (c) {
  460. <span class="missing-if-branch" title="else path not taken" >E</span>if (this.muted) {
  461. <span class="missing-if-branch" title="if path not taken" >I</span>if (c &amp;&amp; this.replace) {
  462. <span class="cstat-no" title="statement not covered" > c = c.toString().replace(/./g, this.replace)</span>
  463. } else {
  464. c = null
  465. }
  466. }
  467. <span class="missing-if-branch" title="if path not taken" >I</span>if (c) <span class="cstat-no" title="statement not covered" >this.emit('data', c)</span>
  468. this.emit('end')
  469. }
  470. &nbsp;
  471. function proxy (fn) { return <span class="fstat-no" title="function not covered" >function () {</span>
  472. <span class="cstat-no" title="statement not covered" > var d = this._dest</span>
  473. <span class="cstat-no" title="statement not covered" > var s = this._src</span>
  474. <span class="cstat-no" title="statement not covered" > if (d &amp;&amp; d[fn]) <span class="cstat-no" title="statement not covered" >d[fn].apply(d, arguments)</span></span>
  475. <span class="cstat-no" title="statement not covered" > if (s &amp;&amp; s[fn]) <span class="cstat-no" title="statement not covered" >s[fn].apply(s, arguments)</span></span>
  476. }}
  477. &nbsp;
  478. MuteStream.prototype.destroy = proxy('destroy')
  479. MuteStream.prototype.destroySoon = proxy('destroySoon')
  480. MuteStream.prototype.close = proxy('close')
  481. &nbsp;</pre></td></tr>
  482. </table></pre>
  483. <div class='push'></div><!-- for sticky footer -->
  484. </div><!-- /wrapper -->
  485. <div class='footer quiet pad2 space-top1 center small'>
  486. Code coverage
  487. generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Feb 12 2016 22:19:00 GMT-0800 (PST)
  488. </div>
  489. </div>
  490. <script src="../prettify.js"></script>
  491. <script>
  492. window.onload = function () {
  493. if (typeof prettyPrint === 'function') {
  494. prettyPrint();
  495. }
  496. };
  497. </script>
  498. <script src="../sorter.js"></script>
  499. </body>
  500. </html>