@trenskow/print 0.1.2 → 0.1.4

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/lib/index.js +9 -2
  2. package/package.json +2 -1
package/lib/index.js CHANGED
@@ -6,6 +6,7 @@
6
6
  // See license in LICENSE.
7
7
  //
8
8
 
9
+ import NullStream from '@trenskow/null-stream';
9
10
  import keyd from 'keyd';
10
11
 
11
12
  let ttyColumn = 0;
@@ -91,15 +92,21 @@ const printer = (stream) => {
91
92
  });
92
93
 
93
94
  data.forEach((row, idx) => {
95
+
94
96
  print.nn(idx === 0 && header ? '\x1b[1m' : '\x1b[0m');
95
- print(row.map((cell, idx) => cell.padEnd(columnWidth[idx])).join(' '));
97
+
98
+ print(
99
+ row
100
+ .map((cell) => typeof cell === 'function' ? cell() : cell)
101
+ .map((cell, idx) => cell.padEnd(columnWidth[idx])).join(' '));
102
+
96
103
  });
97
104
 
98
105
  };
99
106
 
100
107
  Object.defineProperty(print, 'tty', {
101
108
  get: () => {
102
- return stream.isTTY ? print : () => {};
109
+ return stream.isTTY ? print : printer(new NullStream());
103
110
  }
104
111
  });
105
112
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/print",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "A simple package for printing to the console (or other streams).",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -30,6 +30,7 @@
30
30
  "globals": "^15.14.0"
31
31
  },
32
32
  "dependencies": {
33
+ "@trenskow/null-stream": "^0.1.1",
33
34
  "keyd": "^2.1.17"
34
35
  }
35
36
  }