@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.
- package/build/LeUtils.d.ts +103 -103
- package/index.d.ts +2 -1
- package/index.js +66 -2
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/LeUtils.js +72 -2
- package/tests/equals.test.js +216 -0
package/build/LeUtils.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export namespace LeUtils {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
57
|
+
function setInterval(callback: (deltaTime: number) => any, intervalMs?: number, fireImmediately?: boolean): {
|
|
57
58
|
remove: Function;
|
|
58
59
|
};
|
|
59
|
-
|
|
60
|
+
function setAnimationFrameTimeout(callback: (deltaTime: number) => any, frames?: number): {
|
|
60
61
|
remove: Function;
|
|
61
62
|
};
|
|
62
|
-
|
|
63
|
+
function setAnimationFrameInterval(callback: (deltaTime: number) => any, intervalFrames?: number, fireImmediately?: boolean): {
|
|
63
64
|
remove: Function;
|
|
64
65
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
*
|