-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
61 lines (46 loc) · 1.54 KB
/
utils.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
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
var util = require('util')
var utils = {}
/**
* Lazily required module dependencies
*/
utils.alwaysDone = require('always-done')
utils.stackMetadata = require('stacktrace-metadata')
utils.coreAssert = require('core-assert')
utils.errorSymbol = require('error-symbol')
utils.extendShallow = require('extend-shallow')
utils.getFnName = require('get-fn-name')
utils.successSymbol = require('success-symbol')
utils.diag = function diagnostic (err, showStack) {
var res = ' ---\n'
// get message, or toString error object
var msg = err.message && err.message.length
? err.message
: err.toString()
showStack = showStack ? showStack : false // eslint-disable-line no-unneeded-ternary
err = utils.stackMetadata(err, { showStack: showStack, shortStack: false })
res += utils.ident('name: ' + err.name)
res += utils.ident('message: ' + msg)
// show inspected expected value if exists
res = err.expected
? res + utils.ident('expected: ' + util.inspect(err.expected))
: res
// show inspected actual value if exists
res = err.actual
? res + utils.ident('actual: ' + util.inspect(err.actual))
: res
res = err.at ? res + utils.ident('at: ' + err.at) : res
// print stack trace if `showStack` option is `true`
if (showStack && err.stack) {
res += utils.ident('stack:\n' + err.stack.split('\n').slice(1).join('\n'))
}
res += utils.ident('...', true)
return res
}
utils.ident = function ident (str, last) {
return ' ' + str + (last ? '' : '\n')
}
/**
* Expose `utils` modules
*/
module.exports = utils