@ls-stack/utils 3.68.0 → 3.70.0
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/dist/arrayUtils.mjs +1 -1
- package/dist/{assertions-CsE3pD8P.mjs → assertions--46HN4J7.mjs} +1 -1
- package/dist/assertions.mjs +1 -1
- package/dist/asyncQueue.mjs +1 -1
- package/dist/cache.mjs +2 -2
- package/dist/castValues.mjs +1 -1
- package/dist/concurrentCalls.mjs +3 -3
- package/dist/conversions.mjs +1 -1
- package/dist/createThrottleController.mjs +1 -1
- package/dist/deepEqual.mjs +1 -1
- package/dist/deepReplaceValues.mjs +1 -1
- package/dist/enhancedMap.mjs +1 -1
- package/dist/filterObjectOrArrayKeys.mjs +1 -1
- package/dist/fuzzySearch.d.mts +0 -12
- package/dist/fuzzySearch.mjs +0 -12
- package/dist/getCompositeKey.mjs +1 -1
- package/dist/getDiffs.d.mts +16 -0
- package/dist/getDiffs.mjs +202 -0
- package/dist/interpolate.mjs +2 -2
- package/dist/keepPrevIfUnchanged.mjs +1 -1
- package/dist/mathUtils.mjs +1 -1
- package/dist/mockList.d.mts +15 -0
- package/dist/mockList.mjs +41 -0
- package/dist/mutationUtils.mjs +1 -1
- package/dist/objUtils.mjs +1 -1
- package/dist/parallelAsyncCalls.mjs +1 -1
- package/dist/partialEqual.mjs +1 -1
- package/dist/saferTyping.d.mts +6 -1
- package/dist/saferTyping.mjs +8 -1
- package/dist/serializeXML.mjs +1 -1
- package/dist/stringUtils.mjs +1 -1
- package/dist/testUtils.mjs +5 -5
- package/dist/{time-CJSFU8a1.mjs → time-BeJWLHQb.mjs} +2 -2
- package/dist/time.mjs +1 -1
- package/dist/tsResult.mjs +1 -1
- package/dist/typeGuards.mjs +1 -1
- package/dist/typingFnUtils.mjs +1 -1
- package/dist/yamlStringify.mjs +3 -3
- package/package.json +5 -2
- /package/dist/{castValues-QQmtZf_x.mjs → castValues-BA2XDJkl.mjs} +0 -0
- /package/dist/{conversions-CWGUTE04.mjs → conversions-D1BTRFdQ.mjs} +0 -0
- /package/dist/{deepEqual-2xhh-diQ.mjs → deepEqual-Du3EHxxo.mjs} +0 -0
- /package/dist/{mathUtils-DuqyAkNL.mjs → mathUtils-FkPKduxv.mjs} +0 -0
- /package/dist/{stringUtils-DEEj_Z1p.mjs → stringUtils-CUANTYJs.mjs} +0 -0
- /package/dist/{typeGuards-CMQqixVr.mjs → typeGuards-CjiEoecn.mjs} +0 -0
- /package/dist/{typingFnUtils-BLxmDUp5.mjs → typingFnUtils-y_SiKalk.mjs} +0 -0
package/dist/arrayUtils.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as isPlainObject$1, i as isObject$1, n as isFunction$1, o as isPromise$1 } from "./typeGuards-
|
|
1
|
+
import { a as isPlainObject$1, i as isObject$1, n as isFunction$1, o as isPromise$1 } from "./typeGuards-CjiEoecn.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/assertions.ts
|
|
4
4
|
const undefErrMsg = "not undefined assertion failed";
|
package/dist/assertions.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as isFunction, c as isPromise, i as invariant, l as notNullish, n as assertIsNotUndefined, o as isObject, r as exhaustiveCheck, s as isPlainObject, t as assertIsNotNullish, u as notUndefined } from "./assertions
|
|
1
|
+
import { a as isFunction, c as isPromise, i as invariant, l as notNullish, n as assertIsNotUndefined, o as isObject, r as exhaustiveCheck, s as isPlainObject, t as assertIsNotNullish, u as notUndefined } from "./assertions--46HN4J7.mjs";
|
|
2
2
|
|
|
3
3
|
export { assertIsNotNullish, assertIsNotUndefined, exhaustiveCheck, invariant, isFunction, isObject, isPlainObject, isPromise, notNullish, notUndefined };
|
package/dist/asyncQueue.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defer } from "./promiseUtils.mjs";
|
|
2
|
-
import { p as durationObjToMs } from "./time-
|
|
2
|
+
import { p as durationObjToMs } from "./time-BeJWLHQb.mjs";
|
|
3
3
|
import { evtmitter } from "evtmitter";
|
|
4
4
|
import { Result, isResult, resultify, unknownToError } from "t-result";
|
|
5
5
|
|
package/dist/cache.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as isPromise } from "./assertions
|
|
2
|
-
import { p as durationObjToMs } from "./time-
|
|
1
|
+
import { c as isPromise } from "./assertions--46HN4J7.mjs";
|
|
2
|
+
import { p as durationObjToMs } from "./time-BeJWLHQb.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/cache.ts
|
|
5
5
|
/**
|
package/dist/castValues.mjs
CHANGED
package/dist/concurrentCalls.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { i as isObject, o as isPromise } from "./typeGuards-
|
|
2
|
-
import { i as invariant } from "./assertions
|
|
1
|
+
import { i as isObject, o as isPromise } from "./typeGuards-CjiEoecn.mjs";
|
|
2
|
+
import { i as invariant } from "./assertions--46HN4J7.mjs";
|
|
3
3
|
import { truncateArray } from "./arrayUtils.mjs";
|
|
4
4
|
import { safeJsonStringify } from "./safeJson.mjs";
|
|
5
5
|
import { sleep } from "./sleep.mjs";
|
|
6
|
-
import { C as truncateString } from "./stringUtils-
|
|
6
|
+
import { C as truncateString } from "./stringUtils-CUANTYJs.mjs";
|
|
7
7
|
import { Result, resultify, unknownToError } from "t-result";
|
|
8
8
|
|
|
9
9
|
//#region src/concurrentCalls.ts
|
package/dist/conversions.mjs
CHANGED
package/dist/deepEqual.mjs
CHANGED
package/dist/enhancedMap.mjs
CHANGED
package/dist/fuzzySearch.d.mts
CHANGED
|
@@ -17,18 +17,6 @@ type SearchOptions<T> = {
|
|
|
17
17
|
* Uses uFuzzy for efficient fuzzy matching with Latin character normalization.
|
|
18
18
|
* Falls back to simple string inclusion matching if an error occurs.
|
|
19
19
|
*
|
|
20
|
-
* @param options - Configuration options for the fuzzy search
|
|
21
|
-
* @param options.items - Array of items to search through
|
|
22
|
-
* @param options.getStringToMatch - Function that extracts the string to match
|
|
23
|
-
* from each item
|
|
24
|
-
* @param options.searchQuery - The search query string (null or empty string
|
|
25
|
-
* returns all items)
|
|
26
|
-
* @param options.uFuzzy - Configured uFuzzy instance (use `getUFuzzyInstance`
|
|
27
|
-
* to create one)
|
|
28
|
-
* @param options.ignoreBestMatch - If true, skips calculating the best match
|
|
29
|
-
* score for performance
|
|
30
|
-
* @param options.throwOnError - If true, throws errors instead of falling back
|
|
31
|
-
* to simple string matching
|
|
32
20
|
* @returns Object containing filtered/sorted items and the best match score
|
|
33
21
|
* (higher is better)
|
|
34
22
|
*/
|
package/dist/fuzzySearch.mjs
CHANGED
|
@@ -8,18 +8,6 @@ import uFuzzy from "@leeoniya/ufuzzy";
|
|
|
8
8
|
* Uses uFuzzy for efficient fuzzy matching with Latin character normalization.
|
|
9
9
|
* Falls back to simple string inclusion matching if an error occurs.
|
|
10
10
|
*
|
|
11
|
-
* @param options - Configuration options for the fuzzy search
|
|
12
|
-
* @param options.items - Array of items to search through
|
|
13
|
-
* @param options.getStringToMatch - Function that extracts the string to match
|
|
14
|
-
* from each item
|
|
15
|
-
* @param options.searchQuery - The search query string (null or empty string
|
|
16
|
-
* returns all items)
|
|
17
|
-
* @param options.uFuzzy - Configured uFuzzy instance (use `getUFuzzyInstance`
|
|
18
|
-
* to create one)
|
|
19
|
-
* @param options.ignoreBestMatch - If true, skips calculating the best match
|
|
20
|
-
* score for performance
|
|
21
|
-
* @param options.throwOnError - If true, throws errors instead of falling back
|
|
22
|
-
* to simple string matching
|
|
23
11
|
* @returns Object containing filtered/sorted items and the best match score
|
|
24
12
|
* (higher is better)
|
|
25
13
|
*/
|
package/dist/getCompositeKey.mjs
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/getDiffs.d.ts
|
|
2
|
+
declare const addKeysName = "++keys_added";
|
|
3
|
+
declare const removeKeysName = "--keys_removed";
|
|
4
|
+
declare const updateKeysName = "~~keys_updated";
|
|
5
|
+
type ObjDiffsKeys = typeof addKeysName | typeof removeKeysName | typeof updateKeysName;
|
|
6
|
+
declare function getDiffs(oldValue: unknown, newValue: unknown, {
|
|
7
|
+
ignoreDiffs,
|
|
8
|
+
ignoreKeys,
|
|
9
|
+
skipIdKey
|
|
10
|
+
}?: {
|
|
11
|
+
ignoreDiffs?: ObjDiffsKeys[];
|
|
12
|
+
ignoreKeys?: string[];
|
|
13
|
+
skipIdKey?: boolean;
|
|
14
|
+
}): Record<string, unknown> | undefined;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { getDiffs };
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { i as isObject } from "./typeGuards-CjiEoecn.mjs";
|
|
2
|
+
import { l as notNullish } from "./assertions--46HN4J7.mjs";
|
|
3
|
+
import { sortBy } from "./arrayUtils.mjs";
|
|
4
|
+
import { t as deepEqual } from "./deepEqual-Du3EHxxo.mjs";
|
|
5
|
+
import { omit } from "./objUtils.mjs";
|
|
6
|
+
import { __LEGIT_ANY_CAST__, __UNSAFE_TO_STRING__ } from "./saferTyping.mjs";
|
|
7
|
+
|
|
8
|
+
//#region src/getDiffs.ts
|
|
9
|
+
function jsonClone(value) {
|
|
10
|
+
if (value === void 0) return value;
|
|
11
|
+
return JSON.parse(JSON.stringify(value));
|
|
12
|
+
}
|
|
13
|
+
const addKeysName = "++keys_added";
|
|
14
|
+
const removeKeysName = "--keys_removed";
|
|
15
|
+
const updateKeysName = "~~keys_updated";
|
|
16
|
+
function getDiffs(oldValue, newValue, { ignoreDiffs, ignoreKeys, skipIdKey } = {}) {
|
|
17
|
+
if (deepEqual(oldValue, newValue)) return void 0;
|
|
18
|
+
if (!isObject(oldValue) || !isObject(newValue)) return {
|
|
19
|
+
"--old": oldValue,
|
|
20
|
+
"++new": newValue
|
|
21
|
+
};
|
|
22
|
+
const diffs = {
|
|
23
|
+
[addKeysName]: {},
|
|
24
|
+
[removeKeysName]: {},
|
|
25
|
+
[updateKeysName]: {}
|
|
26
|
+
};
|
|
27
|
+
const extraInfo = {};
|
|
28
|
+
const removeKeys = /* @__PURE__ */ new Set();
|
|
29
|
+
for (const [key, value] of Object.entries(oldValue)) {
|
|
30
|
+
if (ignoreKeys?.includes(key)) continue;
|
|
31
|
+
if (newValue[key] === void 0 && value !== void 0) {
|
|
32
|
+
notNullish(diffs[removeKeysName])[key] = value;
|
|
33
|
+
removeKeys.add(key);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
for (const [key, value] of Object.entries(newValue)) {
|
|
37
|
+
if (ignoreKeys?.includes(key) || removeKeys.has(key)) continue;
|
|
38
|
+
if (oldValue[key] === void 0 && value !== void 0) notNullish(diffs[addKeysName])[key] = value;
|
|
39
|
+
else if (!deepEqual(jsonClone(oldValue[key]), jsonClone(value))) {
|
|
40
|
+
const updated = notNullish(diffs[updateKeysName]);
|
|
41
|
+
const old = oldValue[key];
|
|
42
|
+
const simplifiedDiffResult = getSimplifiedDiff(old, value);
|
|
43
|
+
updated[typeof simplifiedDiffResult !== "string" && simplifiedDiffResult !== void 0 && "++new" in simplifiedDiffResult ? key : Array.isArray(old) && Array.isArray(value) ? `${key}~~array_changes` : key] = simplifiedDiffResult;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (ignoreDiffs?.includes(addKeysName) || Object.keys(diffs[addKeysName] ?? {}).length === 0) delete diffs[addKeysName];
|
|
47
|
+
if (ignoreDiffs?.includes(removeKeysName) || Object.keys(diffs[removeKeysName] ?? {}).length === 0) delete diffs[removeKeysName];
|
|
48
|
+
if (ignoreDiffs?.includes(updateKeysName) || diffs[updateKeysName] && Object.keys(diffs[updateKeysName]).length === 0) delete diffs[updateKeysName];
|
|
49
|
+
function checkIdKey(key) {
|
|
50
|
+
if (!isObject(newValue) || !isObject(oldValue)) return false;
|
|
51
|
+
if (key in newValue && key in oldValue && newValue[key] === oldValue[key]) {
|
|
52
|
+
const val = newValue[key];
|
|
53
|
+
if (typeof val === "string" || typeof val === "number") {
|
|
54
|
+
extraInfo[key] = __UNSAFE_TO_STRING__(val);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (Object.keys(diffs).length !== 0 && !skipIdKey) {
|
|
61
|
+
if (!checkIdKey("id")) checkIdKey("key");
|
|
62
|
+
}
|
|
63
|
+
const result = {
|
|
64
|
+
...extraInfo,
|
|
65
|
+
...diffs
|
|
66
|
+
};
|
|
67
|
+
if (Object.keys(result).length === 0) return void 0;
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
function isPrimitive(value) {
|
|
71
|
+
return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
72
|
+
}
|
|
73
|
+
function isSmallArray(value) {
|
|
74
|
+
return JSON.stringify(value).length <= 80;
|
|
75
|
+
}
|
|
76
|
+
function getArrayDiffs(old, newValue) {
|
|
77
|
+
const diffs = {};
|
|
78
|
+
let allItemsHaveKey = null;
|
|
79
|
+
for (const item of old) if (isObject(item)) if ((allItemsHaveKey === null || allItemsHaveKey === "id") && "id" in item && isPrimitive(item.id)) allItemsHaveKey = "id";
|
|
80
|
+
else if ((allItemsHaveKey === null || allItemsHaveKey === "key") && "key" in item && isPrimitive(item.key)) allItemsHaveKey = "key";
|
|
81
|
+
else {
|
|
82
|
+
allItemsHaveKey = false;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
allItemsHaveKey = false;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (allItemsHaveKey) {
|
|
90
|
+
for (const item of newValue) if (isObject(item)) {
|
|
91
|
+
if (item[allItemsHaveKey] === void 0) {
|
|
92
|
+
allItemsHaveKey = false;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (allItemsHaveKey) return arrayDiffFromItemsWithIds(__LEGIT_ANY_CAST__(old), __LEGIT_ANY_CAST__(newValue), allItemsHaveKey);
|
|
98
|
+
if (newValue.every((item) => old.some((oldItem) => deepEqual(oldItem, item)))) return null;
|
|
99
|
+
if (isSmallArray(newValue) && isSmallArray(old)) return null;
|
|
100
|
+
if (Math.min(newValue.length, old.length) / Math.max(newValue.length, old.length) < .5) return null;
|
|
101
|
+
diffs.size = newValue.length === old.length ? newValue.length : [
|
|
102
|
+
old.length,
|
|
103
|
+
"->",
|
|
104
|
+
newValue.length
|
|
105
|
+
];
|
|
106
|
+
for (const [index, value] of newValue.entries()) {
|
|
107
|
+
const oldValue = old[index];
|
|
108
|
+
const indexString = `[${index}]${index === newValue.length - 1 ? "(last_item)" : ""}`;
|
|
109
|
+
if (!deepEqual(oldValue, value)) if (oldValue === void 0) diffs[`${indexString}_added`] = value;
|
|
110
|
+
else if (value === void 0) diffs[`${indexString}_removed`] = oldValue;
|
|
111
|
+
else diffs[indexString] = getSimplifiedDiff(oldValue, value, "array");
|
|
112
|
+
}
|
|
113
|
+
if (old.length > newValue.length) {
|
|
114
|
+
for (const [index, value] of old.entries()) if (index >= newValue.length) diffs[`[${index}]_removed`] = value;
|
|
115
|
+
}
|
|
116
|
+
if (Object.keys(diffs).length === 0) return null;
|
|
117
|
+
return diffs;
|
|
118
|
+
}
|
|
119
|
+
function arrayDiffFromItemsWithIds(oldItems, newItems, key) {
|
|
120
|
+
const diffs = {};
|
|
121
|
+
function getItemKey(item, index) {
|
|
122
|
+
const id = item[key];
|
|
123
|
+
return `[${key}: ${typeof id === "string" ? `'${id}'` : __UNSAFE_TO_STRING__(id)}]${index !== null ? `{${index}}` : ""}`;
|
|
124
|
+
}
|
|
125
|
+
const oldItemsMap = new Map(oldItems.map((item, index) => [item[key], {
|
|
126
|
+
item,
|
|
127
|
+
index
|
|
128
|
+
}]));
|
|
129
|
+
const movedItems = [];
|
|
130
|
+
const oldAdjustIndex = [];
|
|
131
|
+
const newAdjustIndex = [];
|
|
132
|
+
function getDisplayObj(item, idKey, emptyObjDisplay) {
|
|
133
|
+
const objWithoutKey = omit(item, [idKey]);
|
|
134
|
+
if (Object.keys(objWithoutKey).length === 0) return emptyObjDisplay;
|
|
135
|
+
return objWithoutKey;
|
|
136
|
+
}
|
|
137
|
+
for (const [index, item] of oldItems.entries()) if (!newItems.find((newItem) => newItem[key] === item[key])) {
|
|
138
|
+
diffs[`--${getItemKey(item, index)}`] = getDisplayObj(item, key, "removed");
|
|
139
|
+
oldAdjustIndex.push({
|
|
140
|
+
after: index,
|
|
141
|
+
delta: -1
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
for (const [index, item] of newItems.entries()) {
|
|
145
|
+
const oldItem = oldItemsMap.get(item[key]);
|
|
146
|
+
if (!oldItem) {
|
|
147
|
+
diffs[`++${getItemKey(item, index)}`] = getDisplayObj(item, key, "added");
|
|
148
|
+
newAdjustIndex.push({
|
|
149
|
+
after: index,
|
|
150
|
+
delta: 1
|
|
151
|
+
});
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const itemChanged = !deepEqual(oldItem.item, item);
|
|
155
|
+
const itemMoved = oldItem.index !== index;
|
|
156
|
+
if (itemChanged && itemMoved) diffs[`~>${getItemKey(item, null)}·[${oldItem.index} -> ${index}]`] = getDiffs(oldItem.item, item, { skipIdKey: true });
|
|
157
|
+
else {
|
|
158
|
+
if (itemChanged) diffs[`~~${getItemKey(item, index)}`] = getDiffs(oldItem.item, item, { skipIdKey: true });
|
|
159
|
+
if (itemMoved) {
|
|
160
|
+
let expectedIndex = oldItem.index;
|
|
161
|
+
for (const { after, delta } of oldAdjustIndex) if (oldItem.index > after) expectedIndex += delta;
|
|
162
|
+
for (const { after, delta } of newAdjustIndex) if (index > after) expectedIndex += delta;
|
|
163
|
+
if (expectedIndex !== index) {
|
|
164
|
+
const diffKey = `->${getItemKey(item, null)}·[${oldItem.index} -> ${index}]`;
|
|
165
|
+
diffs[diffKey] = "moved";
|
|
166
|
+
movedItems.push({
|
|
167
|
+
key: diffKey,
|
|
168
|
+
deltaAbs: Math.abs(index - oldItem.index)
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const biggestDelta = sortBy(movedItems, (item) => item.deltaAbs, "desc")[0]?.deltaAbs;
|
|
175
|
+
for (const item of movedItems) if (item.deltaAbs !== biggestDelta) delete diffs[item.key];
|
|
176
|
+
return diffs;
|
|
177
|
+
}
|
|
178
|
+
function getSimplifiedDiff(old, value, parentIs) {
|
|
179
|
+
if (isPrimitive(old) && isPrimitive(value)) {
|
|
180
|
+
if (JSON.stringify([
|
|
181
|
+
old,
|
|
182
|
+
"->",
|
|
183
|
+
value
|
|
184
|
+
]).length <= 40) return [
|
|
185
|
+
old,
|
|
186
|
+
"->",
|
|
187
|
+
value
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
if (parentIs !== "array" && Array.isArray(old) && Array.isArray(value)) {
|
|
191
|
+
const arrayDiffs = getArrayDiffs(old, value);
|
|
192
|
+
if (arrayDiffs) return arrayDiffs;
|
|
193
|
+
}
|
|
194
|
+
if (isObject(old) && isObject(value)) return getDiffs(old, value);
|
|
195
|
+
return {
|
|
196
|
+
"--old": old,
|
|
197
|
+
"++new": value
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
//#endregion
|
|
202
|
+
export { getDiffs };
|
package/dist/interpolate.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as invariant } from "./assertions
|
|
2
|
-
import { a as clampRange, i as clampMin, r as clampMax } from "./mathUtils-
|
|
1
|
+
import { i as invariant } from "./assertions--46HN4J7.mjs";
|
|
2
|
+
import { a as clampRange, i as clampMin, r as clampMax } from "./mathUtils-FkPKduxv.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/interpolate.ts
|
|
5
5
|
function mod(n, m) {
|
package/dist/mathUtils.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as clampRange, c as round, i as clampMin, l as roundToStep, n as clamp, o as fixFloatingPointNumber, r as clampMax, s as floorToStep, t as ceilToStep } from "./mathUtils-
|
|
1
|
+
import { a as clampRange, c as round, i as clampMin, l as roundToStep, n as clamp, o as fixFloatingPointNumber, r as clampMax, s as floorToStep, t as ceilToStep } from "./mathUtils-FkPKduxv.mjs";
|
|
2
2
|
|
|
3
3
|
export { ceilToStep, clamp, clampMax, clampMin, clampRange, fixFloatingPointNumber, floorToStep, round, roundToStep };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/mockList.d.ts
|
|
2
|
+
type ItemProps = {
|
|
3
|
+
index: number;
|
|
4
|
+
id: number;
|
|
5
|
+
onEvery: <T, O = undefined>(index: number, value: T, otherwise?: O) => T | O;
|
|
6
|
+
onEven: <T, O = undefined>(value: T, otherwise?: O) => T | O;
|
|
7
|
+
atIndex: <T, O = undefined>(index: number, value: T, otherwise?: O) => T | O;
|
|
8
|
+
atId: <T, O = undefined>(id: number, value: T, otherwise?: O) => T | O;
|
|
9
|
+
cycle: <V, T = V>(valuesToCycle: V[], getValue?: (v: V) => T) => T;
|
|
10
|
+
afterOrEqualIndex: <T>(index: number, value: T, otherwise?: T) => T | undefined;
|
|
11
|
+
afterOrEqualId: <T, O = undefined>(id: number, value: T, otherwise?: O) => T | O;
|
|
12
|
+
};
|
|
13
|
+
declare function mockList<T>(size: number, getItems: (itemProps: ItemProps) => T): T[];
|
|
14
|
+
//#endregion
|
|
15
|
+
export { mockList };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { i as invariant } from "./assertions--46HN4J7.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/mockList.ts
|
|
4
|
+
function mockList(size, getItems) {
|
|
5
|
+
return Array.from({ length: size }, (_, index) => getItems({
|
|
6
|
+
index,
|
|
7
|
+
id: index + 1,
|
|
8
|
+
onEvery: (everyIndex, value, otherwise) => {
|
|
9
|
+
if (index % everyIndex === 0) return value;
|
|
10
|
+
return otherwise;
|
|
11
|
+
},
|
|
12
|
+
onEven: (value, otherwise) => {
|
|
13
|
+
if (index % 2 === 0) return value;
|
|
14
|
+
return otherwise;
|
|
15
|
+
},
|
|
16
|
+
atIndex: (i, value, otherwise) => {
|
|
17
|
+
if (i === index) return value;
|
|
18
|
+
return otherwise;
|
|
19
|
+
},
|
|
20
|
+
cycle: (valuesToCycle, getValue) => {
|
|
21
|
+
const cycleValue = valuesToCycle[index % valuesToCycle.length];
|
|
22
|
+
invariant(cycleValue !== void 0);
|
|
23
|
+
return getValue ? getValue(cycleValue) : cycleValue;
|
|
24
|
+
},
|
|
25
|
+
afterOrEqualIndex: (i, value, otherwise) => {
|
|
26
|
+
if (index >= i) return value;
|
|
27
|
+
return otherwise;
|
|
28
|
+
},
|
|
29
|
+
afterOrEqualId: (id, value, otherwise) => {
|
|
30
|
+
if (index + 1 >= id) return value;
|
|
31
|
+
return otherwise;
|
|
32
|
+
},
|
|
33
|
+
atId: (id, value, otherwise) => {
|
|
34
|
+
if (index + 1 === id) return value;
|
|
35
|
+
return otherwise;
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { mockList };
|
package/dist/mutationUtils.mjs
CHANGED
package/dist/objUtils.mjs
CHANGED
package/dist/partialEqual.mjs
CHANGED
package/dist/saferTyping.d.mts
CHANGED
|
@@ -44,5 +44,10 @@ declare function __FIX_THIS_TYPING__(value: unknown): __LEGIT_ANY__;
|
|
|
44
44
|
* symbol, bigint, ...) Equivalent to `object` type
|
|
45
45
|
*/
|
|
46
46
|
type AnyNonPrimitiveValue = object;
|
|
47
|
+
/**
|
|
48
|
+
* Cast any value to a string. Use this when you have legit usage of string
|
|
49
|
+
* casting.
|
|
50
|
+
*/
|
|
51
|
+
declare function __UNSAFE_TO_STRING__(value: unknown): string;
|
|
47
52
|
//#endregion
|
|
48
|
-
export { AnyNonPrimitiveValue, EmptyObject, __FIX_THIS_CASTING__, __FIX_THIS_TYPING__, __LEGIT_ANY_CAST__, __LEGIT_ANY_FUNCTION__, __LEGIT_ANY__, __LEGIT_CAST__, __REFINE_CAST__ };
|
|
53
|
+
export { AnyNonPrimitiveValue, EmptyObject, __FIX_THIS_CASTING__, __FIX_THIS_TYPING__, __LEGIT_ANY_CAST__, __LEGIT_ANY_FUNCTION__, __LEGIT_ANY__, __LEGIT_CAST__, __REFINE_CAST__, __UNSAFE_TO_STRING__ };
|
package/dist/saferTyping.mjs
CHANGED
|
@@ -40,6 +40,13 @@ function __FIX_THIS_CASTING__(value) {
|
|
|
40
40
|
function __FIX_THIS_TYPING__(value) {
|
|
41
41
|
return value;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Cast any value to a string. Use this when you have legit usage of string
|
|
45
|
+
* casting.
|
|
46
|
+
*/
|
|
47
|
+
function __UNSAFE_TO_STRING__(value) {
|
|
48
|
+
return String(value);
|
|
49
|
+
}
|
|
43
50
|
|
|
44
51
|
//#endregion
|
|
45
|
-
export { __FIX_THIS_CASTING__, __FIX_THIS_TYPING__, __LEGIT_ANY_CAST__, __LEGIT_CAST__, __REFINE_CAST__ };
|
|
52
|
+
export { __FIX_THIS_CASTING__, __FIX_THIS_TYPING__, __LEGIT_ANY_CAST__, __LEGIT_CAST__, __REFINE_CAST__, __UNSAFE_TO_STRING__ };
|
package/dist/serializeXML.mjs
CHANGED
package/dist/stringUtils.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as truncateString, S as removeANSIColors, _ as isPathCase, a as convertToKebabCase, b as isTitleCase, c as convertToSentenceCase, d as formatNum, f as isCamelCase, g as isPascalCase, h as isKebabCase, i as convertToDotCase, l as convertToSnakeCase, m as isDotCase, n as convertToCamelCase, o as convertToPascalCase, p as isConstantCase, r as convertToConstantCase, s as convertToPathCase, t as concatStrings, u as convertToTitleCase, v as isSentenceCase, x as joinStrings, y as isSnakeCase } from "./stringUtils-
|
|
1
|
+
import { C as truncateString, S as removeANSIColors, _ as isPathCase, a as convertToKebabCase, b as isTitleCase, c as convertToSentenceCase, d as formatNum, f as isCamelCase, g as isPascalCase, h as isKebabCase, i as convertToDotCase, l as convertToSnakeCase, m as isDotCase, n as convertToCamelCase, o as convertToPascalCase, p as isConstantCase, r as convertToConstantCase, s as convertToPathCase, t as concatStrings, u as convertToTitleCase, v as isSentenceCase, x as joinStrings, y as isSnakeCase } from "./stringUtils-CUANTYJs.mjs";
|
|
2
2
|
|
|
3
3
|
export { concatStrings, convertToCamelCase, convertToConstantCase, convertToDotCase, convertToKebabCase, convertToPascalCase, convertToPathCase, convertToSentenceCase, convertToSnakeCase, convertToTitleCase, formatNum, isCamelCase, isConstantCase, isDotCase, isKebabCase, isPascalCase, isPathCase, isSentenceCase, isSnakeCase, isTitleCase, joinStrings, removeANSIColors, truncateString };
|
package/dist/testUtils.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as isPlainObject } from "./typeGuards-
|
|
2
|
-
import { o as isObject } from "./assertions
|
|
1
|
+
import { a as isPlainObject } from "./typeGuards-CjiEoecn.mjs";
|
|
2
|
+
import { o as isObject } from "./assertions--46HN4J7.mjs";
|
|
3
3
|
import { arrayWithPrevAndIndex, filterAndMap } from "./arrayUtils.mjs";
|
|
4
4
|
import { defer } from "./promiseUtils.mjs";
|
|
5
|
-
import { i as clampMin } from "./mathUtils-
|
|
6
|
-
import { t as deepEqual } from "./deepEqual-
|
|
5
|
+
import { i as clampMin } from "./mathUtils-FkPKduxv.mjs";
|
|
6
|
+
import { t as deepEqual } from "./deepEqual-Du3EHxxo.mjs";
|
|
7
7
|
import { deepReplaceValues } from "./deepReplaceValues.mjs";
|
|
8
8
|
import { filterObjectOrArrayKeys } from "./filterObjectOrArrayKeys.mjs";
|
|
9
9
|
import { omit, pick } from "./objUtils.mjs";
|
|
@@ -241,7 +241,7 @@ function waitController() {
|
|
|
241
241
|
*/
|
|
242
242
|
function compactSnapshot(value, { collapseObjects = true, maxLineLength = 100, showUndefined = false, showBooleansAs = true, replaceValues, rejectKeys, filterKeys, sortKeys, sortPatterns, ...options } = {}) {
|
|
243
243
|
let processedValue = value;
|
|
244
|
-
if (rejectKeys || filterKeys) {
|
|
244
|
+
if (rejectKeys || filterKeys || sortKeys || sortPatterns) {
|
|
245
245
|
if (isPlainObject(processedValue) || Array.isArray(processedValue)) processedValue = filterObjectOrArrayKeys(processedValue, {
|
|
246
246
|
rejectKeys,
|
|
247
247
|
filterKeys,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as castToNumber } from "./castValues-
|
|
2
|
-
import { r as clampMax } from "./mathUtils-
|
|
1
|
+
import { t as castToNumber } from "./castValues-BA2XDJkl.mjs";
|
|
2
|
+
import { r as clampMax } from "./mathUtils-FkPKduxv.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/time.ts
|
|
5
5
|
const MINUTE_AS_MS = 60 * 1e3;
|
package/dist/time.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as MINUTE_AS_MS, c as WEEK_AS_MS, d as YEAR_AS_SECS, f as dateStringOrNullToUnixMs, g as parseTimeStringToMs, h as msToTimeString, i as HOUR_AS_SECS, l as WEEK_AS_SECS, m as getUnixSeconds, n as DAY_AS_SECS, o as MONTH_AS_MS, p as durationObjToMs, r as HOUR_AS_MS, s as MONTH_AS_SECS, t as DAY_AS_MS, u as YEAR_AS_MS } from "./time-
|
|
1
|
+
import { a as MINUTE_AS_MS, c as WEEK_AS_MS, d as YEAR_AS_SECS, f as dateStringOrNullToUnixMs, g as parseTimeStringToMs, h as msToTimeString, i as HOUR_AS_SECS, l as WEEK_AS_SECS, m as getUnixSeconds, n as DAY_AS_SECS, o as MONTH_AS_MS, p as durationObjToMs, r as HOUR_AS_MS, s as MONTH_AS_SECS, t as DAY_AS_MS, u as YEAR_AS_MS } from "./time-BeJWLHQb.mjs";
|
|
2
2
|
|
|
3
3
|
export { DAY_AS_MS, DAY_AS_SECS, HOUR_AS_MS, HOUR_AS_SECS, MINUTE_AS_MS, MONTH_AS_MS, MONTH_AS_SECS, WEEK_AS_MS, WEEK_AS_SECS, YEAR_AS_MS, YEAR_AS_SECS, dateStringOrNullToUnixMs, durationObjToMs, getUnixSeconds, msToTimeString, parseTimeStringToMs };
|
package/dist/tsResult.mjs
CHANGED
package/dist/typeGuards.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as isPlainObject, i as isObject, n as isFunction, o as isPromise, r as isNonEmptyArray, s as isTruthy, t as arrayHasAtLeastXItems } from "./typeGuards-
|
|
1
|
+
import { a as isPlainObject, i as isObject, n as isFunction, o as isPromise, r as isNonEmptyArray, s as isTruthy, t as arrayHasAtLeastXItems } from "./typeGuards-CjiEoecn.mjs";
|
|
2
2
|
|
|
3
3
|
export { arrayHasAtLeastXItems, isFunction, isNonEmptyArray, isObject, isPlainObject, isPromise, isTruthy };
|
package/dist/typingFnUtils.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as isObjKey, c as objectHasKey, d as typedObjectEntries, f as typedObjectKeys, i as isNonEmptyArray, l as strictTypedObjectEntries, n as asPartialUndefinedValues, o as isSubTypeOf, p as unionsAreTheSame, r as asType, s as narrowStringToUnion, t as asNonPartial, u as typeOnRightExtendsLeftType } from "./typingFnUtils-
|
|
1
|
+
import { a as isObjKey, c as objectHasKey, d as typedObjectEntries, f as typedObjectKeys, i as isNonEmptyArray, l as strictTypedObjectEntries, n as asPartialUndefinedValues, o as isSubTypeOf, p as unionsAreTheSame, r as asType, s as narrowStringToUnion, t as asNonPartial, u as typeOnRightExtendsLeftType } from "./typingFnUtils-y_SiKalk.mjs";
|
|
2
2
|
|
|
3
3
|
export { asNonPartial, asPartialUndefinedValues, asType, isNonEmptyArray, isObjKey, isSubTypeOf, narrowStringToUnion, objectHasKey, strictTypedObjectEntries, typeOnRightExtendsLeftType, typedObjectEntries, typedObjectKeys, unionsAreTheSame };
|
package/dist/yamlStringify.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as isPlainObject, i as isObject } from "./typeGuards-
|
|
2
|
-
import { C as truncateString } from "./stringUtils-
|
|
3
|
-
import { t as bytesToHumanReadable } from "./conversions-
|
|
1
|
+
import { a as isPlainObject, i as isObject } from "./typeGuards-CjiEoecn.mjs";
|
|
2
|
+
import { C as truncateString } from "./stringUtils-CUANTYJs.mjs";
|
|
3
|
+
import { t as bytesToHumanReadable } from "./conversions-D1BTRFdQ.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/yamlStringify.ts
|
|
6
6
|
function yamlStringify(obj, { maxLineLength = 100, showUndefined, maxDepth = 50, collapseObjects = false, addRootObjSpaces = "beforeAndAfter" } = {}) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-stack/utils",
|
|
3
3
|
"description": "Universal TypeScript utilities for browser and Node.js",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.70.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"./fuzzySearch": "./dist/fuzzySearch.mjs",
|
|
39
39
|
"./getAutoIncrementId": "./dist/getAutoIncrementId.mjs",
|
|
40
40
|
"./getCompositeKey": "./dist/getCompositeKey.mjs",
|
|
41
|
+
"./getDiffs": "./dist/getDiffs.mjs",
|
|
41
42
|
"./getValueStableKey": "./dist/getValueStableKey.mjs",
|
|
42
43
|
"./hash": "./dist/hash.mjs",
|
|
43
44
|
"./interpolate": "./dist/interpolate.mjs",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"./levenshtein": "./dist/levenshtein.mjs",
|
|
49
50
|
"./matchPath": "./dist/matchPath.mjs",
|
|
50
51
|
"./mathUtils": "./dist/mathUtils.mjs",
|
|
52
|
+
"./mockList": "./dist/mockList.mjs",
|
|
51
53
|
"./mutationUtils": "./dist/mutationUtils.mjs",
|
|
52
54
|
"./objUtils": "./dist/objUtils.mjs",
|
|
53
55
|
"./parallelAsyncCalls": "./dist/parallelAsyncCalls.mjs",
|
|
@@ -122,6 +124,7 @@
|
|
|
122
124
|
"build": "tsdown",
|
|
123
125
|
"bench:deepEqual": "tsm --no-warnings benchmarks/deepEqual.ts",
|
|
124
126
|
"docs": "typedoc",
|
|
125
|
-
"docs:watch": "typedoc --watch"
|
|
127
|
+
"docs:watch": "typedoc --watch",
|
|
128
|
+
"update-exports": "node ../../scripts/updatePackageExports.ts"
|
|
126
129
|
}
|
|
127
130
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|