@sc-voice/tools 3.15.0 → 3.17.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 +1 -1
- package/src/defines.mjs +1 -0
- package/src/math/interval.mjs +18 -8
- package/src/text/color-console.mjs +77 -73
package/package.json
CHANGED
package/src/defines.mjs
CHANGED
package/src/math/interval.mjs
CHANGED
|
@@ -99,7 +99,7 @@ export class Interval {
|
|
|
99
99
|
const msg = 'i6l.contains';
|
|
100
100
|
const dbg = DBG.I6L_CONTAINS;
|
|
101
101
|
if (typeof num !== 'number' || Number.isNaN(num)) {
|
|
102
|
-
dbg && cc.fyi1(msg+0.1, false);
|
|
102
|
+
dbg && cc.fyi1(msg + 0.1, false);
|
|
103
103
|
return false;
|
|
104
104
|
}
|
|
105
105
|
let { lo, hi, leftOpen, rightOpen } = this;
|
|
@@ -151,28 +151,38 @@ export class Interval {
|
|
|
151
151
|
overlaps(iv2) {
|
|
152
152
|
const msg = 'i6l.overlaps';
|
|
153
153
|
const dbg = DBG.I6L_OVERLAPS;
|
|
154
|
-
let {
|
|
155
|
-
|
|
154
|
+
let {
|
|
155
|
+
lo: lo1,
|
|
156
|
+
hi: hi1,
|
|
157
|
+
leftOpen: lOpen1,
|
|
158
|
+
rightOpen: rOpen1,
|
|
159
|
+
} = this;
|
|
160
|
+
let {
|
|
161
|
+
lo: lo2,
|
|
162
|
+
hi: hi2,
|
|
163
|
+
leftOpen: lOpen2,
|
|
164
|
+
rightOpen: rOpen2,
|
|
165
|
+
} = iv2;
|
|
156
166
|
|
|
157
167
|
//console.log(msg, {lo1, lo2, hi1, hi2});
|
|
158
168
|
if (!lOpen1 && iv2.contains(lo1)) {
|
|
159
|
-
dbg && cc.fyi1(msg+1, 'lo1');
|
|
169
|
+
dbg && cc.fyi1(msg + 1, 'lo1');
|
|
160
170
|
return true;
|
|
161
171
|
}
|
|
162
172
|
if (!rOpen1 && iv2.contains(hi1)) {
|
|
163
|
-
dbg && cc.fyi1(msg+2, 'hi1');
|
|
173
|
+
dbg && cc.fyi1(msg + 2, 'hi1');
|
|
164
174
|
return true;
|
|
165
175
|
}
|
|
166
176
|
if (!lOpen2 && this.contains(lo2)) {
|
|
167
|
-
dbg && cc.fyi1(msg+3, 'lo2');
|
|
177
|
+
dbg && cc.fyi1(msg + 3, 'lo2');
|
|
168
178
|
return true;
|
|
169
179
|
}
|
|
170
180
|
if (!rOpen2 && this.contains(hi2)) {
|
|
171
|
-
dbg && cc.fyi1(msg+4, 'hi2');
|
|
181
|
+
dbg && cc.fyi1(msg + 4, 'hi2');
|
|
172
182
|
return true;
|
|
173
183
|
}
|
|
174
184
|
|
|
175
|
-
dbg && cc.fyi1(msg+0.1, false);
|
|
185
|
+
dbg && cc.fyi1(msg + 0.1, false);
|
|
176
186
|
return false;
|
|
177
187
|
}
|
|
178
188
|
}
|
|
@@ -25,32 +25,30 @@ let CC;
|
|
|
25
25
|
export class ColorConsole {
|
|
26
26
|
constructor(opts = {}) {
|
|
27
27
|
let {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
badColor1 = BRIGHT_RED,
|
|
29
|
+
badColor2 = RED,
|
|
30
|
+
fyiColor1 = BRIGHT_WHITE,
|
|
31
|
+
fyiColor2 = BRIGHT_BLACK,
|
|
32
|
+
okColor1 = BRIGHT_GREEN,
|
|
33
|
+
okColor2 = GREEN,
|
|
34
|
+
valueColor = CYAN,
|
|
35
|
+
dateFormat = new Intl.DateTimeFormat(undefined, {
|
|
36
|
+
dateStyle: 'short',
|
|
37
|
+
}),
|
|
38
38
|
precision = 3,
|
|
39
39
|
write = (...args) => console.log.call(null, ...args),
|
|
40
40
|
} = opts;
|
|
41
41
|
|
|
42
42
|
Object.assign(this, {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
colorTag2,
|
|
51
|
-
colorTag3,
|
|
52
|
-
colorTag4,
|
|
43
|
+
badColor1,
|
|
44
|
+
badColor2,
|
|
45
|
+
dateFormat,
|
|
46
|
+
fyiColor1,
|
|
47
|
+
fyiColor2,
|
|
48
|
+
okColor1,
|
|
49
|
+
okColor2,
|
|
53
50
|
precision,
|
|
51
|
+
valueColor,
|
|
54
52
|
write,
|
|
55
53
|
});
|
|
56
54
|
}
|
|
@@ -60,59 +58,89 @@ export class ColorConsole {
|
|
|
60
58
|
return CC;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
|
|
61
|
+
valueOf(thing) {
|
|
62
|
+
const msg = 'c10e.valueOf';
|
|
64
63
|
let { precision } = this;
|
|
64
|
+
switch (typeof thing) {
|
|
65
|
+
case 'object': {
|
|
66
|
+
if (thing === null) {
|
|
67
|
+
return 'null';
|
|
68
|
+
}
|
|
69
|
+
if (thing instanceof Date) {
|
|
70
|
+
return this.dateFormat.format(thing);
|
|
71
|
+
}
|
|
72
|
+
if (
|
|
73
|
+
thing.constructor !== Object &&
|
|
74
|
+
typeof thing.toString === 'function'
|
|
75
|
+
) {
|
|
76
|
+
return thing.toString();
|
|
77
|
+
}
|
|
78
|
+
return thing;
|
|
79
|
+
}
|
|
80
|
+
case 'string':
|
|
81
|
+
return thing;
|
|
82
|
+
case 'number': {
|
|
83
|
+
let v = thing.toFixed(precision);
|
|
84
|
+
if (thing === Number(v)) {
|
|
85
|
+
v = v.replace(/\.?0+$/, '');
|
|
86
|
+
}
|
|
87
|
+
return v;
|
|
88
|
+
}
|
|
89
|
+
default:
|
|
90
|
+
return JSON.stringify(thing);
|
|
91
|
+
}
|
|
92
|
+
} // valueOf
|
|
93
|
+
|
|
94
|
+
color(textColor, ...things) {
|
|
95
|
+
let { valueColor } = this;
|
|
65
96
|
let label = '';
|
|
97
|
+
let endColor = NO_COLOR;
|
|
66
98
|
return things.reduce((a, thing) => {
|
|
67
99
|
let newLabel = '';
|
|
100
|
+
let v = this.valueOf(thing);
|
|
68
101
|
switch (typeof thing) {
|
|
69
102
|
case 'object': {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
thing &&
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
103
|
+
if (
|
|
104
|
+
thing === null ||
|
|
105
|
+
(thing.constructor !== Object &&
|
|
106
|
+
typeof thing.toString === 'function')
|
|
107
|
+
) {
|
|
108
|
+
a.push(label + valueColor + v + endColor);
|
|
109
|
+
} else {
|
|
110
|
+
label && a.push(label + endColor);
|
|
111
|
+
a.push(v);
|
|
112
|
+
}
|
|
78
113
|
break;
|
|
79
114
|
}
|
|
80
115
|
case 'string':
|
|
81
116
|
if (thing.endsWith(':')) {
|
|
82
|
-
newLabel =
|
|
117
|
+
newLabel = textColor + v;
|
|
118
|
+
} else if (label) {
|
|
119
|
+
a.push(label + valueColor + v + endColor);
|
|
83
120
|
} else {
|
|
84
|
-
a.push(
|
|
85
|
-
}
|
|
86
|
-
break;
|
|
87
|
-
case 'number': {
|
|
88
|
-
let v = thing.toFixed(precision);
|
|
89
|
-
if (thing === Number(v)) {
|
|
90
|
-
v = v.replace(/\.?0+$/, '');
|
|
121
|
+
a.push(textColor + v + endColor);
|
|
91
122
|
}
|
|
92
|
-
a.push(label + GREEN + v + NO_COLOR);
|
|
93
123
|
break;
|
|
94
|
-
|
|
124
|
+
case 'number':
|
|
95
125
|
default:
|
|
96
|
-
a.push(label +
|
|
126
|
+
a.push(label + valueColor + v + endColor);
|
|
97
127
|
break;
|
|
98
128
|
}
|
|
99
129
|
label = newLabel;
|
|
100
130
|
return a;
|
|
101
131
|
}, []);
|
|
102
|
-
}
|
|
132
|
+
} // color
|
|
103
133
|
|
|
104
134
|
fyi(...rest) {
|
|
105
135
|
return this.fyi2(...rest);
|
|
106
136
|
}
|
|
107
137
|
|
|
108
138
|
fyi1(...rest) {
|
|
109
|
-
|
|
110
|
-
this.write(...this.color(color, ...rest));
|
|
139
|
+
this.write(...this.color(this.fyiColor1, ...rest));
|
|
111
140
|
}
|
|
112
141
|
|
|
113
142
|
fyi2(...rest) {
|
|
114
|
-
|
|
115
|
-
this.write(...this.color(color, ...rest));
|
|
143
|
+
this.write(...this.color(this.fyiColor2, ...rest));
|
|
116
144
|
}
|
|
117
145
|
|
|
118
146
|
ok(...rest) {
|
|
@@ -120,13 +148,11 @@ export class ColorConsole {
|
|
|
120
148
|
}
|
|
121
149
|
|
|
122
150
|
ok1(...rest) {
|
|
123
|
-
|
|
124
|
-
this.write(...this.color(color, ...rest));
|
|
151
|
+
this.write(...this.color(this.okColor1, ...rest));
|
|
125
152
|
}
|
|
126
153
|
|
|
127
154
|
ok2(...rest) {
|
|
128
|
-
|
|
129
|
-
this.write(...this.color(color, ...rest));
|
|
155
|
+
this.write(...this.color(this.okColor2, ...rest));
|
|
130
156
|
}
|
|
131
157
|
|
|
132
158
|
bad(...rest) {
|
|
@@ -134,32 +160,10 @@ export class ColorConsole {
|
|
|
134
160
|
}
|
|
135
161
|
|
|
136
162
|
bad1(...rest) {
|
|
137
|
-
|
|
138
|
-
this.write(...this.color(color, ...rest));
|
|
163
|
+
this.write(...this.color(this.badColor1, ...rest));
|
|
139
164
|
}
|
|
140
165
|
|
|
141
166
|
bad2(...rest) {
|
|
142
|
-
|
|
143
|
-
this.write(...this.color(color, ...rest));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
tag1(...rest) {
|
|
147
|
-
let color = this.colorTag1;
|
|
148
|
-
this.write(...this.color(color, ...rest));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
tag2(...rest) {
|
|
152
|
-
let color = this.colorTag2;
|
|
153
|
-
this.write(...this.color(color, ...rest));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
tag3(...rest) {
|
|
157
|
-
let color = this.colorTag3;
|
|
158
|
-
this.write(...this.color(color, ...rest));
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
tag4(...rest) {
|
|
162
|
-
let color = this.colorTag4;
|
|
163
|
-
this.write(...this.color(color, ...rest));
|
|
167
|
+
this.write(...this.color(this.badColor2, ...rest));
|
|
164
168
|
}
|
|
165
169
|
}
|