-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (44 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*!
* clean-tostring <https://github.com/tunnckoCore/clean-tostring>
*
* Copyright (c) 2016 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
'use strict'
var cleanupCoverageCode = require('cleanup-coverage-code')
/**
* > Clean coverage code of `fn.toString()`, but be aware of that
* it remains minified.
*
* **Example**
*
* ```js
* var cleanup = require('clean-tostring')
* var isIstanbul = process.env.running_under_istanbul
*
* function fixture (a) {
* if (typeof a === 'string') {
* return a
* }
* return false
* }
*
* if (isIstanbul) {
* console.log(cleanup(fixture))
* // => 'function fixture(a) {if(typeof a===\'string\'){return a;}else{}return false;}'
* } else {
* console.log(cleanup(fixture))
* // => 'function fixture(a) {\n if (typeof a === \'string\') {\n return a\n }\n return false\n }'
* }
* ```
*
* @param {Function} `fn`
* @return {String}
* @api public
*/
module.exports = function cleanTostring (fn) {
if (typeof fn !== 'function') {
throw new TypeError('clean-tostring: expect `fn` be function')
}
return cleanupCoverageCode(fn.toString()).replace('\)\{', ') {')
}