@appartmint/tsm-mint 0.1.9 → 0.1.10
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/util/object.cjs.js +1 -0
- package/dist/util/object.d.ts +59 -0
- package/dist/util/object.es.js +110 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function i(e,t){let r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;let n=!0;return r.forEach(u=>{e[u]!==t[u]&&(n=!1)}),n}function l(e,t){let r=!0;if(e===t)return r;try{if(Object.keys(t).length===0)return!r}catch{return!r}return Object.keys(t).forEach(n=>{r=r&&l(e[n],t[n])}),r}function o(e,t){return Object.keys(e).reduce((r,n)=>(t.includes(n)||(r[n]=e[n]),r),{})}function y(e,t){return Object.keys(e).reduce((r,n)=>(t.includes(e[n])||(r[n]=e[n]),r),{})}function h(e,t){return Object.keys(e).sort(t).reduce((r,n)=>(r[n]=e[n],r),{})}function a(e,t){return Object.keys(e).sort((r,n)=>t(e[r],e[n])).reduce((r,n)=>(r[n]=e[n],r),{})}function K(e,t){return t.reduce((r,n)=>(r[n]=e[n],r),{})}function S(e,t){return Object.keys(e).reduce((r,n)=>(t.includes(e[n])&&(r[n]=e[n]),r),{})}function m(e,t,r="id"){if(!(t!=null&&t.length))t==null||t.forEach(u=>e.push(u));else{const u=t.reduce((s,c)=>({...s,[(c==null?void 0:c[r])??""]:c}),{}),f=e.filter(s=>!u[(s==null?void 0:s[r])??""]);f==null||f.forEach(s=>{const c=e.indexOf(s);typeof c=="number"&&c!==-1&&e.splice(c,1)}),e.forEach(s=>{u[(s==null?void 0:s[r])??""]&&Object.assign(s,u[(s==null?void 0:s[r])??""])})}const n=t==null?void 0:t.filter(u=>!e.some(f=>(f==null?void 0:f[r])===(u==null?void 0:u[r])));n==null||n.forEach(u=>e.push(u))}function O(e,t){return Object.keys(e).find(r=>e[r]===t)}function A(e){if(typeof e!="object"||e===null)return e;const t=new WeakMap,r=[[e,Array.isArray(e)?[]:{}]];for(;r.length;){const[n,u,f]=r.pop();if(f!==void 0){const s=n[f];if(typeof s=="function"){u[f]=s.bind(u);continue}if(typeof s!="object"||s===null){u[f]=s;continue}if(t.has(s)){u[f]=t.get(s);continue}u[f]=Array.isArray(s)?[]:{},t.set(s,u[f]),r.push([s,u[f]])}else{if(t.set(n,u),Array.isArray(n)){n.forEach((s,c)=>{r.push([n,u,c])});continue}Object.keys(n).forEach(s=>{r.push([n,u,s])})}}return t.get(e)}exports.objectDeepClone=A;exports.objectFilterKeys=K;exports.objectFilterValues=S;exports.objectGetKeyByValue=O;exports.objectIsSuperset=l;exports.objectRemoveValues=y;exports.objectSameKeys=i;exports.objectSortKeys=h;exports.objectSortValues=a;exports.objectUpdateArray=m;exports.removeKeys=o;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true if the provided objects have the same keys
|
|
3
|
+
*/
|
|
4
|
+
export declare function objectSameKeys(obj1: any, obj2: any): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Returns true if the first object has at least the same
|
|
7
|
+
* entries as the second object
|
|
8
|
+
* @param superset - the object to check
|
|
9
|
+
* @param subset - the object whose entries are required
|
|
10
|
+
* @returns - true if the first object is a superset of the second
|
|
11
|
+
*/
|
|
12
|
+
export declare function objectIsSuperset(superset: any, subset: any): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Removes object entries by key
|
|
15
|
+
* @param object - the object to remove entries from
|
|
16
|
+
* @param keys - the keys to remove
|
|
17
|
+
*/
|
|
18
|
+
export declare function removeKeys(object: any, keys: string[]): any;
|
|
19
|
+
/**
|
|
20
|
+
* Removes object entries by value
|
|
21
|
+
*/
|
|
22
|
+
export declare function objectRemoveValues(object: any, values: any[]): any;
|
|
23
|
+
/**
|
|
24
|
+
* Sorts an object's entries alphabetically by key
|
|
25
|
+
*/
|
|
26
|
+
export declare function objectSortKeys(object: any, compareFn?: (a: string, b: string) => number): any;
|
|
27
|
+
/**
|
|
28
|
+
* Sorts an object's entries alphabetically by value
|
|
29
|
+
*/
|
|
30
|
+
export declare function objectSortValues(object: any, compareFn: (a: any, b: any) => number): any;
|
|
31
|
+
/**
|
|
32
|
+
* Filters an object by its keys
|
|
33
|
+
* @param object - the object to filter
|
|
34
|
+
* @param keys - the keys to keep
|
|
35
|
+
* @returns - the filtered object
|
|
36
|
+
*/
|
|
37
|
+
export declare function objectFilterKeys(object: any, keys: string[]): Object;
|
|
38
|
+
/**
|
|
39
|
+
* Filters an object by its values
|
|
40
|
+
* @param object - the object to filter
|
|
41
|
+
* @param values - the values to keep
|
|
42
|
+
* @returns - the filtered object
|
|
43
|
+
*/
|
|
44
|
+
export declare function objectFilterValues(object: any, values: any[]): Object;
|
|
45
|
+
/**
|
|
46
|
+
* Update two sets of objects
|
|
47
|
+
* @param original - the original object
|
|
48
|
+
* @param update - the object to update the original with
|
|
49
|
+
* @returns - the original objects with updated data from the update
|
|
50
|
+
*/
|
|
51
|
+
export declare function objectUpdateArray(original: any[], update?: any[], key?: string): any;
|
|
52
|
+
/**
|
|
53
|
+
* Get an object's key by value
|
|
54
|
+
*/
|
|
55
|
+
export declare function objectGetKeyByValue(object: any, value: any): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Create a deep copy of an object
|
|
58
|
+
*/
|
|
59
|
+
export declare function objectDeepClone<T>(object: T): T;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
function l(r, u) {
|
|
2
|
+
let n = Object.keys(r);
|
|
3
|
+
if (n.length !== Object.keys(u).length)
|
|
4
|
+
return !1;
|
|
5
|
+
let e = !0;
|
|
6
|
+
return n.forEach((s) => {
|
|
7
|
+
r[s] !== u[s] && (e = !1);
|
|
8
|
+
}), e;
|
|
9
|
+
}
|
|
10
|
+
function c(r, u) {
|
|
11
|
+
let n = !0;
|
|
12
|
+
if (r === u)
|
|
13
|
+
return n;
|
|
14
|
+
try {
|
|
15
|
+
if (Object.keys(u).length === 0)
|
|
16
|
+
return !n;
|
|
17
|
+
} catch {
|
|
18
|
+
return !n;
|
|
19
|
+
}
|
|
20
|
+
return Object.keys(u).forEach((e) => {
|
|
21
|
+
n = n && c(r[e], u[e]);
|
|
22
|
+
}), n;
|
|
23
|
+
}
|
|
24
|
+
function h(r, u) {
|
|
25
|
+
return Object.keys(r).reduce((n, e) => (u.includes(e) || (n[e] = r[e]), n), {});
|
|
26
|
+
}
|
|
27
|
+
function y(r, u) {
|
|
28
|
+
return Object.keys(r).reduce((n, e) => (u.includes(r[e]) || (n[e] = r[e]), n), {});
|
|
29
|
+
}
|
|
30
|
+
function a(r, u) {
|
|
31
|
+
return Object.keys(r).sort(u).reduce((n, e) => (n[e] = r[e], n), {});
|
|
32
|
+
}
|
|
33
|
+
function o(r, u) {
|
|
34
|
+
return Object.keys(r).sort((n, e) => u(r[n], r[e])).reduce((n, e) => (n[e] = r[e], n), {});
|
|
35
|
+
}
|
|
36
|
+
function E(r, u) {
|
|
37
|
+
return u.reduce((n, e) => (n[e] = r[e], n), {});
|
|
38
|
+
}
|
|
39
|
+
function O(r, u) {
|
|
40
|
+
return Object.keys(r).reduce((n, e) => (u.includes(r[e]) && (n[e] = r[e]), n), {});
|
|
41
|
+
}
|
|
42
|
+
function A(r, u, n = "id") {
|
|
43
|
+
if (!(u != null && u.length))
|
|
44
|
+
u == null || u.forEach((s) => r.push(s));
|
|
45
|
+
else {
|
|
46
|
+
const s = u.reduce((f, i) => ({
|
|
47
|
+
...f,
|
|
48
|
+
[(i == null ? void 0 : i[n]) ?? ""]: i
|
|
49
|
+
}), {}), t = r.filter((f) => !s[(f == null ? void 0 : f[n]) ?? ""]);
|
|
50
|
+
t == null || t.forEach((f) => {
|
|
51
|
+
const i = r.indexOf(f);
|
|
52
|
+
typeof i == "number" && i !== -1 && r.splice(i, 1);
|
|
53
|
+
}), r.forEach((f) => {
|
|
54
|
+
s[(f == null ? void 0 : f[n]) ?? ""] && Object.assign(f, s[(f == null ? void 0 : f[n]) ?? ""]);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const e = u == null ? void 0 : u.filter((s) => !r.some((t) => (t == null ? void 0 : t[n]) === (s == null ? void 0 : s[n])));
|
|
58
|
+
e == null || e.forEach((s) => r.push(s));
|
|
59
|
+
}
|
|
60
|
+
function K(r, u) {
|
|
61
|
+
return Object.keys(r).find((n) => r[n] === u);
|
|
62
|
+
}
|
|
63
|
+
function m(r) {
|
|
64
|
+
if (typeof r != "object" || r === null)
|
|
65
|
+
return r;
|
|
66
|
+
const u = /* @__PURE__ */ new WeakMap(), n = [[r, Array.isArray(r) ? [] : {}]];
|
|
67
|
+
for (; n.length; ) {
|
|
68
|
+
const [e, s, t] = n.pop();
|
|
69
|
+
if (t !== void 0) {
|
|
70
|
+
const f = e[t];
|
|
71
|
+
if (typeof f == "function") {
|
|
72
|
+
s[t] = f.bind(s);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (typeof f != "object" || f === null) {
|
|
76
|
+
s[t] = f;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (u.has(f)) {
|
|
80
|
+
s[t] = u.get(f);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
s[t] = Array.isArray(f) ? [] : {}, u.set(f, s[t]), n.push([f, s[t]]);
|
|
84
|
+
} else {
|
|
85
|
+
if (u.set(e, s), Array.isArray(e)) {
|
|
86
|
+
e.forEach((f, i) => {
|
|
87
|
+
n.push([e, s, i]);
|
|
88
|
+
});
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
Object.keys(e).forEach((f) => {
|
|
92
|
+
n.push([e, s, f]);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return u.get(r);
|
|
97
|
+
}
|
|
98
|
+
export {
|
|
99
|
+
m as objectDeepClone,
|
|
100
|
+
E as objectFilterKeys,
|
|
101
|
+
O as objectFilterValues,
|
|
102
|
+
K as objectGetKeyByValue,
|
|
103
|
+
c as objectIsSuperset,
|
|
104
|
+
y as objectRemoveValues,
|
|
105
|
+
l as objectSameKeys,
|
|
106
|
+
a as objectSortKeys,
|
|
107
|
+
o as objectSortValues,
|
|
108
|
+
A as objectUpdateArray,
|
|
109
|
+
h as removeKeys
|
|
110
|
+
};
|