@8ms/helpers 2.3.9 → 2.3.11
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/.yarn/install-state.gz +0 -0
- package/dist/lodash/index.d.mts +18 -1
- package/dist/lodash/index.mjs +88 -1
- package/package.json +1 -1
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/dist/lodash/index.d.mts
CHANGED
|
@@ -7,13 +7,30 @@ declare const trim: (str: string, chars?: string) => string;
|
|
|
7
7
|
//#region src/lodash/isDate.d.ts
|
|
8
8
|
declare const isDate: (value: unknown) => value is Date;
|
|
9
9
|
//#endregion
|
|
10
|
+
//#region src/lodash/isEmpty.d.ts
|
|
11
|
+
declare const isEmpty: (value: unknown) => boolean;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/lodash/isEqual.d.ts
|
|
14
|
+
declare const isEqual: (a: unknown, b: unknown) => boolean;
|
|
15
|
+
//#endregion
|
|
10
16
|
//#region src/lodash/isObject.d.ts
|
|
11
17
|
declare const isObject: (value: unknown) => value is object;
|
|
12
18
|
//#endregion
|
|
13
19
|
//#region src/lodash/merge.d.ts
|
|
14
20
|
declare const merge: <T extends object>(target: T, ...sources: any[]) => T;
|
|
15
21
|
//#endregion
|
|
22
|
+
//#region src/lodash/orderBy.d.ts
|
|
23
|
+
type OrderDirection = "asc" | "desc";
|
|
24
|
+
type Iteratee<T> = ((item: T) => unknown) | string;
|
|
25
|
+
declare const orderBy: <T>(collection: T[], iteratees: Iteratee<T> | Iteratee<T>[], orders?: OrderDirection | OrderDirection[]) => T[];
|
|
26
|
+
//#endregion
|
|
16
27
|
//#region src/lodash/unescape.d.ts
|
|
17
28
|
declare const unescape: (str: string) => string;
|
|
18
29
|
//#endregion
|
|
19
|
-
|
|
30
|
+
//#region src/lodash/uniq.d.ts
|
|
31
|
+
declare const uniq: (arr: any[]) => any[];
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/lodash/uniqBy.d.ts
|
|
34
|
+
declare const uniqBy: <T>(collection: T[], iteratee: ((item: T) => unknown) | string) => T[];
|
|
35
|
+
//#endregion
|
|
36
|
+
export { isDate, isEmpty, isEqual, isObject, merge, orderBy, set, trim, unescape, uniq, uniqBy };
|
package/dist/lodash/index.mjs
CHANGED
|
@@ -29,6 +29,49 @@ const isDate = (value) => {
|
|
|
29
29
|
return value instanceof Date && !isNaN(value.getTime());
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/lodash/isEmpty.ts
|
|
34
|
+
const isEmpty = (value) => {
|
|
35
|
+
if (value == null) return true;
|
|
36
|
+
if (typeof value === "boolean" || typeof value === "number") return true;
|
|
37
|
+
if (typeof value === "string" || Array.isArray(value)) return value.length === 0;
|
|
38
|
+
if (value instanceof Map || value instanceof Set) return value.size === 0;
|
|
39
|
+
if (typeof value === "object") return Object.keys(value).length === 0;
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/lodash/isEqual.ts
|
|
45
|
+
const isEqual = (a, b) => {
|
|
46
|
+
if (a === b) return true;
|
|
47
|
+
if (a == null || b == null) return a === b;
|
|
48
|
+
if (typeof a !== typeof b) return false;
|
|
49
|
+
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
|
|
50
|
+
if (a instanceof RegExp && b instanceof RegExp) return a.toString() === b.toString();
|
|
51
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
52
|
+
if (a.length !== b.length) return false;
|
|
53
|
+
return a.every((item, i) => isEqual(item, b[i]));
|
|
54
|
+
}
|
|
55
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
56
|
+
if (a instanceof Map && b instanceof Map) {
|
|
57
|
+
if (a.size !== b.size) return false;
|
|
58
|
+
for (const [key, val] of a) if (!b.has(key) || !isEqual(val, b.get(key))) return false;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (a instanceof Set && b instanceof Set) {
|
|
62
|
+
if (a.size !== b.size) return false;
|
|
63
|
+
for (const val of a) if (!b.has(val)) return false;
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
67
|
+
const keysA = Object.keys(a);
|
|
68
|
+
const keysB = Object.keys(b);
|
|
69
|
+
if (keysA.length !== keysB.length) return false;
|
|
70
|
+
return keysA.every((key) => Object.prototype.hasOwnProperty.call(b, key) && isEqual(a[key], b[key]));
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
};
|
|
74
|
+
|
|
32
75
|
//#endregion
|
|
33
76
|
//#region src/lodash/isObject.ts
|
|
34
77
|
const isObject = (value) => {
|
|
@@ -56,6 +99,30 @@ const merge = (target, ...sources) => {
|
|
|
56
99
|
return target;
|
|
57
100
|
};
|
|
58
101
|
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/lodash/orderBy.ts
|
|
104
|
+
const orderBy = (collection, iteratees, orders = "asc") => {
|
|
105
|
+
const keys = Array.isArray(iteratees) ? iteratees : [iteratees];
|
|
106
|
+
const dirs = Array.isArray(orders) ? orders : [orders];
|
|
107
|
+
const getValue = (item, key) => {
|
|
108
|
+
if (typeof key === "function") return key(item);
|
|
109
|
+
return key.split(".").reduce((acc, part) => acc?.[part], item);
|
|
110
|
+
};
|
|
111
|
+
return [...collection].sort((a, b) => {
|
|
112
|
+
for (let i = 0; i < keys.length; i++) {
|
|
113
|
+
const dir = dirs[i] === "desc" ? -1 : 1;
|
|
114
|
+
const aVal = getValue(a, keys[i]);
|
|
115
|
+
const bVal = getValue(b, keys[i]);
|
|
116
|
+
if (aVal === bVal) continue;
|
|
117
|
+
if (aVal == null) return 1;
|
|
118
|
+
if (bVal == null) return -1;
|
|
119
|
+
if (typeof aVal === "string" && typeof bVal === "string") return aVal.localeCompare(bVal) * dir;
|
|
120
|
+
return (aVal < bVal ? -1 : 1) * dir;
|
|
121
|
+
}
|
|
122
|
+
return 0;
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
59
126
|
//#endregion
|
|
60
127
|
//#region src/lodash/unescape.ts
|
|
61
128
|
const unescape = (str) => {
|
|
@@ -70,4 +137,24 @@ const unescape = (str) => {
|
|
|
70
137
|
};
|
|
71
138
|
|
|
72
139
|
//#endregion
|
|
73
|
-
|
|
140
|
+
//#region src/lodash/uniq.ts
|
|
141
|
+
const uniq = (arr) => [...new Set(arr)];
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/lodash/uniqBy.ts
|
|
145
|
+
const uniqBy = (collection, iteratee) => {
|
|
146
|
+
const seen = /* @__PURE__ */ new Set();
|
|
147
|
+
const getValue = (item) => {
|
|
148
|
+
if (typeof iteratee === "function") return iteratee(item);
|
|
149
|
+
return iteratee.split(".").reduce((acc, part) => acc?.[part], item);
|
|
150
|
+
};
|
|
151
|
+
return collection.filter((item) => {
|
|
152
|
+
const key = getValue(item);
|
|
153
|
+
if (seen.has(key)) return false;
|
|
154
|
+
seen.add(key);
|
|
155
|
+
return true;
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
160
|
+
export { isDate, isEmpty, isEqual, isObject, merge, orderBy, set, trim, unescape, uniq, uniqBy };
|