@sc-voice/tools 3.11.0 → 3.13.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
@@ -1,3 +1,7 @@
1
+ import { Assert } from './src/js/assert.mjs';
2
+ export const JS = {
3
+ Assert,
4
+ }
1
5
 
2
6
  import { Fraction } from './src/math/fraction.mjs';
3
7
  import { Interval } from './src/math/interval.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sc-voice/tools",
3
- "version": "3.11.0",
3
+ "version": "3.13.0",
4
4
  "description": "Utilities for SC-Voice",
5
5
  "main": "index.mjs",
6
6
  "files": [
@@ -0,0 +1,8 @@
1
+ export class Assert {
2
+ static ok(expr, msg) {
3
+ if (!expr) {
4
+ throw new Error(msg || 'Unknown assertion error');
5
+ }
6
+ return expr;
7
+ }
8
+ }
@@ -73,6 +73,10 @@ export class Interval {
73
73
  return this.hi === INFINITY ? PLUS_INFINITY : this.hi;
74
74
  }
75
75
 
76
+ get degenerate() {
77
+ return this.hi === this.lo;
78
+ }
79
+
76
80
  contains(num) {
77
81
  if (typeof num !== 'number' || Number.isNaN(num)) {
78
82
  return false;
@@ -62,9 +62,13 @@ export class ColorConsole {
62
62
  let newLabel = '';
63
63
  switch (typeof thing) {
64
64
  case 'object':
65
- // TODO: pretty objects like console
66
65
  label && a.push(label);
67
- a.push(thing);
66
+ let s = thing &&
67
+ (thing.constructor !== Object) &&
68
+ (typeof thing.toString) === 'function'
69
+ ? color+thing.toString()+NO_COLOR
70
+ : thing;
71
+ a.push(s);
68
72
  break;
69
73
  case 'string':
70
74
  if (thing.endsWith(':')) {