@sc-voice/tools 3.6.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.6.0",
3
+ "version": "3.8.0",
4
4
  "description": "Utilities for SC-Voice",
5
5
  "main": "index.mjs",
6
6
  "files": [
@@ -93,6 +93,15 @@ export class Interval {
93
93
 
94
94
  toString() {
95
95
  let { lo, hi } = this;
96
+ if (lo === hi) {
97
+ return [
98
+ lo === INFINITY ? '(' : '[',
99
+ lo === INFINITY ? MINUS_INFINITY : lo,
100
+ lo == null ? '' : ',',
101
+ hi === INFINITY ? PLUS_INFINITY : hi,
102
+ hi === INFINITY ? ')' : ']',
103
+ ].join('');
104
+ }
96
105
  return [
97
106
  lo === INFINITY ? '(' : '[',
98
107
  lo === INFINITY ? MINUS_INFINITY : lo,
@@ -23,55 +23,84 @@ 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
- fyi(msg, ...rest) {
88
+ fyi(...rest) {
89
+ return this.fyi2(...rest);
90
+ }
91
+
92
+ fyi1(...rest) {
69
93
  let color = this.colorFyi1;
70
- this.write(...this.color(color, rest));
94
+ this.write(...this.color(color, ...rest));
95
+ }
96
+
97
+ fyi2(...rest) {
98
+ let color = this.colorFyi2;
99
+ this.write(...this.color(color, ...rest));
71
100
  }
72
101
 
73
102
  ok(...rest) {
74
- return this.ok1(...rest);
103
+ return this.ok2(...rest);
75
104
  }
76
105
 
77
106
  ok1(...rest) {
@@ -85,7 +114,7 @@ export class ColorConsole {
85
114
  }
86
115
 
87
116
  bad(...rest) {
88
- return this.bad1(...rest);
117
+ return this.bad2(...rest);
89
118
  }
90
119
 
91
120
  bad1(...rest) {
@@ -108,12 +137,12 @@ export class ColorConsole {
108
137
  this.write(...this.color(color, ...rest));
109
138
  }
110
139
 
111
- tag3(msg, lvl, ...rest) {
140
+ tag3(...rest) {
112
141
  let color = this.colorTag3;
113
142
  this.write(...this.color(color, ...rest));
114
143
  }
115
144
 
116
- tag4(msg, lvl, ...rest) {
145
+ tag4(...rest) {
117
146
  let color = this.colorTag4;
118
147
  this.write(...this.color(color, ...rest));
119
148
  }