@lowentry/utils 1.19.4 → 1.21.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.
@@ -1,5 +1,6 @@
1
1
  export namespace LeUtils {
2
2
  function equals(value: any, other: any): boolean;
3
+ function equalsMapLike(elementsA: any, elementsB: any, ignoreKeys?: any[]): boolean;
3
4
  function clone(value: any): any;
4
5
  function onDomReady(callback: Function): {
5
6
  remove: Function;
@@ -118,21 +119,6 @@ export namespace LeUtils {
118
119
  function localStorageRemove(id: string): void;
119
120
  function isCurrentHostPrivate(): boolean;
120
121
  function isGivenHostPrivate(host: string): boolean;
121
- function createTreeSet(elements: any[], comparator: (valueA: any, valueB: any) => number): {
122
- getElements: (() => any[]);
123
- getComparator: (() => ((valueA: any, valueB: any) => number));
124
- size: (() => number);
125
- isEmpty: (() => boolean);
126
- contains: ((value: any) => boolean);
127
- first: (() => any | undefined);
128
- last: (() => any | undefined);
129
- pollFirst: (() => any | undefined);
130
- pollLast: (() => any | undefined);
131
- add: ((value: any) => void);
132
- addAll: ((values: any) => void);
133
- getEqualValue: ((value: any) => any);
134
- getEqualValueOrAdd: ((value: any) => any);
135
- };
136
122
  function createTransactionalValue(value?: any): {
137
123
  value: any;
138
124
  changes: {
@@ -0,0 +1,115 @@
1
+ /**
2
+ * A TreeSet is a set of elements, sorted by a comparator.
3
+ * Binary search is used to find elements, which makes it very fast to find elements.
4
+ *
5
+ * The comparator is also used to determine if two values are equal to each other.
6
+ * 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.
7
+ */
8
+ export class TreeSet {
9
+ /**
10
+ * Creates a new TreeSet with the given elements and comparator.
11
+ *
12
+ * @param {*[]} [elements=[]] - The initial elements of the set.
13
+ * @param {(valueA:*, valueB:*) => number} [comparator=LeUtils.compare] - The comparator function to use for sorting.
14
+ */
15
+ constructor(elements?: any[], comparator?: (valueA: any, valueB: any) => number);
16
+ /**
17
+ *
18
+ *
19
+ * @param {*} value - The value to search for in the set.
20
+ * @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).
21
+ * @private
22
+ */
23
+ private binarySearch;
24
+ /**
25
+ * Returns the elements of the set.
26
+ */
27
+ getElements(): any[];
28
+ /**
29
+ * Returns the comparator of the set.
30
+ *
31
+ * @returns {(valueA:*, valueB:*) => number}
32
+ */
33
+ getComparator(): (valueA: any, valueB: any) => number;
34
+ /**
35
+ * Returns the size of the set.
36
+ *
37
+ * @returns {number}
38
+ */
39
+ size(): number;
40
+ /**
41
+ * Returns true if the set is empty, false otherwise.
42
+ *
43
+ * @returns {boolean}
44
+ */
45
+ isEmpty(): boolean;
46
+ /**
47
+ * Returns true if the set contains a value that is equal to the given value, returns false otherwise.
48
+ *
49
+ * @param {*} value - The value to check for in the set.
50
+ * @return {boolean} - True if the set contains the value, false otherwise.
51
+ */
52
+ contains(value: any): boolean;
53
+ /**
54
+ * Returns the first element of the set, or undefined if it is empty.
55
+ *
56
+ * @return {*|undefined} - The first element of the set, or undefined if it is empty.
57
+ */
58
+ first(): any | undefined;
59
+ /**
60
+ * Returns the last element of the set, or undefined if it is empty.
61
+ *
62
+ * @return {*|undefined} - The last element of the set, or undefined if it is empty.
63
+ */
64
+ last(): any | undefined;
65
+ /**
66
+ * Removes and returns the first element of the set, or undefined if it is empty.
67
+ *
68
+ * @returns {*|undefined} - The first element of the set, or undefined if it is empty.
69
+ */
70
+ pollFirst(): any | undefined;
71
+ /**
72
+ * Removes and returns the last element of the set, or undefined if it is empty.
73
+ *
74
+ * @returns {*|undefined} - The last element of the set, or undefined if it is empty.
75
+ */
76
+ pollLast(): any | undefined;
77
+ /**
78
+ * Adds the given value to the set. Will only do so if no equal value already exists.
79
+ * @param {*} value - The value to add to the set.
80
+ */
81
+ add(value: any): void;
82
+ /**
83
+ * Adds all the given values to the set. Will only do so if no equal value already exists.
84
+ *
85
+ * @param {*} values - The values to add to the set.
86
+ */
87
+ addAll(values: any): void;
88
+ /**
89
+ * Returns an equal value that's already in the tree set, or undefined if no equal values in it exist.
90
+ *
91
+ * @param {*} value - The value to search for in the set.
92
+ * @return {*|undefined} - The equal value if found, or undefined if not found.
93
+ */
94
+ getEqualValue(value: any): any | undefined;
95
+ /**
96
+ * 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.
97
+ *
98
+ * @param {*} value - The value to search for in the set.
99
+ * @return {*} - The equal value if found, or the added value if not found.
100
+ */
101
+ getEqualValueOrAdd(value: any): any;
102
+ /**
103
+ * Returns a string representation of the TreeSet.
104
+ *
105
+ * @returns {string} - A string representation of the TreeSet, including its elements and comparator.
106
+ */
107
+ toString(): string;
108
+ /**
109
+ * Returns a JSON representation of the TreeSet.
110
+ *
111
+ * @returns {Object} - An object containing the elements and comparator of the TreeSet.
112
+ */
113
+ toJSON(): any;
114
+ #private;
115
+ }
package/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { LeUtils } from "./LeUtils.js";
2
2
  export { LinkedList } from "./classes/LinkedList.js";
3
3
  export { SerializableMap } from "./classes/SerializableMap.js";
4
+ export { TreeSet } from "./classes/TreeSet.js";
4
5
  export { ISSET, IS_ARRAY, ARRAY, IS_OBJECT, OBJECT, STRING, STRING_ANY, INT, INT_ANY, FLOAT, FLOAT_ANY, INT_LAX, INT_LAX_ANY, FLOAT_LAX, FLOAT_LAX_ANY } from "./LeTypes.js";
package/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export declare function ISSET(value: any): boolean;
24
24
 
25
25
  export declare namespace LeUtils {
26
26
  export function equals(value: any, other: any): boolean;
27
+ export function equalsMapLike(elementsA: any, elementsB: any, ignoreKeys?: any[]): boolean;
27
28
  export function clone(value: any): any;
28
29
  export function onDomReady(callback: Function): {
29
30
  remove: Function;
@@ -142,21 +143,6 @@ export declare namespace LeUtils {
142
143
  export function localStorageRemove(id: string): void;
143
144
  export function isCurrentHostPrivate(): boolean;
144
145
  export function isGivenHostPrivate(host: string): boolean;
145
- export function createTreeSet(elements: any[], comparator: (valueA: any, valueB: any) => number): {
146
- getElements: (() => any[]);
147
- getComparator: (() => ((valueA: any, valueB: any) => number));
148
- size: (() => number);
149
- isEmpty: (() => boolean);
150
- contains: ((value: any) => boolean);
151
- first: (() => any | undefined);
152
- last: (() => any | undefined);
153
- pollFirst: (() => any | undefined);
154
- pollLast: (() => any | undefined);
155
- add: ((value: any) => void);
156
- addAll: ((values: any) => void);
157
- getEqualValue: ((value: any) => any);
158
- getEqualValueOrAdd: ((value: any) => any);
159
- };
160
146
  export function createTransactionalValue(value?: any): {
161
147
  value: any;
162
148
  changes: {
@@ -298,4 +284,120 @@ export declare function STRING(value: any): string;
298
284
 
299
285
  export declare function STRING_ANY(...values: any): string;
300
286
 
287
+ /**
288
+ * A TreeSet is a set of elements, sorted by a comparator.
289
+ * Binary search is used to find elements, which makes it very fast to find elements.
290
+ *
291
+ * The comparator is also used to determine if two values are equal to each other.
292
+ * 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.
293
+ */
294
+ export declare class TreeSet {
295
+ /**
296
+ * Creates a new TreeSet with the given elements and comparator.
297
+ *
298
+ * @param {*[]} [elements=[]] - The initial elements of the set.
299
+ * @param {(valueA:*, valueB:*) => number} [comparator=LeUtils.compare] - The comparator function to use for sorting.
300
+ */
301
+ constructor(elements?: any[], comparator?: (valueA: any, valueB: any) => number);
302
+ /**
303
+ *
304
+ *
305
+ * @param {*} value - The value to search for in the set.
306
+ * @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).
307
+ * @private
308
+ */
309
+ private binarySearch;
310
+ /**
311
+ * Returns the elements of the set.
312
+ */
313
+ getElements(): any[];
314
+ /**
315
+ * Returns the comparator of the set.
316
+ *
317
+ * @returns {(valueA:*, valueB:*) => number}
318
+ */
319
+ getComparator(): (valueA: any, valueB: any) => number;
320
+ /**
321
+ * Returns the size of the set.
322
+ *
323
+ * @returns {number}
324
+ */
325
+ size(): number;
326
+ /**
327
+ * Returns true if the set is empty, false otherwise.
328
+ *
329
+ * @returns {boolean}
330
+ */
331
+ isEmpty(): boolean;
332
+ /**
333
+ * Returns true if the set contains a value that is equal to the given value, returns false otherwise.
334
+ *
335
+ * @param {*} value - The value to check for in the set.
336
+ * @return {boolean} - True if the set contains the value, false otherwise.
337
+ */
338
+ contains(value: any): boolean;
339
+ /**
340
+ * Returns the first element of the set, or undefined if it is empty.
341
+ *
342
+ * @return {*|undefined} - The first element of the set, or undefined if it is empty.
343
+ */
344
+ first(): any | undefined;
345
+ /**
346
+ * Returns the last element of the set, or undefined if it is empty.
347
+ *
348
+ * @return {*|undefined} - The last element of the set, or undefined if it is empty.
349
+ */
350
+ last(): any | undefined;
351
+ /**
352
+ * Removes and returns the first element of the set, or undefined if it is empty.
353
+ *
354
+ * @returns {*|undefined} - The first element of the set, or undefined if it is empty.
355
+ */
356
+ pollFirst(): any | undefined;
357
+ /**
358
+ * Removes and returns the last element of the set, or undefined if it is empty.
359
+ *
360
+ * @returns {*|undefined} - The last element of the set, or undefined if it is empty.
361
+ */
362
+ pollLast(): any | undefined;
363
+ /**
364
+ * Adds the given value to the set. Will only do so if no equal value already exists.
365
+ * @param {*} value - The value to add to the set.
366
+ */
367
+ add(value: any): void;
368
+ /**
369
+ * Adds all the given values to the set. Will only do so if no equal value already exists.
370
+ *
371
+ * @param {*} values - The values to add to the set.
372
+ */
373
+ addAll(values: any): void;
374
+ /**
375
+ * Returns an equal value that's already in the tree set, or undefined if no equal values in it exist.
376
+ *
377
+ * @param {*} value - The value to search for in the set.
378
+ * @return {*|undefined} - The equal value if found, or undefined if not found.
379
+ */
380
+ getEqualValue(value: any): any | undefined;
381
+ /**
382
+ * 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.
383
+ *
384
+ * @param {*} value - The value to search for in the set.
385
+ * @return {*} - The equal value if found, or the added value if not found.
386
+ */
387
+ getEqualValueOrAdd(value: any): any;
388
+ /**
389
+ * Returns a string representation of the TreeSet.
390
+ *
391
+ * @returns {string} - A string representation of the TreeSet, including its elements and comparator.
392
+ */
393
+ toString(): string;
394
+ /**
395
+ * Returns a JSON representation of the TreeSet.
396
+ *
397
+ * @returns {Object} - An object containing the elements and comparator of the TreeSet.
398
+ */
399
+ toJSON(): any;
400
+ #private;
401
+ }
402
+
301
403
  export { }