@sc-voice/tools 3.7.0 → 3.9.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.9.0",
4
4
  "description": "Utilities for SC-Voice",
5
5
  "main": "index.mjs",
6
6
  "files": [
@@ -23,46 +23,71 @@ 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}`;
60
- case 'number':
61
- return `${GREEN}${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;
76
+ case 'number': {
77
+ let v = thing.toFixed(precision);
78
+ if (thing === Number(v)) {
79
+ v = v.replace(/\.?0+$/, '')
80
+ }
81
+ a.push(label+GREEN+v+NO_COLOR);
82
+ break;
83
+ }
62
84
  default:
63
- return `${color}${JSON.stringify(thing)}${NO_COLOR}`;
85
+ a.push(label+color+JSON.stringify(thing)+NO_COLOR);
86
+ break;
64
87
  }
65
- });
88
+ label = newLabel;
89
+ return a;
90
+ }, []);
66
91
  }
67
92
 
68
93
  fyi(...rest) {
@@ -117,12 +142,12 @@ export class ColorConsole {
117
142
  this.write(...this.color(color, ...rest));
118
143
  }
119
144
 
120
- tag3(msg, lvl, ...rest) {
145
+ tag3(...rest) {
121
146
  let color = this.colorTag3;
122
147
  this.write(...this.color(color, ...rest));
123
148
  }
124
149
 
125
- tag4(msg, lvl, ...rest) {
150
+ tag4(...rest) {
126
151
  let color = this.colorTag4;
127
152
  this.write(...this.color(color, ...rest));
128
153
  }