@lowentry/utils 1.20.1 → 1.22.1

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.js CHANGED
@@ -8,8 +8,8 @@ import _wrapAsyncGenerator from '@babel/runtime/helpers/wrapAsyncGenerator';
8
8
  import _regeneratorRuntime from '@babel/runtime/regenerator';
9
9
  import FastDeepEqual from 'fast-deep-equal';
10
10
  import CloneDeep from 'clone-deep';
11
- import _createClass from '@babel/runtime/helpers/createClass';
12
11
  import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
12
+ import _createClass from '@babel/runtime/helpers/createClass';
13
13
  import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
14
14
  import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
15
15
  import _inherits from '@babel/runtime/helpers/inherits';
@@ -214,9 +214,9 @@ var FLOAT_LAX_ANY = function FLOAT_LAX_ANY() {
214
214
 
215
215
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
216
216
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
217
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
218
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
219
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
217
+ function _createForOfIteratorHelper$1(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$1(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
218
+ function _unsupportedIterableToArray$1(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$1(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$1(r, a) : void 0; } }
219
+ function _arrayLikeToArray$1(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
220
220
 
221
221
  /**
222
222
  * @param {LeUtils_TransactionalValue} transactionalValue
@@ -704,7 +704,7 @@ var LeUtils = {
704
704
  }
705
705
  if (typeof (elements === null || elements === void 0 ? void 0 : elements[Symbol.iterator]) === 'function') {
706
706
  var i = 0;
707
- var _iterator = _createForOfIteratorHelper(elements),
707
+ var _iterator = _createForOfIteratorHelper$1(elements),
708
708
  _step;
709
709
  try {
710
710
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
@@ -820,7 +820,7 @@ var LeUtils = {
820
820
  _context.next = 17;
821
821
  break;
822
822
  }
823
- _iterator2 = _createForOfIteratorHelper(elements);
823
+ _iterator2 = _createForOfIteratorHelper$1(elements);
824
824
  _context.prev = 10;
825
825
  _iterator2.s();
826
826
  case 11:
@@ -852,7 +852,7 @@ var LeUtils = {
852
852
  _context.next = 25;
853
853
  break;
854
854
  }
855
- _iterator3 = _createForOfIteratorHelper(elements);
855
+ _iterator3 = _createForOfIteratorHelper$1(elements);
856
856
  _context.prev = 18;
857
857
  _iterator3.s();
858
858
  case 19:
@@ -904,7 +904,7 @@ var LeUtils = {
904
904
  break;
905
905
  }
906
906
  _i4 = 0;
907
- _iterator4 = _createForOfIteratorHelper(elements);
907
+ _iterator4 = _createForOfIteratorHelper$1(elements);
908
908
  _context.prev = 30;
909
909
  _iterator4.s();
910
910
  case 31:
@@ -999,7 +999,7 @@ var LeUtils = {
999
999
  */
1000
1000
  each: function each(elements, callback) {
1001
1001
  var optionalSkipHasOwnPropertyCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1002
- var _iterator5 = _createForOfIteratorHelper(LeUtils.eachIterator(elements, optionalSkipHasOwnPropertyCheck)),
1002
+ var _iterator5 = _createForOfIteratorHelper$1(LeUtils.eachIterator(elements, optionalSkipHasOwnPropertyCheck)),
1003
1003
  _step5;
1004
1004
  try {
1005
1005
  for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
@@ -1149,7 +1149,7 @@ var LeUtils = {
1149
1149
  case 1:
1150
1150
  return _context5.abrupt("return", _context5.sent);
1151
1151
  case 2:
1152
- _iterator6 = _createForOfIteratorHelper(LeUtils.eachIterator(elements, optionalSkipHasOwnPropertyCheck));
1152
+ _iterator6 = _createForOfIteratorHelper$1(LeUtils.eachIterator(elements, optionalSkipHasOwnPropertyCheck));
1153
1153
  _context5.prev = 3;
1154
1154
  _iterator6.s();
1155
1155
  case 4:
@@ -1333,7 +1333,7 @@ var LeUtils = {
1333
1333
  var optionalSkipHasOwnPropertyCheck = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1334
1334
  var keys = LeUtils.sortKeys(elements, comparator, optionalSkipHasOwnPropertyCheck);
1335
1335
  var result = [];
1336
- var _iterator7 = _createForOfIteratorHelper(keys),
1336
+ var _iterator7 = _createForOfIteratorHelper$1(keys),
1337
1337
  _step7;
1338
1338
  try {
1339
1339
  for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
@@ -3034,6 +3034,15 @@ var LeUtils = {
3034
3034
  * @returns {boolean}
3035
3035
  */
3036
3036
  isGivenHostPrivate: function isGivenHostPrivate(host) {
3037
+ host = STRING(host).trim();
3038
+ if (!host) {
3039
+ return false;
3040
+ }
3041
+ try {
3042
+ host = new URL(host).hostname;
3043
+ } catch (e) {
3044
+ host = host.split(':')[0];
3045
+ }
3037
3046
  host = STRING(host).trim().toLowerCase();
3038
3047
  if (host === 'localhost' || host === '127.0.0.1') {
3039
3048
  return true;
@@ -3048,178 +3057,6 @@ var LeUtils = {
3048
3057
  // 172.16.0.0 - 172.31.255.255
3049
3058
  parts[0] === '192' && parts[1] === '168'; // 192.168.0.0 - 192.168.255.255
3050
3059
  },
3051
- /**
3052
- * Creates and returns a new TreeSet.
3053
- * A TreeSet is a set of elements, sorted by a comparator.
3054
- * Binary search is used to find elements, which makes it very fast to find elements.
3055
- *
3056
- * The comparator is also used to determine if two values are equal to each other.
3057
- * This way, you can have values that aren't the same be treated as if they are. This can be used to deal with issues such as floating point errors for example.
3058
- *
3059
- * @param {*[]} elements
3060
- * @param {(valueA:*, valueB:*) => number} comparator
3061
- * @returns {{getElements:(()=>*[]), getComparator:(()=>((valueA:*,valueB:*)=>number)), size:(()=>number), isEmpty:(()=>boolean), contains:((value:*)=>boolean), first:(()=>*|undefined), last:(()=>*|undefined), pollFirst:(()=>*|undefined), pollLast:(()=>*|undefined), add:((value:*)=>void), addAll:((values:*)=>void), getEqualValue:((value:*)=>*), getEqualValueOrAdd:((value:*)=>*)}}
3062
- */
3063
- createTreeSet: function createTreeSet(elements, comparator) {
3064
- comparator = comparator || LeUtils.compare;
3065
- elements = elements || [];
3066
- elements.sort(comparator);
3067
-
3068
- /**
3069
- * Performs a binary search on the elements, and returns the result.
3070
- *
3071
- * @param {*} value
3072
- * @returns {{found: boolean, index: number, value: *|undefined}}
3073
- */
3074
- var binarySearch = function binarySearch(value) {
3075
- var low = 0;
3076
- var high = elements.length - 1;
3077
- while (low <= high) {
3078
- var mid = Math.floor((low + high) / 2);
3079
- var midValue = elements[mid];
3080
- var cmp = comparator(midValue, value);
3081
- if (cmp < 0) {
3082
- low = mid + 1;
3083
- } else if (cmp > 0) {
3084
- high = mid - 1;
3085
- } else {
3086
- return {
3087
- found: true,
3088
- index: mid,
3089
- value: midValue
3090
- };
3091
- }
3092
- }
3093
- return {
3094
- found: false,
3095
- index: low,
3096
- value: undefined
3097
- };
3098
- };
3099
- var treeSet = {
3100
- /**
3101
- * Returns the elements of the set.
3102
- *
3103
- * @returns {*[]}
3104
- */
3105
- getElements: function getElements() {
3106
- return elements;
3107
- },
3108
- /**
3109
- * Returns the comparator of the set.
3110
- *
3111
- * @returns {(valueA:*, valueB:*) => number}
3112
- */
3113
- getComparator: function getComparator() {
3114
- return comparator;
3115
- },
3116
- /**
3117
- * Returns the size of the set.
3118
- *
3119
- * @returns {number}
3120
- */
3121
- size: function size() {
3122
- return elements.length;
3123
- },
3124
- /**
3125
- * Returns true if the set is empty, false otherwise.
3126
- *
3127
- * @returns {boolean}
3128
- */
3129
- isEmpty: function isEmpty() {
3130
- return elements.length <= 0;
3131
- },
3132
- /**
3133
- * Returns true if the set contains a value that is equal to the given value, returns false otherwise.
3134
- *
3135
- * @param {*} value
3136
- * @returns {boolean}
3137
- */
3138
- contains: function contains(value) {
3139
- return binarySearch(value).found;
3140
- },
3141
- /**
3142
- * Returns the first element of the set, or undefined if it is empty.
3143
- *
3144
- * @returns {*|undefined}
3145
- */
3146
- first: function first() {
3147
- return elements.length > 0 ? elements[0] : undefined;
3148
- },
3149
- /**
3150
- * Returns the last element of the set, or undefined if it is empty.
3151
- *
3152
- * @returns {*|undefined}
3153
- */
3154
- last: function last() {
3155
- return elements.length > 0 ? elements[elements.length - 1] : undefined;
3156
- },
3157
- /**
3158
- * Removes and returns the first element of the set, or undefined if it is empty.
3159
- *
3160
- * @returns {*|undefined}
3161
- */
3162
- pollFirst: function pollFirst() {
3163
- return elements.length > 0 ? elements.splice(0, 1)[0] : undefined;
3164
- },
3165
- /**
3166
- * Removes and returns the last element of the set, or undefined if it is empty.
3167
- *
3168
- * @returns {*|undefined}
3169
- */
3170
- pollLast: function pollLast() {
3171
- return elements.length > 0 ? elements.splice(elements.length - 1, 1)[0] : undefined;
3172
- },
3173
- /**
3174
- * Adds the given value to the set. Will only do so if no equal value already exists.
3175
- *
3176
- * @param {*} value
3177
- */
3178
- add: function add(value) {
3179
- var result = binarySearch(value);
3180
- if (result.found) {
3181
- return;
3182
- }
3183
- elements.splice(result.index, 0, value);
3184
- },
3185
- /**
3186
- * Adds all the given values to the set. Will only do so if no equal value already exists.
3187
- *
3188
- * @param {*} values
3189
- */
3190
- addAll: function addAll(values) {
3191
- LeUtils.each(values, treeSet.add);
3192
- },
3193
- /**
3194
- * Returns an equal value that's already in the tree set, or undefined if no equal values in it exist.
3195
- *
3196
- * @param {*} value
3197
- * @returns {*|undefined}
3198
- */
3199
- getEqualValue: function getEqualValue(value) {
3200
- var result = binarySearch(value);
3201
- if (result.found) {
3202
- return result.value;
3203
- }
3204
- return undefined;
3205
- },
3206
- /**
3207
- * Returns an equal value that's already in the tree set. If no equal values in it exist, the given value will be added and returned.
3208
- *
3209
- * @param {*} value
3210
- * @returns {*}
3211
- */
3212
- getEqualValueOrAdd: function getEqualValueOrAdd(value) {
3213
- var result = binarySearch(value);
3214
- if (result.found) {
3215
- return result.value;
3216
- }
3217
- elements.splice(result.index, 0, value);
3218
- return value;
3219
- }
3220
- };
3221
- return treeSet;
3222
- },
3223
3060
  /**
3224
3061
  * @typedef {Object} LeUtils_TransactionalValue
3225
3062
  * @property {*} value
@@ -3588,11 +3425,149 @@ var LeUtils = {
3588
3425
  }()
3589
3426
  };
3590
3427
 
3591
- function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
3592
- function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
3593
- function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
3594
- function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
3595
- function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
3428
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
3429
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
3430
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
3431
+ function _classPrivateFieldInitSpec$2(e, t, a) { _checkPrivateRedeclaration$2(e, t), t.set(e, a); }
3432
+ function _checkPrivateRedeclaration$2(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
3433
+ function _classPrivateFieldGet$2(s, a) { return s.get(_assertClassBrand$2(s, a)); }
3434
+ function _classPrivateFieldSet$2(s, a, r) { return s.set(_assertClassBrand$2(s, a), r), r; }
3435
+ function _assertClassBrand$2(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
3436
+ var _events = /*#__PURE__*/new WeakMap();
3437
+ /**
3438
+ * A simple event emitter class that allows you to register listeners for events, emit events, and remove listeners.
3439
+ */
3440
+ var EventEmitter = /*#__PURE__*/function () {
3441
+ /**
3442
+ * Creates a new EventEmitter instance.
3443
+ */
3444
+ function EventEmitter() {
3445
+ _classCallCheck(this, EventEmitter);
3446
+ /** @type {Map<string, Set<Function>>} */
3447
+ _classPrivateFieldInitSpec$2(this, _events, void 0);
3448
+ _classPrivateFieldSet$2(_events, this, new Map());
3449
+ }
3450
+
3451
+ /**
3452
+ * Registers a listener for a specific event.
3453
+ *
3454
+ * @param {string} event - The name of the event to listen for.
3455
+ * @param {Function} listener - The function to call when the event is emitted.
3456
+ * @returns {{remove:(()=>void)}}
3457
+ */
3458
+ return _createClass(EventEmitter, [{
3459
+ key: "on",
3460
+ value: function on(event, listener) {
3461
+ var _classPrivateFieldGet2,
3462
+ _this = this;
3463
+ if (!_classPrivateFieldGet$2(_events, this).has(event)) {
3464
+ _classPrivateFieldGet$2(_events, this).set(event, new Set());
3465
+ }
3466
+ (_classPrivateFieldGet2 = _classPrivateFieldGet$2(_events, this).get(event)) === null || _classPrivateFieldGet2 === void 0 || _classPrivateFieldGet2.add(listener);
3467
+ return {
3468
+ remove: function remove() {
3469
+ return _this.off(event, listener);
3470
+ }
3471
+ };
3472
+ }
3473
+
3474
+ /**
3475
+ * Registers a listener for a specific event, this listener will be called only once.
3476
+ *
3477
+ * @param {string} event - The name of the event to listen for.
3478
+ * @param {Function} listener - The function to call when the event is emitted.
3479
+ * @returns {{remove:()=>void}}
3480
+ */
3481
+ }, {
3482
+ key: "once",
3483
+ value: function once(event, listener) {
3484
+ var _this2 = this;
3485
+ var _wrapper = function wrapper() {
3486
+ _this2.off(event, _wrapper);
3487
+ listener.apply(void 0, arguments);
3488
+ };
3489
+ this.on(event, _wrapper);
3490
+ return {
3491
+ remove: function remove() {
3492
+ return _this2.off(event, _wrapper);
3493
+ }
3494
+ };
3495
+ }
3496
+
3497
+ /**
3498
+ * Removes a listener for a specific event.
3499
+ *
3500
+ * @param {string} event - The name of the event to stop listening for.
3501
+ * @param {Function} listener - The function to remove from the event listeners.
3502
+ */
3503
+ }, {
3504
+ key: "off",
3505
+ value: function off(event, listener) {
3506
+ var listeners = _classPrivateFieldGet$2(_events, this).get(event);
3507
+ if (listeners) {
3508
+ listeners["delete"](listener);
3509
+ if (listeners.size === 0) {
3510
+ _classPrivateFieldGet$2(_events, this)["delete"](event);
3511
+ }
3512
+ }
3513
+ }
3514
+
3515
+ /**
3516
+ * Emits an event, calling all registered listeners with the provided arguments.
3517
+ *
3518
+ * @param {string} event - The name of the event to emit.
3519
+ * @param {...*} args - The arguments to pass to the listeners.
3520
+ */
3521
+ }, {
3522
+ key: "emit",
3523
+ value: function emit(event) {
3524
+ var listeners = _classPrivateFieldGet$2(_events, this).get(event);
3525
+ if (listeners) {
3526
+ var snapshot = _toConsumableArray(listeners);
3527
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
3528
+ args[_key - 1] = arguments[_key];
3529
+ }
3530
+ var _iterator = _createForOfIteratorHelper(snapshot),
3531
+ _step;
3532
+ try {
3533
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
3534
+ var listener = _step.value;
3535
+ try {
3536
+ listener.apply(void 0, args);
3537
+ } catch (err) {
3538
+ console.error("Error in listener for \"".concat(event, "\":"), err);
3539
+ }
3540
+ }
3541
+ } catch (err) {
3542
+ _iterator.e(err);
3543
+ } finally {
3544
+ _iterator.f();
3545
+ }
3546
+ }
3547
+ }
3548
+
3549
+ /**
3550
+ * Clears all listeners for a specific event or all events if no event is specified.
3551
+ *
3552
+ * @param {string} [event] - The name of the event to clear listeners for. If not provided, all events will be cleared.
3553
+ */
3554
+ }, {
3555
+ key: "clear",
3556
+ value: function clear(event) {
3557
+ if (event !== undefined) {
3558
+ _classPrivateFieldGet$2(_events, this)["delete"](event);
3559
+ } else {
3560
+ _classPrivateFieldGet$2(_events, this).clear();
3561
+ }
3562
+ }
3563
+ }]);
3564
+ }();
3565
+
3566
+ function _classPrivateFieldInitSpec$1(e, t, a) { _checkPrivateRedeclaration$1(e, t), t.set(e, a); }
3567
+ function _checkPrivateRedeclaration$1(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
3568
+ function _classPrivateFieldSet$1(s, a, r) { return s.set(_assertClassBrand$1(s, a), r), r; }
3569
+ function _classPrivateFieldGet$1(s, a) { return s.get(_assertClassBrand$1(s, a)); }
3570
+ function _assertClassBrand$1(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
3596
3571
  var LinkedListNode = /*#__PURE__*/_createClass(
3597
3572
  /**
3598
3573
  * @param {*} value
@@ -3614,11 +3589,11 @@ var LinkedList = /*#__PURE__*/function () {
3614
3589
  function LinkedList() {
3615
3590
  _classCallCheck(this, LinkedList);
3616
3591
  /** @type {LinkedListNode|null} */
3617
- _classPrivateFieldInitSpec(this, _head, null);
3592
+ _classPrivateFieldInitSpec$1(this, _head, null);
3618
3593
  /** @type {LinkedListNode|null} */
3619
- _classPrivateFieldInitSpec(this, _tail, null);
3594
+ _classPrivateFieldInitSpec$1(this, _tail, null);
3620
3595
  /** @type {number} */
3621
- _classPrivateFieldInitSpec(this, _size, 0);
3596
+ _classPrivateFieldInitSpec$1(this, _size, 0);
3622
3597
  }
3623
3598
 
3624
3599
  /**
@@ -3629,7 +3604,7 @@ var LinkedList = /*#__PURE__*/function () {
3629
3604
  return _createClass(LinkedList, [{
3630
3605
  key: "size",
3631
3606
  get: function get() {
3632
- return _classPrivateFieldGet(_size, this);
3607
+ return _classPrivateFieldGet$1(_size, this);
3633
3608
  }
3634
3609
 
3635
3610
  /**
@@ -3642,15 +3617,15 @@ var LinkedList = /*#__PURE__*/function () {
3642
3617
  value: function unshift(value) {
3643
3618
  var _this$size;
3644
3619
  var newNode = new LinkedListNode(value);
3645
- if (_classPrivateFieldGet(_head, this) === null) {
3646
- _classPrivateFieldSet(_head, this, newNode);
3647
- _classPrivateFieldSet(_tail, this, newNode);
3620
+ if (_classPrivateFieldGet$1(_head, this) === null) {
3621
+ _classPrivateFieldSet$1(_head, this, newNode);
3622
+ _classPrivateFieldSet$1(_tail, this, newNode);
3648
3623
  } else {
3649
- newNode.next = _classPrivateFieldGet(_head, this);
3650
- _classPrivateFieldGet(_head, this).previous = newNode;
3651
- _classPrivateFieldSet(_head, this, newNode);
3624
+ newNode.next = _classPrivateFieldGet$1(_head, this);
3625
+ _classPrivateFieldGet$1(_head, this).previous = newNode;
3626
+ _classPrivateFieldSet$1(_head, this, newNode);
3652
3627
  }
3653
- _classPrivateFieldSet(_size, this, (_this$size = _classPrivateFieldGet(_size, this), _this$size++, _this$size));
3628
+ _classPrivateFieldSet$1(_size, this, (_this$size = _classPrivateFieldGet$1(_size, this), _this$size++, _this$size));
3654
3629
  }
3655
3630
 
3656
3631
  /**
@@ -3663,15 +3638,15 @@ var LinkedList = /*#__PURE__*/function () {
3663
3638
  value: function push(value) {
3664
3639
  var _this$size3;
3665
3640
  var newNode = new LinkedListNode(value);
3666
- if (_classPrivateFieldGet(_tail, this) === null) {
3667
- _classPrivateFieldSet(_head, this, newNode);
3668
- _classPrivateFieldSet(_tail, this, newNode);
3641
+ if (_classPrivateFieldGet$1(_tail, this) === null) {
3642
+ _classPrivateFieldSet$1(_head, this, newNode);
3643
+ _classPrivateFieldSet$1(_tail, this, newNode);
3669
3644
  } else {
3670
- newNode.previous = _classPrivateFieldGet(_tail, this);
3671
- _classPrivateFieldGet(_tail, this).next = newNode;
3672
- _classPrivateFieldSet(_tail, this, newNode);
3645
+ newNode.previous = _classPrivateFieldGet$1(_tail, this);
3646
+ _classPrivateFieldGet$1(_tail, this).next = newNode;
3647
+ _classPrivateFieldSet$1(_tail, this, newNode);
3673
3648
  }
3674
- _classPrivateFieldSet(_size, this, (_this$size3 = _classPrivateFieldGet(_size, this), _this$size3++, _this$size3));
3649
+ _classPrivateFieldSet$1(_size, this, (_this$size3 = _classPrivateFieldGet$1(_size, this), _this$size3++, _this$size3));
3675
3650
  }
3676
3651
 
3677
3652
  /**
@@ -3683,17 +3658,17 @@ var LinkedList = /*#__PURE__*/function () {
3683
3658
  key: "shift",
3684
3659
  value: function shift() {
3685
3660
  var _this$size5;
3686
- if (_classPrivateFieldGet(_head, this) === null) {
3661
+ if (_classPrivateFieldGet$1(_head, this) === null) {
3687
3662
  return undefined;
3688
3663
  }
3689
- var value = _classPrivateFieldGet(_head, this).value;
3690
- _classPrivateFieldSet(_head, this, _classPrivateFieldGet(_head, this).next);
3691
- if (_classPrivateFieldGet(_head, this) !== null) {
3692
- _classPrivateFieldGet(_head, this).previous = null;
3664
+ var value = _classPrivateFieldGet$1(_head, this).value;
3665
+ _classPrivateFieldSet$1(_head, this, _classPrivateFieldGet$1(_head, this).next);
3666
+ if (_classPrivateFieldGet$1(_head, this) !== null) {
3667
+ _classPrivateFieldGet$1(_head, this).previous = null;
3693
3668
  } else {
3694
- _classPrivateFieldSet(_tail, this, null);
3669
+ _classPrivateFieldSet$1(_tail, this, null);
3695
3670
  }
3696
- _classPrivateFieldSet(_size, this, (_this$size5 = _classPrivateFieldGet(_size, this), _this$size5--, _this$size5));
3671
+ _classPrivateFieldSet$1(_size, this, (_this$size5 = _classPrivateFieldGet$1(_size, this), _this$size5--, _this$size5));
3697
3672
  return value;
3698
3673
  }
3699
3674
 
@@ -3706,17 +3681,17 @@ var LinkedList = /*#__PURE__*/function () {
3706
3681
  key: "pop",
3707
3682
  value: function pop() {
3708
3683
  var _this$size7;
3709
- if (_classPrivateFieldGet(_tail, this) === null) {
3684
+ if (_classPrivateFieldGet$1(_tail, this) === null) {
3710
3685
  return undefined;
3711
3686
  }
3712
- var value = _classPrivateFieldGet(_tail, this).value;
3713
- _classPrivateFieldSet(_tail, this, _classPrivateFieldGet(_tail, this).previous);
3714
- if (_classPrivateFieldGet(_tail, this) !== null) {
3715
- _classPrivateFieldGet(_tail, this).next = null;
3687
+ var value = _classPrivateFieldGet$1(_tail, this).value;
3688
+ _classPrivateFieldSet$1(_tail, this, _classPrivateFieldGet$1(_tail, this).previous);
3689
+ if (_classPrivateFieldGet$1(_tail, this) !== null) {
3690
+ _classPrivateFieldGet$1(_tail, this).next = null;
3716
3691
  } else {
3717
- _classPrivateFieldSet(_head, this, null);
3692
+ _classPrivateFieldSet$1(_head, this, null);
3718
3693
  }
3719
- _classPrivateFieldSet(_size, this, (_this$size7 = _classPrivateFieldGet(_size, this), _this$size7--, _this$size7));
3694
+ _classPrivateFieldSet$1(_size, this, (_this$size7 = _classPrivateFieldGet$1(_size, this), _this$size7--, _this$size7));
3720
3695
  return value;
3721
3696
  }
3722
3697
  }]);
@@ -3749,5 +3724,256 @@ var SerializableMap = /*#__PURE__*/function (_Map) {
3749
3724
  }]);
3750
3725
  }(/*#__PURE__*/_wrapNativeSuper(Map));
3751
3726
 
3752
- export { ARRAY, FLOAT, FLOAT_ANY, FLOAT_LAX, FLOAT_LAX_ANY, INT, INT_ANY, INT_LAX, INT_LAX_ANY, ISSET, IS_ARRAY, IS_OBJECT, LeUtils, LinkedList, OBJECT, STRING, STRING_ANY, SerializableMap };
3727
+ function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
3728
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
3729
+ function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
3730
+ function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
3731
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
3732
+
3733
+ /**
3734
+ * A TreeSet is a set of elements, sorted by a comparator.
3735
+ * Binary search is used to find elements, which makes it very fast to find elements.
3736
+ *
3737
+ * The comparator is also used to determine if two values are equal to each other.
3738
+ * This way, you can have values that aren't the same be treated as if they are. This can be used to deal with issues such as floating point errors for example.
3739
+ */
3740
+ var _elements = /*#__PURE__*/new WeakMap();
3741
+ var _comparator = /*#__PURE__*/new WeakMap();
3742
+ var TreeSet = /*#__PURE__*/function () {
3743
+ /**
3744
+ * Creates a new TreeSet with the given elements and comparator.
3745
+ *
3746
+ * @param {*[]} [elements=[]] - The initial elements of the set.
3747
+ * @param {(valueA:*, valueB:*) => number} [comparator=LeUtils.compare] - The comparator function to use for sorting.
3748
+ */
3749
+ function TreeSet(elements, comparator) {
3750
+ _classCallCheck(this, TreeSet);
3751
+ /** @type {*[]} */
3752
+ _classPrivateFieldInitSpec(this, _elements, void 0);
3753
+ /** @type {(valueA:*, valueB:*) => number} */
3754
+ _classPrivateFieldInitSpec(this, _comparator, void 0);
3755
+ _classPrivateFieldSet(_comparator, this, comparator || LeUtils.compare);
3756
+ _classPrivateFieldSet(_elements, this, elements || []);
3757
+ _classPrivateFieldGet(_elements, this).sort(_classPrivateFieldGet(_comparator, this));
3758
+ }
3759
+
3760
+ /**
3761
+ *
3762
+ *
3763
+ * @param {*} value - The value to search for in the set.
3764
+ * @returns {{found:boolean, index:number, value:*|undefined}} - An object containing whether the value was found, the index where it would be inserted, and the value at that index (if found).
3765
+ * @private
3766
+ */
3767
+ return _createClass(TreeSet, [{
3768
+ key: "binarySearch",
3769
+ value: function binarySearch(value) {
3770
+ var low = 0;
3771
+ var high = _classPrivateFieldGet(_elements, this).length - 1;
3772
+ while (low <= high) {
3773
+ var mid = Math.floor((low + high) / 2);
3774
+ var midValue = _classPrivateFieldGet(_elements, this)[mid];
3775
+ var cmp = _classPrivateFieldGet(_comparator, this).call(this, midValue, value);
3776
+ if (cmp < 0) {
3777
+ low = mid + 1;
3778
+ } else if (cmp > 0) {
3779
+ high = mid - 1;
3780
+ } else {
3781
+ return {
3782
+ found: true,
3783
+ index: mid,
3784
+ value: midValue
3785
+ };
3786
+ }
3787
+ }
3788
+ return {
3789
+ found: false,
3790
+ index: low,
3791
+ value: undefined
3792
+ };
3793
+ }
3794
+ }, {
3795
+ key: "getElements",
3796
+ value:
3797
+ /**
3798
+ * Returns the elements of the set.
3799
+ */
3800
+ function getElements() {
3801
+ return _classPrivateFieldGet(_elements, this);
3802
+ }
3803
+
3804
+ /**
3805
+ * Returns the comparator of the set.
3806
+ *
3807
+ * @returns {(valueA:*, valueB:*) => number}
3808
+ */
3809
+ }, {
3810
+ key: "getComparator",
3811
+ value: function getComparator() {
3812
+ return _classPrivateFieldGet(_comparator, this);
3813
+ }
3814
+
3815
+ /**
3816
+ * Returns the size of the set.
3817
+ *
3818
+ * @returns {number}
3819
+ */
3820
+ }, {
3821
+ key: "size",
3822
+ value: function size() {
3823
+ return _classPrivateFieldGet(_elements, this).length;
3824
+ }
3825
+
3826
+ /**
3827
+ * Returns true if the set is empty, false otherwise.
3828
+ *
3829
+ * @returns {boolean}
3830
+ */
3831
+ }, {
3832
+ key: "isEmpty",
3833
+ value: function isEmpty() {
3834
+ return _classPrivateFieldGet(_elements, this).length <= 0;
3835
+ }
3836
+
3837
+ /**
3838
+ * Returns true if the set contains a value that is equal to the given value, returns false otherwise.
3839
+ *
3840
+ * @param {*} value - The value to check for in the set.
3841
+ * @return {boolean} - True if the set contains the value, false otherwise.
3842
+ */
3843
+ }, {
3844
+ key: "contains",
3845
+ value: function contains(value) {
3846
+ return this.binarySearch(value).found;
3847
+ }
3848
+
3849
+ /**
3850
+ * Returns the first element of the set, or undefined if it is empty.
3851
+ *
3852
+ * @return {*|undefined} - The first element of the set, or undefined if it is empty.
3853
+ */
3854
+ }, {
3855
+ key: "first",
3856
+ value: function first() {
3857
+ return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this)[0] : undefined;
3858
+ }
3859
+
3860
+ /**
3861
+ * Returns the last element of the set, or undefined if it is empty.
3862
+ *
3863
+ * @return {*|undefined} - The last element of the set, or undefined if it is empty.
3864
+ */
3865
+ }, {
3866
+ key: "last",
3867
+ value: function last() {
3868
+ return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this)[_classPrivateFieldGet(_elements, this).length - 1] : undefined;
3869
+ }
3870
+
3871
+ /**
3872
+ * Removes and returns the first element of the set, or undefined if it is empty.
3873
+ *
3874
+ * @returns {*|undefined} - The first element of the set, or undefined if it is empty.
3875
+ */
3876
+ }, {
3877
+ key: "pollFirst",
3878
+ value: function pollFirst() {
3879
+ return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this).splice(0, 1)[0] : undefined;
3880
+ }
3881
+
3882
+ /**
3883
+ * Removes and returns the last element of the set, or undefined if it is empty.
3884
+ *
3885
+ * @returns {*|undefined} - The last element of the set, or undefined if it is empty.
3886
+ */
3887
+ }, {
3888
+ key: "pollLast",
3889
+ value: function pollLast() {
3890
+ return _classPrivateFieldGet(_elements, this).length > 0 ? _classPrivateFieldGet(_elements, this).splice(_classPrivateFieldGet(_elements, this).length - 1, 1)[0] : undefined;
3891
+ }
3892
+
3893
+ /**
3894
+ * Adds the given value to the set. Will only do so if no equal value already exists.
3895
+ * @param {*} value - The value to add to the set.
3896
+ */
3897
+ }, {
3898
+ key: "add",
3899
+ value: function add(value) {
3900
+ var result = this.binarySearch(value);
3901
+ if (result.found) {
3902
+ return;
3903
+ }
3904
+ _classPrivateFieldGet(_elements, this).splice(result.index, 0, value);
3905
+ }
3906
+
3907
+ /**
3908
+ * Adds all the given values to the set. Will only do so if no equal value already exists.
3909
+ *
3910
+ * @param {*} values - The values to add to the set.
3911
+ */
3912
+ }, {
3913
+ key: "addAll",
3914
+ value: function addAll(values) {
3915
+ LeUtils.each(values, this.add.bind(this));
3916
+ }
3917
+
3918
+ /**
3919
+ * Returns an equal value that's already in the tree set, or undefined if no equal values in it exist.
3920
+ *
3921
+ * @param {*} value - The value to search for in the set.
3922
+ * @return {*|undefined} - The equal value if found, or undefined if not found.
3923
+ */
3924
+ }, {
3925
+ key: "getEqualValue",
3926
+ value: function getEqualValue(value) {
3927
+ var result = this.binarySearch(value);
3928
+ if (result.found) {
3929
+ return result.value;
3930
+ }
3931
+ return undefined;
3932
+ }
3933
+
3934
+ /**
3935
+ * Returns an equal value that's already in the tree set. If no equal values in it exist, the given value will be added and returned.
3936
+ *
3937
+ * @param {*} value - The value to search for in the set.
3938
+ * @return {*} - The equal value if found, or the added value if not found.
3939
+ */
3940
+ }, {
3941
+ key: "getEqualValueOrAdd",
3942
+ value: function getEqualValueOrAdd(value) {
3943
+ var result = this.binarySearch(value);
3944
+ if (result.found) {
3945
+ return result.value;
3946
+ }
3947
+ _classPrivateFieldGet(_elements, this).splice(result.index, 0, value);
3948
+ return value;
3949
+ }
3950
+
3951
+ /**
3952
+ * Returns a string representation of the TreeSet.
3953
+ *
3954
+ * @returns {string} - A string representation of the TreeSet, including its elements and comparator.
3955
+ */
3956
+ }, {
3957
+ key: "toString",
3958
+ value: function toString() {
3959
+ return "TreeSet{elements:".concat(_classPrivateFieldGet(_elements, this), ", comparator:").concat(_classPrivateFieldGet(_comparator, this), "}");
3960
+ }
3961
+
3962
+ /**
3963
+ * Returns a JSON representation of the TreeSet.
3964
+ *
3965
+ * @returns {Object} - An object containing the elements and comparator of the TreeSet.
3966
+ */
3967
+ }, {
3968
+ key: "toJSON",
3969
+ value: function toJSON() {
3970
+ return {
3971
+ elements: _classPrivateFieldGet(_elements, this),
3972
+ comparator: _classPrivateFieldGet(_comparator, this).toString()
3973
+ };
3974
+ }
3975
+ }]);
3976
+ }();
3977
+
3978
+ export { ARRAY, EventEmitter, FLOAT, FLOAT_ANY, FLOAT_LAX, FLOAT_LAX_ANY, INT, INT_ANY, INT_LAX, INT_LAX_ANY, ISSET, IS_ARRAY, IS_OBJECT, LeUtils, LinkedList, OBJECT, STRING, STRING_ANY, SerializableMap, TreeSet };
3753
3979
  //# sourceMappingURL=index.js.map