@sc-voice/tools 3.7.0 → 3.8.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sc-voice/tools",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "Utilities for SC-Voice",
5
5
  "main": "index.mjs",
6
6
  "files": [
@@ -23,46 +23,66 @@ const {
23
23
  export class ColorConsole {
24
24
  constructor(opts = {}) {
25
25
  let {
26
- write = (...args) => console.log.call(null, ...args),
27
- colorOk1 = BRIGHT_GREEN,
28
- colorOk2 = GREEN,
29
- colorFyi1 = BRIGHT_BLACK,
30
26
  colorBad1 = BRIGHT_RED,
31
27
  colorBad2 = RED,
28
+ colorFyi1 = BRIGHT_WHITE,
29
+ colorFyi2 = BRIGHT_BLACK,
30
+ colorOk1 = BRIGHT_GREEN,
31
+ colorOk2 = GREEN,
32
32
  colorTag1 = CYAN,
33
33
  colorTag2 = BRIGHT_CYAN,
34
34
  colorTag3 = MAGENTA,
35
35
  colorTag4 = BRIGHT_MAGENTA,
36
+ precision = 3,
37
+ write = (...args) => console.log.call(null, ...args),
38
+
36
39
  } = opts;
37
40
 
38
41
  Object.assign(this, {
39
- write,
40
- colorOk1,
41
- colorOk2,
42
- colorFyi1,
43
42
  colorBad1,
44
43
  colorBad2,
44
+ colorFyi1,
45
+ colorFyi2,
46
+ colorOk1,
47
+ colorOk2,
45
48
  colorTag1,
46
49
  colorTag2,
47
50
  colorTag3,
48
51
  colorTag4,
52
+ precision,
53
+ write,
54
+
49
55
  });
50
56
  }
51
57
 
52
58
  color(color, ...things) {
53
- return things.map((thing) => {
59
+ let { precision } = this;
60
+ let label = '';
61
+ return things.reduce((a,thing) => {
62
+ let newLabel = '';
54
63
  switch (typeof thing) {
55
64
  case 'object':
56
65
  // TODO: pretty objects like console
57
- return thing;
66
+ label && a.push(label);
67
+ a.push(thing);
68
+ break;
58
69
  case 'string':
59
- return `${color}${thing}${NO_COLOR}`;
70
+ if (thing.endsWith(':')) {
71
+ newLabel = NO_COLOR+thing;
72
+ } else {
73
+ a.push(label+color+thing+NO_COLOR);
74
+ }
75
+ break;
60
76
  case 'number':
61
- return `${GREEN}${thing}${NO_COLOR}`;
77
+ a.push(label+GREEN+thing.toFixed(precision)+NO_COLOR);
78
+ break;
62
79
  default:
63
- return `${color}${JSON.stringify(thing)}${NO_COLOR}`;
80
+ a.push(label+color+JSON.stringify(thing)+NO_COLOR);
81
+ break;
64
82
  }
65
- });
83
+ label = newLabel;
84
+ return a;
85
+ }, []);
66
86
  }
67
87
 
68
88
  fyi(...rest) {
@@ -117,12 +137,12 @@ export class ColorConsole {
117
137
  this.write(...this.color(color, ...rest));
118
138
  }
119
139
 
120
- tag3(msg, lvl, ...rest) {
140
+ tag3(...rest) {
121
141
  let color = this.colorTag3;
122
142
  this.write(...this.color(color, ...rest));
123
143
  }
124
144
 
125
- tag4(msg, lvl, ...rest) {
145
+ tag4(...rest) {
126
146
  let color = this.colorTag4;
127
147
  this.write(...this.color(color, ...rest));
128
148
  }