@woosh/meep-engine 2.84.5 → 2.84.6

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/build/meep.cjs CHANGED
@@ -61271,7 +61271,7 @@ class List {
61271
61271
  this.data.push(el);
61272
61272
  const oldLength = this.length;
61273
61273
 
61274
- this.length++;
61274
+ this.length = oldLength + 1;
61275
61275
 
61276
61276
  this.on.added.send2(el, oldLength);
61277
61277
  return this;
@@ -96086,40 +96086,38 @@ LinearValue.prototype.fromJSON = function (json) {
96086
96086
 
96087
96087
  /**
96088
96088
  *
96089
- * @param {number} x
96090
- * @param {string} [separator=',']
96089
+ * @param {string} string
96090
+ * @param {string} trailing_sequence
96091
96091
  * @returns {string}
96092
96092
  */
96093
- function number_format_by_thousands(x, separator = ',') {
96093
+ function string_strip_trailing(string, trailing_sequence) {
96094
+ const trailing_sequence_length = trailing_sequence.length;
96094
96095
 
96095
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
96096
+ if (trailing_sequence_length <= 0) {
96097
+ // special case to avoid infinite looping
96098
+ return string;
96099
+ }
96100
+
96101
+ let end_index = string.length;
96102
+
96103
+ while (string.substring(end_index - trailing_sequence_length, end_index) === trailing_sequence) {
96104
+ end_index -= trailing_sequence_length;
96105
+ }
96106
+
96107
+ return string.substring(0, end_index);
96096
96108
  }
96097
96109
 
96098
96110
  /**
96099
96111
  *
96100
- * @param {string} value
96101
- * @returns {number}
96112
+ * @param {number} x
96113
+ * @param {string} [separator=',']
96114
+ * @returns {string}
96102
96115
  */
96103
- function countDecimals(value) {
96104
- if (value % 1 === 0) {
96105
- //whole number
96106
- return 0;
96107
- }
96108
- const s = value.toString();
96109
- const index = s.indexOf('.');
96110
-
96111
- if (index === -1) {
96112
- return 0;
96113
- }
96114
-
96115
- //find last 0
96116
- let endIndex = s.length - 1;
96117
- for (; endIndex > index && s.charAt(endIndex) === "0"; endIndex--) {
96118
-
96119
- }
96120
- return endIndex - index;
96121
- }
96116
+ function number_format_by_thousands(x, separator = ',') {
96122
96117
 
96118
+ return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
96119
+ }
96120
+
96123
96121
  /**
96124
96122
  *
96125
96123
  * @param {number} value
@@ -96130,10 +96128,12 @@ function number_pretty_print(value) {
96130
96128
  const MAX_DECIMALS = 2;
96131
96129
 
96132
96130
  const fraction = value % 1;
96133
- if (fraction !== 0 && Math.abs(value) < 100) {
96134
- const decimals = countDecimals(value.toFixed(MAX_DECIMALS));
96135
- const decimalsToPrint = Math.min(decimals, MAX_DECIMALS);
96136
- return value.toFixed(decimalsToPrint);
96131
+
96132
+ const would_produce_decimals = fraction * Math.pow(10, MAX_DECIMALS) > 0;
96133
+
96134
+ if (would_produce_decimals && Math.abs(value) < 100) {
96135
+ const truncated = value.toFixed(MAX_DECIMALS);
96136
+ return string_strip_trailing(truncated, "0");
96137
96137
  } else {
96138
96138
  //no fraction
96139
96139
  return number_format_by_thousands(value - fraction, ",");