@lowentry/utils 1.19.3 → 1.20.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,10 +1,11 @@
1
1
  export namespace LeUtils {
2
- export { FastDeepEqual as equals };
3
- export function clone(value: any): any;
4
- export function onDomReady(callback: Function): {
2
+ function equals(value: any, other: any): boolean;
3
+ function equalsMapLike(elementsA: any, elementsB: any, ignoreKeys?: any[]): boolean;
4
+ function clone(value: any): any;
5
+ function onDomReady(callback: Function): {
5
6
  remove: Function;
6
7
  };
7
- export function parseVersionString(versionString: string | any): {
8
+ function parseVersionString(versionString: string | any): {
8
9
  major: (number);
9
10
  minor: (number);
10
11
  patch: (number);
@@ -15,56 +16,56 @@ export namespace LeUtils {
15
16
  largerThan: ((arg0: string | any) => boolean);
16
17
  largerThanOrEquals: ((arg0: string | any) => boolean);
17
18
  };
18
- export function contains(array: any[] | any | Function, value: any): boolean;
19
- export function containsCaseInsensitive(array: any[] | any | Function, value: any): boolean;
20
- export function containsAll(array: any[] | any | Function, values: any[] | any | Function): boolean;
21
- export function containsAllCaseInsensitive(array: any[] | any | Function, values: any[] | any | Function): boolean;
22
- export function containsAny(array: any[] | any | Function, values: any[] | any | Function): boolean;
23
- export function containsAnyCaseInsensitive(array: any[] | any | Function, values: any[] | any | Function): boolean;
24
- export function containsNone(array: any[] | any | Function, values: any[] | any | Function): boolean;
25
- export function containsNoneCaseInsensitive(array: any[] | any | Function, values: any[] | any | Function): boolean;
26
- export function findIndexValue(elements: any[] | any | Function, callback: (value: any, index: any) => boolean | void, optionalSkipHasOwnPropertyCheck?: boolean): {
19
+ function contains(array: any[] | any | Function, value: any): boolean;
20
+ function containsCaseInsensitive(array: any[] | any | Function, value: any): boolean;
21
+ function containsAll(array: any[] | any | Function, values: any[] | any | Function): boolean;
22
+ function containsAllCaseInsensitive(array: any[] | any | Function, values: any[] | any | Function): boolean;
23
+ function containsAny(array: any[] | any | Function, values: any[] | any | Function): boolean;
24
+ function containsAnyCaseInsensitive(array: any[] | any | Function, values: any[] | any | Function): boolean;
25
+ function containsNone(array: any[] | any | Function, values: any[] | any | Function): boolean;
26
+ function containsNoneCaseInsensitive(array: any[] | any | Function, values: any[] | any | Function): boolean;
27
+ function findIndexValue(elements: any[] | any | Function, callback: (value: any, index: any) => boolean | void, optionalSkipHasOwnPropertyCheck?: boolean): {
27
28
  index: any;
28
29
  value: any;
29
30
  } | null;
30
- export function findIndex(elements: any[] | any | Function, callback: (value: any, index: any) => boolean | void, optionalSkipHasOwnPropertyCheck?: boolean): any | null;
31
- export function find(elements: any[] | any | Function, callback: (value: any, index: any) => boolean | void, optionalSkipHasOwnPropertyCheck?: boolean): any | null;
32
- export function getValueAtIndex(elements: any, index: any, optionalSkipHasOwnPropertyCheck?: boolean): any;
33
- export function supportsEach(elements: any): boolean;
34
- export function eachIterator(elements: any, optionalSkipHasOwnPropertyCheck?: boolean): Generator<any, void, unknown>;
35
- export function each(elements: any, callback: (value: any, index?: any) => boolean | void, optionalSkipHasOwnPropertyCheck?: boolean): any;
36
- export function eachAsync(elements: any, asyncCallback: any, parallelCount?: number, optionalSkipHasOwnPropertyCheck?: boolean): Promise<any>;
37
- export function getEmptySimplifiedCollection(elements: any): [boolean, any[] | any | Map<any, any>, (value: any, index: any) => void];
38
- export function filter(elements: any, callback?: (value: any, index: any) => boolean | undefined, optionalSkipHasOwnPropertyCheck?: boolean): any;
39
- export function map(elements: any, callback?: (value: any, index: any) => any, optionalSkipHasOwnPropertyCheck?: boolean): any;
40
- export function mapToArray(elements: any, callback?: (value: any, index: any) => any, optionalSkipHasOwnPropertyCheck?: boolean): any[];
41
- export function mapToArraySorted(elements: any, comparator: (valueA: any, valueB: any) => number, callback?: (value: any, index: any) => any, optionalSkipHasOwnPropertyCheck?: boolean): any[];
42
- export function sortKeys(elements: any, comparator: (valueA: any, valueB: any) => number, optionalSkipHasOwnPropertyCheck?: boolean): any[];
43
- export function flattenArray(array: any): any[];
44
- export function flattenToArray(elements: any, optionalSkipHasOwnPropertyCheck?: boolean): any[];
45
- export function compare(a: any, b: any): number;
46
- export function compareNumbers(a: number, b: number): number;
47
- export function compareNumericStrings(a: string | number, b: string | number): number;
48
- export function compareNaturalStrings(a: string, b: string): number;
49
- export function compareTimestampStrings(a: string, b: string): number;
50
- export function isEmptyObject(obj: any, optionalSkipHasOwnPropertyCheck?: boolean | undefined): boolean;
51
- export function getObjectFieldsCount(obj: any, optionalSkipHasOwnPropertyCheck?: boolean | undefined): number;
52
- export function isGeneratorFunction(func: any): any;
53
- export function setTimeout(callback: (deltaTime: number) => any, ms: number): {
31
+ function findIndex(elements: any[] | any | Function, callback: (value: any, index: any) => boolean | void, optionalSkipHasOwnPropertyCheck?: boolean): any | null;
32
+ function find(elements: any[] | any | Function, callback: (value: any, index: any) => boolean | void, optionalSkipHasOwnPropertyCheck?: boolean): any | null;
33
+ function getValueAtIndex(elements: any, index: any, optionalSkipHasOwnPropertyCheck?: boolean): any;
34
+ function supportsEach(elements: any): boolean;
35
+ function eachIterator(elements: any, optionalSkipHasOwnPropertyCheck?: boolean): Generator<any, void, unknown>;
36
+ function each(elements: any, callback: (value: any, index?: any) => boolean | void, optionalSkipHasOwnPropertyCheck?: boolean): any;
37
+ function eachAsync(elements: any, asyncCallback: any, parallelCount?: number, optionalSkipHasOwnPropertyCheck?: boolean): Promise<any>;
38
+ function getEmptySimplifiedCollection(elements: any): [boolean, any[] | any | Map<any, any>, (value: any, index: any) => void];
39
+ function filter(elements: any, callback?: (value: any, index: any) => boolean | undefined, optionalSkipHasOwnPropertyCheck?: boolean): any;
40
+ function map(elements: any, callback?: (value: any, index: any) => any, optionalSkipHasOwnPropertyCheck?: boolean): any;
41
+ function mapToArray(elements: any, callback?: (value: any, index: any) => any, optionalSkipHasOwnPropertyCheck?: boolean): any[];
42
+ function mapToArraySorted(elements: any, comparator: (valueA: any, valueB: any) => number, callback?: (value: any, index: any) => any, optionalSkipHasOwnPropertyCheck?: boolean): any[];
43
+ function sortKeys(elements: any, comparator: (valueA: any, valueB: any) => number, optionalSkipHasOwnPropertyCheck?: boolean): any[];
44
+ function flattenArray(array: any): any[];
45
+ function flattenToArray(elements: any, optionalSkipHasOwnPropertyCheck?: boolean): any[];
46
+ function compare(a: any, b: any): number;
47
+ function compareNumbers(a: number, b: number): number;
48
+ function compareNumericStrings(a: string | number, b: string | number): number;
49
+ function compareNaturalStrings(a: string, b: string): number;
50
+ function compareTimestampStrings(a: string, b: string): number;
51
+ function isEmptyObject(obj: any, optionalSkipHasOwnPropertyCheck?: boolean | undefined): boolean;
52
+ function getObjectFieldsCount(obj: any, optionalSkipHasOwnPropertyCheck?: boolean | undefined): number;
53
+ function isGeneratorFunction(func: any): any;
54
+ function setTimeout(callback: (deltaTime: number) => any, ms: number): {
54
55
  remove: Function;
55
56
  };
56
- export function setInterval(callback: (deltaTime: number) => any, intervalMs?: number, fireImmediately?: boolean): {
57
+ function setInterval(callback: (deltaTime: number) => any, intervalMs?: number, fireImmediately?: boolean): {
57
58
  remove: Function;
58
59
  };
59
- export function setAnimationFrameTimeout(callback: (deltaTime: number) => any, frames?: number): {
60
+ function setAnimationFrameTimeout(callback: (deltaTime: number) => any, frames?: number): {
60
61
  remove: Function;
61
62
  };
62
- export function setAnimationFrameInterval(callback: (deltaTime: number) => any, intervalFrames?: number, fireImmediately?: boolean): {
63
+ function setAnimationFrameInterval(callback: (deltaTime: number) => any, intervalFrames?: number, fireImmediately?: boolean): {
63
64
  remove: Function;
64
65
  };
65
- export function promiseTimeout(ms: number): Promise<number>;
66
- export function promiseAnimationFrameTimeout(frames: number): Promise<number>;
67
- export function fetch(url: string, options?: {
66
+ function promiseTimeout(ms: number): Promise<number>;
67
+ function promiseAnimationFrameTimeout(frames: number): Promise<number>;
68
+ function fetch(url: string, options?: {
68
69
  retries?: number | null;
69
70
  delay?: number | ((attempt: number) => number) | null;
70
71
  } | any | null): {
@@ -74,51 +75,51 @@ export namespace LeUtils {
74
75
  remove: Function;
75
76
  isRemoved: Function;
76
77
  };
77
- export function cachedFetch(url: any, options: any, responseFunction: any): Promise<any>;
78
- export function platformIsMobile(): boolean;
79
- export function platformHasCursor(): boolean;
80
- export function capitalize(string: string): string;
81
- export function endsWithAny(string: string, endingCharsStringOrArray: string | string[]): boolean;
82
- export function startsWithAny(string: string, startingCharsStringOrArray: string | string[]): boolean;
83
- export function trimEnd(string: string, trimCharsStringOrArray: string | string[]): string;
84
- export function trimStart(string: string, trimCharsStringOrArray: string | string[]): string;
85
- export function trim(string: string, trimCharsStringOrArray: string | string[]): string;
86
- export function purgeSentence(sentence: string): string;
87
- export function purgeErrorMessage(error: any): string;
88
- export function generateNamePermutations(...names: string[]): string[];
89
- export function increaseNumericStringByOne(string: string): string;
90
- export function uniqueId(): string;
91
- export function timestamp(now?: number | null | undefined): string;
92
- export function getEmptyImageSrc(): string;
93
- export function getPercentage(part: number | string, total: number | string): number;
94
- export function getImagePixels(image: HTMLImageElement): Uint8ClampedArray;
95
- export function getColoredImage(image: HTMLImageElement, color: string): string;
96
- export function rgbToHex(rgb: number[]): string;
97
- export function hexToRgb(hexstring: string): number[];
98
- export function rgbToHsl(rgb: number[]): number[];
99
- export function hslToRgb(hsl: any): number[];
100
- export function rgbToLab(rgb: number[]): number[];
101
- export function getDifferenceBetweenRgb(rgbA: number[], rgbB: number[]): number;
102
- export function getDifferenceBetweenLab(labA: number[], labB: number[]): number;
103
- export function getRgbOfGradient(gradient: {
78
+ function cachedFetch(url: any, options: any, responseFunction: any): Promise<any>;
79
+ function platformIsMobile(): boolean;
80
+ function platformHasCursor(): boolean;
81
+ function capitalize(string: string): string;
82
+ function endsWithAny(string: string, endingCharsStringOrArray: string | string[]): boolean;
83
+ function startsWithAny(string: string, startingCharsStringOrArray: string | string[]): boolean;
84
+ function trimEnd(string: string, trimCharsStringOrArray: string | string[]): string;
85
+ function trimStart(string: string, trimCharsStringOrArray: string | string[]): string;
86
+ function trim(string: string, trimCharsStringOrArray: string | string[]): string;
87
+ function purgeSentence(sentence: string): string;
88
+ function purgeErrorMessage(error: any): string;
89
+ function generateNamePermutations(...names: string[]): string[];
90
+ function increaseNumericStringByOne(string: string): string;
91
+ function uniqueId(): string;
92
+ function timestamp(now?: number | null | undefined): string;
93
+ function getEmptyImageSrc(): string;
94
+ function getPercentage(part: number | string, total: number | string): number;
95
+ function getImagePixels(image: HTMLImageElement): Uint8ClampedArray;
96
+ function getColoredImage(image: HTMLImageElement, color: string): string;
97
+ function rgbToHex(rgb: number[]): string;
98
+ function hexToRgb(hexstring: string): number[];
99
+ function rgbToHsl(rgb: number[]): number[];
100
+ function hslToRgb(hsl: any): number[];
101
+ function rgbToLab(rgb: number[]): number[];
102
+ function getDifferenceBetweenRgb(rgbA: number[], rgbB: number[]): number;
103
+ function getDifferenceBetweenLab(labA: number[], labB: number[]): number;
104
+ function getRgbOfGradient(gradient: {
104
105
  percentage?: number[];
105
106
  }, percentage: number): number[];
106
- export function getRgbBetween(startRgb: number[], endRgb: number[], percentage: number): number[];
107
- export function btoa(string: string): string;
108
- export function atob(base64string: string): string;
109
- export function utf8ToBase64(string: string): string;
110
- export function base64ToUtf8(base64string: string): string;
111
- export function base64ToHex(base64string: string): string;
112
- export function hexToBase64(hexstring: string): string;
113
- export function base64ToBytes(base64string: string): Uint8Array;
114
- export function bytesToBase64(arraybuffer: ArrayLike<number> | ArrayBuffer): string;
115
- export function downloadFile(base64string: string, fileName?: string, mimeType?: string): void;
116
- export function localStorageGet(id: string): any;
117
- export function localStorageSet(id: string, data: any): void;
118
- export function localStorageRemove(id: string): void;
119
- export function isCurrentHostPrivate(): boolean;
120
- export function isGivenHostPrivate(host: string): boolean;
121
- export function createTreeSet(elements: any[], comparator: (valueA: any, valueB: any) => number): {
107
+ function getRgbBetween(startRgb: number[], endRgb: number[], percentage: number): number[];
108
+ function btoa(string: string): string;
109
+ function atob(base64string: string): string;
110
+ function utf8ToBase64(string: string): string;
111
+ function base64ToUtf8(base64string: string): string;
112
+ function base64ToHex(base64string: string): string;
113
+ function hexToBase64(hexstring: string): string;
114
+ function base64ToBytes(base64string: string): Uint8Array;
115
+ function bytesToBase64(arraybuffer: ArrayLike<number> | ArrayBuffer): string;
116
+ function downloadFile(base64string: string, fileName?: string, mimeType?: string): void;
117
+ function localStorageGet(id: string): any;
118
+ function localStorageSet(id: string, data: any): void;
119
+ function localStorageRemove(id: string): void;
120
+ function isCurrentHostPrivate(): boolean;
121
+ function isGivenHostPrivate(host: string): boolean;
122
+ function createTreeSet(elements: any[], comparator: (valueA: any, valueB: any) => number): {
122
123
  getElements: (() => any[]);
123
124
  getComparator: (() => ((valueA: any, valueB: any) => number));
124
125
  size: (() => number);
@@ -133,86 +134,85 @@ export namespace LeUtils {
133
134
  getEqualValue: ((value: any) => any);
134
135
  getEqualValueOrAdd: ((value: any) => any);
135
136
  };
136
- export function createTransactionalValue(value?: any): {
137
+ function createTransactionalValue(value?: any): {
137
138
  value: any;
138
139
  changes: {
139
140
  id: string;
140
141
  value: any;
141
142
  }[];
142
143
  };
143
- export function isTransactionalValueValid(transactionalValue: {
144
+ function isTransactionalValueValid(transactionalValue: {
144
145
  value: any;
145
146
  changes: {
146
147
  id: string;
147
148
  value: any;
148
149
  }[];
149
150
  }): boolean;
150
- export function transactionalValueToString(transactionalValue: {
151
+ function transactionalValueToString(transactionalValue: {
151
152
  value: any;
152
153
  changes: {
153
154
  id: string;
154
155
  value: any;
155
156
  }[];
156
157
  }): string;
157
- export function transactionSetAndCommit(transactionalValue: {
158
+ function transactionSetAndCommit(transactionalValue: {
158
159
  value: any;
159
160
  changes: {
160
161
  id: string;
161
162
  value: any;
162
163
  }[];
163
164
  }, value: any): void;
164
- export function transactionSetWithoutCommitting(transactionalValue: {
165
+ function transactionSetWithoutCommitting(transactionalValue: {
165
166
  value: any;
166
167
  changes: {
167
168
  id: string;
168
169
  value: any;
169
170
  }[];
170
171
  }, value: any): string;
171
- export function transactionCommitChange(transactionalValue: {
172
+ function transactionCommitChange(transactionalValue: {
172
173
  value: any;
173
174
  changes: {
174
175
  id: string;
175
176
  value: any;
176
177
  }[];
177
178
  }, changeId: string): boolean;
178
- export function transactionCancelChange(transactionalValue: {
179
+ function transactionCancelChange(transactionalValue: {
179
180
  value: any;
180
181
  changes: {
181
182
  id: string;
182
183
  value: any;
183
184
  }[];
184
185
  }, changeId: string): boolean;
185
- export function transactionIsChangeRelevant(transactionalValue: {
186
+ function transactionIsChangeRelevant(transactionalValue: {
186
187
  value: any;
187
188
  changes: {
188
189
  id: string;
189
190
  value: any;
190
191
  }[];
191
192
  }, changeId: string): boolean;
192
- export function transactionGetCommittedValue(transactionalValue: {
193
+ function transactionGetCommittedValue(transactionalValue: {
193
194
  value: any;
194
195
  changes: {
195
196
  id: string;
196
197
  value: any;
197
198
  }[];
198
199
  }): any;
199
- export function transactionGetValue(transactionalValue: {
200
+ function transactionGetValue(transactionalValue: {
200
201
  value: any;
201
202
  changes: {
202
203
  id: string;
203
204
  value: any;
204
205
  }[];
205
206
  }): any;
206
- export function createWorkerThread(name: string): {
207
+ function createWorkerThread(name: string): {
207
208
  worker: Worker | null;
208
209
  sendMessage: (data: any, options: {
209
210
  timeout: number | undefined;
210
211
  } | undefined) => Promise<any>;
211
212
  };
212
- export function sendWorkerMessage(workerName: any, data: any, options: any): any;
213
- export function purgeEmail(email: string): string;
214
- export function isFocusClear(): boolean;
215
- export function getUserLocale(): any;
216
- export function getUserLocaleDateFormat(): any;
213
+ function sendWorkerMessage(workerName: any, data: any, options: any): any;
214
+ function purgeEmail(email: string): string;
215
+ function isFocusClear(): boolean;
216
+ function getUserLocale(): any;
217
+ function getUserLocaleDateFormat(): any;
217
218
  }
218
- import FastDeepEqual from 'fast-deep-equal';
package/index.d.ts CHANGED
@@ -23,7 +23,8 @@ export declare function IS_OBJECT(value: any): boolean;
23
23
  export declare function ISSET(value: any): boolean;
24
24
 
25
25
  export declare namespace LeUtils {
26
- { FastDeepEqual as equals };
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;
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
3
  import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
4
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
4
  import _typeof from '@babel/runtime/helpers/typeof';
5
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
6
6
  import '@babel/runtime/helpers/awaitAsyncGenerator';
7
7
  import _wrapAsyncGenerator from '@babel/runtime/helpers/wrapAsyncGenerator';
8
8
  import _regeneratorRuntime from '@babel/runtime/regenerator';
@@ -254,7 +254,71 @@ var LeUtils = {
254
254
  * @param {*} other The other value to compare.
255
255
  * @returns {boolean} Returns true if the values are equivalent.
256
256
  */
257
- equals: FastDeepEqual,
257
+ equals: function equals(value, other) {
258
+ return FastDeepEqual(value, other);
259
+ },
260
+ /**
261
+ * Performs a deep equality comparison between two collections (objects, maps, arrays, etc), sorting on the keys before comparing them.
262
+ *
263
+ * This is useful for comparing objects that have the same properties, but in a different order, and/or in a different collection type (like Maps vs Objects).
264
+ *
265
+ * @param {*} elementsA The elements to compare.
266
+ * @param {*} elementsB The other elements to compare.
267
+ * @param {string[]} [ignoreKeys=[]] An array of keys to ignore when comparing the elements. This is useful for ignoring properties that are not relevant for the comparison.
268
+ * @return {boolean} Returns true if the given values are equivalent, ignoring the order of properties.
269
+ */
270
+ equalsMapLike: function () {
271
+ var sortKeyValueArrays = function sortKeyValueArrays(pairA, pairB) {
272
+ return LeUtils.compare(pairA[0], pairB[0]);
273
+ };
274
+ return function (elementsA, elementsB) {
275
+ var ignoreKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
276
+ elementsA = LeUtils.mapToArray(elementsA, function (value, key) {
277
+ return [key, value];
278
+ }).sort(sortKeyValueArrays);
279
+ elementsB = LeUtils.mapToArray(elementsB, function (value, key) {
280
+ return [key, value];
281
+ }).sort(sortKeyValueArrays);
282
+ ignoreKeys = typeof ignoreKeys === 'string' ? ARRAY(ignoreKeys) : LeUtils.mapToArray(ignoreKeys);
283
+ var indexA = 0;
284
+ var indexB = 0;
285
+ while (indexA < elementsA.length && indexB < elementsB.length) {
286
+ var _elementsA$indexA = _slicedToArray(elementsA[indexA], 2),
287
+ mapKey = _elementsA$indexA[0],
288
+ mapValue = _elementsA$indexA[1];
289
+ var _elementsB$indexB = _slicedToArray(elementsB[indexB], 2),
290
+ ownMapKey = _elementsB$indexB[0],
291
+ ownMapValue = _elementsB$indexB[1];
292
+ var ignoreKeysIncludesMapKey = ignoreKeys.includes(mapKey);
293
+ var ignoreKeysIncludesOwnMapKey = ignoreKeys.includes(ownMapKey);
294
+ if (ignoreKeysIncludesMapKey) {
295
+ indexA++;
296
+ if (ignoreKeysIncludesOwnMapKey) {
297
+ indexB++;
298
+ }
299
+ continue;
300
+ } else if (ignoreKeysIncludesOwnMapKey) {
301
+ indexB++;
302
+ continue;
303
+ }
304
+ if (!LeUtils.equals(mapKey, ownMapKey) || !LeUtils.equals(mapValue, ownMapValue)) {
305
+ return false;
306
+ }
307
+ indexA++;
308
+ indexB++;
309
+ }
310
+ while (indexA < elementsA.length && ignoreKeys.includes(elementsA[indexA][0])) {
311
+ indexA++;
312
+ }
313
+ if (indexA < elementsA.length) {
314
+ return false;
315
+ }
316
+ while (indexB < elementsB.length && ignoreKeys.includes(elementsB[indexB][0])) {
317
+ indexB++;
318
+ }
319
+ return indexB >= elementsB.length;
320
+ };
321
+ }(),
258
322
  /**
259
323
  * Returns a deep copy of the given value.
260
324
  *