@sc-voice/tools 3.14.0 → 3.16.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.14.0",
3
+ "version": "3.16.0",
4
4
  "description": "Utilities for SC-Voice",
5
5
  "main": "index.mjs",
6
6
  "files": [
package/src/defines.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  export const DBG = {
2
2
  ALIGN_ALL: 0,
3
3
  ALIGN_LINE: 0,
4
+ COLOR_CONSOLE: 0,
4
5
  I6L_CONTAINS: 0,
5
6
  I6L_OVERLAPS: 0,
6
7
  ML_DOC_VECTORS: 0, // 'mn8:3.4',
@@ -1,5 +1,5 @@
1
1
  import { Unicode } from '../text/unicode.mjs';
2
- const { INFINITY } = Unicode;
2
+ const { EMPTY_SET, INFINITY } = Unicode;
3
3
  import { ColorConsole } from '../text/color-console.mjs';
4
4
  const { cc } = ColorConsole;
5
5
  import { DBG } from '../defines.mjs';
@@ -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;
@@ -126,50 +126,63 @@ export class Interval {
126
126
  }
127
127
 
128
128
  toString() {
129
- let { lo, hi } = this;
129
+ let { lo, hi, leftOpen, rightOpen, isEmpty } = this;
130
+ if (isEmpty) {
131
+ return EMPTY_SET;
132
+ }
130
133
  if (lo === hi) {
131
134
  return [
132
- lo === INFINITY ? '(' : '[',
135
+ leftOpen ? '(' : '[',
133
136
  lo === INFINITY ? MINUS_INFINITY : lo,
134
137
  lo == null ? '' : ',',
135
138
  hi === INFINITY ? PLUS_INFINITY : hi,
136
- hi === INFINITY ? ')' : ']',
139
+ rightOpen ? ')' : ']',
137
140
  ].join('');
138
141
  }
139
142
  return [
140
- lo === INFINITY ? '(' : '[',
143
+ leftOpen ? '(' : '[',
141
144
  lo === INFINITY ? MINUS_INFINITY : lo,
142
145
  lo === hi ? '' : ',',
143
146
  hi === INFINITY ? PLUS_INFINITY : hi,
144
- hi === INFINITY ? ')' : ']',
147
+ rightOpen ? ')' : ']',
145
148
  ].join('');
146
149
  }
147
150
 
148
151
  overlaps(iv2) {
149
152
  const msg = 'i6l.overlaps';
150
153
  const dbg = DBG.I6L_OVERLAPS;
151
- let { lo: lo1, hi: hi1, leftOpen:lOpen1, rightOpen: rOpen1 } = this;
152
- let { lo: lo2, hi: hi2, leftOpen:lOpen2, rightOpen: rOpen2 } = iv2;
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;
153
166
 
154
167
  //console.log(msg, {lo1, lo2, hi1, hi2});
155
168
  if (!lOpen1 && iv2.contains(lo1)) {
156
- dbg && cc.fyi1(msg+1, 'lo1');
169
+ dbg && cc.fyi1(msg + 1, 'lo1');
157
170
  return true;
158
171
  }
159
172
  if (!rOpen1 && iv2.contains(hi1)) {
160
- dbg && cc.fyi1(msg+2, 'hi1');
173
+ dbg && cc.fyi1(msg + 2, 'hi1');
161
174
  return true;
162
175
  }
163
176
  if (!lOpen2 && this.contains(lo2)) {
164
- dbg && cc.fyi1(msg+3, 'lo2');
177
+ dbg && cc.fyi1(msg + 3, 'lo2');
165
178
  return true;
166
179
  }
167
180
  if (!rOpen2 && this.contains(hi2)) {
168
- dbg && cc.fyi1(msg+4, 'hi2');
181
+ dbg && cc.fyi1(msg + 4, 'hi2');
169
182
  return true;
170
183
  }
171
184
 
172
- dbg && cc.fyi1(msg+0.1, false);
185
+ dbg && cc.fyi1(msg + 0.1, false);
173
186
  return false;
174
187
  }
175
188
  }
@@ -25,31 +25,25 @@ let CC;
25
25
  export class ColorConsole {
26
26
  constructor(opts = {}) {
27
27
  let {
28
- colorBad1 = BRIGHT_RED,
29
- colorBad2 = RED,
30
- colorFyi1 = BRIGHT_WHITE,
31
- colorFyi2 = BRIGHT_BLACK,
32
- colorOk1 = BRIGHT_GREEN,
33
- colorOk2 = GREEN,
34
- colorTag1 = CYAN,
35
- colorTag2 = BRIGHT_CYAN,
36
- colorTag3 = MAGENTA,
37
- colorTag4 = BRIGHT_MAGENTA,
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,
38
35
  precision = 3,
39
36
  write = (...args) => console.log.call(null, ...args),
40
37
  } = opts;
41
38
 
42
39
  Object.assign(this, {
43
- colorBad1,
44
- colorBad2,
45
- colorFyi1,
46
- colorFyi2,
47
- colorOk1,
48
- colorOk2,
49
- colorTag1,
50
- colorTag2,
51
- colorTag3,
52
- colorTag4,
40
+ badColor1,
41
+ badColor2,
42
+ fyiColor1,
43
+ fyiColor2,
44
+ okColor1,
45
+ okColor2,
46
+ valueColor,
53
47
  precision,
54
48
  write,
55
49
  });
@@ -60,28 +54,34 @@ export class ColorConsole {
60
54
  return CC;
61
55
  }
62
56
 
63
- color(color, ...things) {
64
- let { precision } = this;
57
+ color(textColor, ...things) {
58
+ let { precision, valueColor } = this;
65
59
  let label = '';
60
+ let endColor = NO_COLOR;
66
61
  return things.reduce((a, thing) => {
67
62
  let newLabel = '';
68
63
  switch (typeof thing) {
69
64
  case 'object': {
70
- label && a.push(label);
71
- let s =
72
- thing &&
65
+ if (thing === null) {
66
+ a.push(label + valueColor + 'null' + endColor);
67
+ } else if (
73
68
  thing.constructor !== Object &&
74
69
  typeof thing.toString === 'function'
75
- ? color + thing.toString() + NO_COLOR
76
- : thing;
77
- a.push(s);
70
+ ) {
71
+ a.push(label + valueColor + thing.toString() + endColor);
72
+ } else {
73
+ label && a.push(label + endColor);
74
+ a.push(thing);
75
+ }
78
76
  break;
79
77
  }
80
78
  case 'string':
81
79
  if (thing.endsWith(':')) {
82
- newLabel = NO_COLOR + thing;
80
+ newLabel = textColor + thing;
81
+ } else if (label) {
82
+ a.push(label + valueColor + thing + endColor);
83
83
  } else {
84
- a.push(label + color + thing + NO_COLOR);
84
+ a.push(textColor + thing + endColor);
85
85
  }
86
86
  break;
87
87
  case 'number': {
@@ -89,30 +89,30 @@ export class ColorConsole {
89
89
  if (thing === Number(v)) {
90
90
  v = v.replace(/\.?0+$/, '');
91
91
  }
92
- a.push(label + GREEN + v + NO_COLOR);
92
+ a.push(label + valueColor + v + endColor);
93
93
  break;
94
94
  }
95
95
  default:
96
- a.push(label + color + JSON.stringify(thing) + NO_COLOR);
96
+ a.push(
97
+ label + valueColor + JSON.stringify(thing) + endColor,
98
+ );
97
99
  break;
98
100
  }
99
101
  label = newLabel;
100
102
  return a;
101
103
  }, []);
102
- }
104
+ } // color
103
105
 
104
106
  fyi(...rest) {
105
107
  return this.fyi2(...rest);
106
108
  }
107
109
 
108
110
  fyi1(...rest) {
109
- let color = this.colorFyi1;
110
- this.write(...this.color(color, ...rest));
111
+ this.write(...this.color(this.fyiColor1, ...rest));
111
112
  }
112
113
 
113
114
  fyi2(...rest) {
114
- let color = this.colorFyi2;
115
- this.write(...this.color(color, ...rest));
115
+ this.write(...this.color(this.fyiColor2, ...rest));
116
116
  }
117
117
 
118
118
  ok(...rest) {
@@ -120,13 +120,11 @@ export class ColorConsole {
120
120
  }
121
121
 
122
122
  ok1(...rest) {
123
- let color = this.colorOk1;
124
- this.write(...this.color(color, ...rest));
123
+ this.write(...this.color(this.okColor1, ...rest));
125
124
  }
126
125
 
127
126
  ok2(...rest) {
128
- let color = this.colorOk2;
129
- this.write(...this.color(color, ...rest));
127
+ this.write(...this.color(this.okColor2, ...rest));
130
128
  }
131
129
 
132
130
  bad(...rest) {
@@ -134,32 +132,11 @@ export class ColorConsole {
134
132
  }
135
133
 
136
134
  bad1(...rest) {
137
- let color = this.colorBad1;
138
- this.write(...this.color(color, ...rest));
135
+ this.write(...this.color(this.badColor1, ...rest));
139
136
  }
140
137
 
141
138
  bad2(...rest) {
142
- let color = this.colorBad2;
143
- this.write(...this.color(color, ...rest));
144
- }
145
-
146
- tag1(...rest) {
147
- let color = this.colorTag1;
148
- this.write(...this.color(color, ...rest));
139
+ this.write(...this.color(this.badColor2, ...rest));
149
140
  }
150
141
 
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));
164
- }
165
142
  }
@@ -220,6 +220,9 @@ export class Unicode {
220
220
  static get IMPLIES() {
221
221
  return '\u21D2';
222
222
  }
223
+ static get EMPTY_SET() {
224
+ return '\u2205';
225
+ }
223
226
  static get ELEMENT_OF() {
224
227
  return '\u2208';
225
228
  }
@@ -355,6 +358,9 @@ export class Unicode {
355
358
  get IMPLIES() {
356
359
  return Unicode.IMPLIES;
357
360
  }
361
+ get EMPTY_SET() {
362
+ return Unicode.EMPTY_SET;
363
+ }
358
364
  get ELEMENT_OF() {
359
365
  return Unicode.ELEMENT_OF;
360
366
  }