bare-console 3.0.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +28 -30
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -7,34 +7,22 @@ module.exports = class Console {
7
7
 
8
8
  this._colors = opts.colors === true
9
9
  this._timers = new Map()
10
- }
11
-
12
- log (...args) {
13
- let out = ''
14
- let first = true
15
10
 
16
- for (const arg of args) {
17
- if (first) first = false
18
- else out += ' '
19
-
20
- out += typeof arg === 'string' ? arg : inspect(arg, { colors: this._colors })
11
+ if (opts.bind) {
12
+ this.log = this.log.bind(this)
13
+ this.error = this.error.bind(this)
14
+ this.time = this.time.bind(this)
15
+ this.timeEnd = this.timeEnd.bind(this)
16
+ this.trace = this.trace.bind(this)
21
17
  }
18
+ }
22
19
 
23
- this._stdout.write(out + '\n')
20
+ log (...args) {
21
+ this._stdout.write(formatArgs(args) + '\n')
24
22
  }
25
23
 
26
24
  error (...args) {
27
- let out = ''
28
- let first = true
29
-
30
- for (const arg of args) {
31
- if (first) first = false
32
- else out += ' '
33
-
34
- out += typeof arg === 'string' ? arg : inspect(arg, { colors: this._colors })
35
- }
36
-
37
- this._stderr.write(out + '\n')
25
+ this._stderr.write(formatArgs(args) + '\n')
38
26
  }
39
27
 
40
28
  time (label = 'default') {
@@ -62,17 +50,27 @@ module.exports = class Console {
62
50
  else this.log(label + ': ' + ms.toFixed(3) + 'ms')
63
51
  }
64
52
 
65
- trace (...messages) {
66
- const { stack } = new Error()
67
-
68
- const first = stack.indexOf('\n')
69
- const second = stack.indexOf('\n', first + 1)
70
- const start = second > -1 ? second : 0
71
-
72
- this.error('Trace: ' + messages.join(' ') + stack.slice(start))
53
+ trace (...args) {
54
+ const err = { name: 'Trace', message: formatArgs(args) }
55
+ Error.captureStackTrace(err, this.trace)
56
+ this.error(err.stack)
73
57
  }
74
58
  }
75
59
 
76
60
  function adaptStream (stream) {
77
61
  return typeof stream === 'function' ? { write: stream } : stream
78
62
  }
63
+
64
+ function formatArgs (args) {
65
+ let out = ''
66
+ let first = true
67
+
68
+ for (const arg of args) {
69
+ if (first) first = false
70
+ else out += ' '
71
+
72
+ out += typeof arg === 'string' ? arg : inspect(arg, { colors: this._colors })
73
+ }
74
+
75
+ return out
76
+ }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "bare-console",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "description": "Simple debugging console for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [
7
7
  "index.js"
8
8
  ],
9
9
  "scripts": {
10
- "test": "standard && bare test.js"
10
+ "test": "standard && brittle test.js"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "homepage": "https://github.com/holepunchto/bare-console#readme",
22
22
  "dependencies": {
23
- "bare-inspect": "^1.0.0"
23
+ "bare-inspect": "^1.1.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "brittle": "^3.1.1",