@sc-voice/tools 2.14.0 → 2.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": "2.14.0",
3
+ "version": "2.16.0",
4
4
  "description": "Utilities for SC-Voice",
5
5
  "main": "index.mjs",
6
6
  "files": [
@@ -261,6 +261,14 @@ export class Unicode {
261
261
  MAGENTA: '\u001b[35m',
262
262
  CYAN: '\u001b[36m',
263
263
  WHITE: '\u001b[37m',
264
+ BRIGHT_BLACK: '\u001b[90m',
265
+ BRIGHT_RED: '\u001b[91m',
266
+ BRIGHT_GREEN: '\u001b[92m',
267
+ BRIGHT_YELLOW: '\u001b[93m',
268
+ BRIGHT_BLUE: '\u001b[94m',
269
+ BRIGHT_MAGENTA: '\u001b[95m',
270
+ BRIGHT_CYAN: '\u001b[96m',
271
+ BRIGHT_WHITE: '\u001b[97m',
264
272
  NO_COLOR: '\u001b[0m',
265
273
  };
266
274
  }
@@ -21,8 +21,26 @@ export class WordVector extends Object {
21
21
  }
22
22
 
23
23
  toString(opts={}) {
24
- let { precision=2 } = opts;
25
- let sv = Object.entries(this).reduce((a, e) => {
24
+ let { order='value', precision=2 } = opts;
25
+ let entries = Object.entries(this);
26
+ switch (order) {
27
+ case 'key':
28
+ entries.sort((a,b)=>{
29
+ let [ka] = a;
30
+ let [kb] = b;
31
+ return ka.localeCompare(kb);
32
+ });
33
+ break;
34
+ case 'value':
35
+ default:
36
+ entries.sort((a,b)=>{
37
+ let [ka, va] = a;
38
+ let [kb, vb] = b;
39
+ return (vb-va) || ka.localeCompare(kb);
40
+ });
41
+ break;
42
+ }
43
+ let sv = entries.reduce((a, e) => {
26
44
  let [k, v] = e;
27
45
  let vf = v.toFixed(precision).replace(/\.0*$/,'');
28
46
  a.push(`${k}:${vf}`);