@sc-voice/tools 3.17.0 → 3.19.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/index.mjs CHANGED
@@ -12,6 +12,7 @@ export const ScvMath = {
12
12
  };
13
13
 
14
14
  import { BilaraPath } from './src/text/bilara-path.mjs';
15
+ import { Column } from './src/text/column.mjs';
15
16
  import { Corpus } from './src/text/corpus.mjs';
16
17
  import { EbtDoc } from './src/text/ebt-doc.mjs';
17
18
  import { LegacyDoc } from './src/text/legacy-doc.mjs';
@@ -27,6 +28,7 @@ import { ColorConsole} from './src/text/color-console.mjs';
27
28
  export const Text = {
28
29
  BilaraPath,
29
30
  ColorConsole,
31
+ Column,
30
32
  Corpus,
31
33
  EbtDoc,
32
34
  LegacyDoc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sc-voice/tools",
3
- "version": "3.17.0",
3
+ "version": "3.19.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
+ C4N_TO_STRING: 0,
4
5
  COLOR_CONSOLE: 0,
5
6
  I6L_CONTAINS: 0,
6
7
  I6L_OVERLAPS: 0,
@@ -62,9 +62,11 @@ export class ColorConsole {
62
62
  const msg = 'c10e.valueOf';
63
63
  let { precision } = this;
64
64
  switch (typeof thing) {
65
+ case 'undefined':
66
+ return 'undefined';
65
67
  case 'object': {
66
- if (thing === null) {
67
- return 'null';
68
+ if (thing == null) {
69
+ return '' + thing;
68
70
  }
69
71
  if (thing instanceof Date) {
70
72
  return this.dateFormat.format(thing);
@@ -101,7 +103,7 @@ export class ColorConsole {
101
103
  switch (typeof thing) {
102
104
  case 'object': {
103
105
  if (
104
- thing === null ||
106
+ thing == null ||
105
107
  (thing.constructor !== Object &&
106
108
  typeof thing.toString === 'function')
107
109
  ) {
@@ -0,0 +1,142 @@
1
+ import { ColorConsole } from './color-console.mjs';
2
+ const { cc } = ColorConsole;
3
+
4
+ export class Column {
5
+ static instances = 0;
6
+ constructor(opts = {}) {
7
+ let { name, rows = [], separator = ',' } = opts;
8
+
9
+ Column.instances++;
10
+ if (name == null) {
11
+ name = 'column' + Column.instances;
12
+ }
13
+
14
+ Object.assign(this, {
15
+ name,
16
+ rows,
17
+ separator,
18
+ });
19
+ }
20
+
21
+ static fromWrappedList(list, opts = {}) {
22
+ const msg = 'c4n.fromWrappedList';
23
+ const dbg = 0;
24
+ let {
25
+ name = 'columns',
26
+ nColumns = 2,
27
+ namePrefix = 'column',
28
+ order = 'row-major',
29
+ separator,
30
+ } = opts;
31
+
32
+ let singleColumn = new Column({ name, separator });
33
+ switch (order) {
34
+ case 'col-major':
35
+ case 'column-major':
36
+ {
37
+ let transpose = [];
38
+ let col;
39
+ let nRows = Math.ceil(list.length / nColumns);
40
+ dbg && cc.fyi1(msg + 0.1, { nRows });
41
+ for (let i = 0; i < list.length; i++) {
42
+ let ir = i % nRows;
43
+ let ic = Math.floor(i / nRows) * nRows;
44
+ let iList = ir + ic;
45
+ if (ir === 0) {
46
+ if (col) {
47
+ transpose.push(col);
48
+ }
49
+ col = [];
50
+ }
51
+ col.push(list[iList]);
52
+ }
53
+ if (col?.length) {
54
+ transpose.push(col);
55
+ }
56
+ let row;
57
+ for (let i = 0; i < nRows * nColumns; i++) {
58
+ let ic = i % nColumns;
59
+ if (ic === 0) {
60
+ if (row) {
61
+ singleColumn.push(row);
62
+ }
63
+ row = [];
64
+ }
65
+ let ir = Math.floor(i / nColumns);
66
+ dbg && cc.fyi1(msg + 0.1, { ic, ir });
67
+ let vc = transpose[ic];
68
+ if (vc !== undefined) {
69
+ let vr = vc[ir];
70
+ vr && row.push(vc[ir]);
71
+ }
72
+ }
73
+ if (row?.length) {
74
+ singleColumn.push(row);
75
+ }
76
+ }
77
+ break;
78
+ case 'row-major':
79
+ default:
80
+ {
81
+ let row;
82
+ for (let i = 0; i < list.length; i++) {
83
+ let ic = i % nColumns;
84
+ if (ic === 0) {
85
+ if (row) {
86
+ singleColumn.push(row);
87
+ }
88
+ row = [];
89
+ }
90
+ row.push(list[i]);
91
+ }
92
+ if (row?.length) {
93
+ singleColumn.push(row);
94
+ }
95
+ }
96
+ break;
97
+ }
98
+
99
+ return singleColumn;
100
+ }
101
+
102
+ toStrings(opts = {}) {
103
+ let s5s = [];
104
+ let { showName = false } = opts;
105
+ let { name, rows } = this;
106
+
107
+ if (showName) {
108
+ s5s.push(name);
109
+ }
110
+ for (let i = 0; i < rows.length; i++) {
111
+ let v = rows[i];
112
+ switch (typeof v) {
113
+ case 'object':
114
+ if (
115
+ v?.constructor !== Object &&
116
+ typeof v?.toString === 'function'
117
+ ) {
118
+ s5s.push(v.toString());
119
+ } else {
120
+ s5s.push(JSON.stringify(v));
121
+ }
122
+ break;
123
+ default:
124
+ s5s.push('' + v);
125
+ break;
126
+ }
127
+ }
128
+
129
+ return s5s;
130
+ }
131
+
132
+ push(...args) {
133
+ for (let i = 0; i < args.length; i++) {
134
+ this.rows.push(args[i]);
135
+ }
136
+ }
137
+
138
+ toString() {
139
+ let { rows, separator } = this;
140
+ return rows.join(separator);
141
+ }
142
+ }