@t007/utils 0.0.12 → 0.0.13
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/index.cjs +20 -19
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +19 -18
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -37,9 +37,9 @@ __export(index_exports, {
|
|
|
37
37
|
isIter: () => isIter,
|
|
38
38
|
isNum: () => isNum,
|
|
39
39
|
isObj: () => isObj,
|
|
40
|
+
isPOJO: () => isPOJO,
|
|
40
41
|
isSameURL: () => isSameURL,
|
|
41
42
|
isStr: () => isStr,
|
|
42
|
-
isStrictObj: () => isStrictObj,
|
|
43
43
|
isSym: () => isSym,
|
|
44
44
|
loadResource: () => loadResource,
|
|
45
45
|
onAllMethods: () => onAllMethods,
|
|
@@ -70,7 +70,7 @@ function isArr(obj) {
|
|
|
70
70
|
function isObj(obj, arraycheck = true) {
|
|
71
71
|
return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function isPOJO(obj, crossRealms = false, typecheck = true) {
|
|
74
74
|
return (typecheck ? isObj(obj, false) : true) && (crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
|
|
75
75
|
}
|
|
76
76
|
function isIter(obj) {
|
|
@@ -83,20 +83,6 @@ function inBoolArrOpt(opt, str) {
|
|
|
83
83
|
return opt?.includes?.(str) ?? opt;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
// src/core/str.ts
|
|
87
|
-
function uid(prefix = "") {
|
|
88
|
-
return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
|
|
89
|
-
}
|
|
90
|
-
function isSameURL(src1, src2) {
|
|
91
|
-
if (!isStr(src1) || !isStr(src2) || !src1 || !src2) return false;
|
|
92
|
-
try {
|
|
93
|
-
const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
|
|
94
|
-
return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
|
|
95
|
-
} catch {
|
|
96
|
-
return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
86
|
// src/core/dom.ts
|
|
101
87
|
function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
|
|
102
88
|
return assignEl(el, props, dataset, styles), el;
|
|
@@ -147,15 +133,30 @@ function clamp(min = 0, val, max = Infinity) {
|
|
|
147
133
|
return Math.min(Math.max(val, min), max);
|
|
148
134
|
}
|
|
149
135
|
|
|
136
|
+
// src/core/str.ts
|
|
137
|
+
function uid(prefix = "") {
|
|
138
|
+
return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
|
|
139
|
+
}
|
|
140
|
+
function isSameURL(src1, src2) {
|
|
141
|
+
if (!isStr(src1) || !isStr(src2) || !src1 || !src2) return false;
|
|
142
|
+
try {
|
|
143
|
+
const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
|
|
144
|
+
return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
|
|
145
|
+
} catch {
|
|
146
|
+
return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
150
|
// src/mixins/methodist.ts
|
|
151
|
-
function onAllMethods(owner, callback) {
|
|
151
|
+
function onAllMethods(owner, callback, skipNestedOwn = true, nested = false) {
|
|
152
152
|
let proto = owner;
|
|
153
153
|
while (proto && proto !== Object.prototype) {
|
|
154
154
|
for (const method of Object.getOwnPropertyNames(proto)) {
|
|
155
155
|
if (method === "constructor") continue;
|
|
156
|
+
if (nested && skipNestedOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
|
|
156
157
|
if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) callback(method, owner);
|
|
157
158
|
}
|
|
158
|
-
proto = Object.getPrototypeOf(proto);
|
|
159
|
+
proto = Object.getPrototypeOf(proto), nested = true;
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
function bindAllMethods(owner) {
|
|
@@ -297,9 +298,9 @@ if (isDef(window)) {
|
|
|
297
298
|
isIter,
|
|
298
299
|
isNum,
|
|
299
300
|
isObj,
|
|
301
|
+
isPOJO,
|
|
300
302
|
isSameURL,
|
|
301
303
|
isStr,
|
|
302
|
-
isStrictObj,
|
|
303
304
|
isSym,
|
|
304
305
|
loadResource,
|
|
305
306
|
onAllMethods,
|
package/dist/index.d.cts
CHANGED
|
@@ -57,7 +57,7 @@ declare function isNum<T extends number = number>(val: any): val is T;
|
|
|
57
57
|
declare function isStr<T extends string = string>(val: any): val is T;
|
|
58
58
|
declare function isArr<T = unknown>(obj: any): obj is T[];
|
|
59
59
|
declare function isObj<T extends object = object>(obj: any, arraycheck?: boolean): obj is T;
|
|
60
|
-
declare function
|
|
60
|
+
declare function isPOJO<T extends object = object>(obj: any, crossRealms?: boolean, typecheck?: boolean): obj is T;
|
|
61
61
|
declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
|
|
62
62
|
declare function isFunc<T extends Function = Function>(val: any): val is T;
|
|
63
63
|
declare function inBoolArrOpt(opt: any, str: string): boolean;
|
|
@@ -88,9 +88,9 @@ declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>,
|
|
|
88
88
|
declare const VIRTUAL_RESOURCE: unique symbol;
|
|
89
89
|
declare function loadResource(req: string | symbol, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, w?: Window & typeof globalThis): Promise<HTMLElement | void>;
|
|
90
90
|
|
|
91
|
-
declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void): void;
|
|
91
|
+
declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void, skipNestedOwn?: boolean, nested?: boolean): void;
|
|
92
92
|
declare function bindAllMethods(owner: any): void;
|
|
93
93
|
declare function guardAllMethods(owner: any, guardFn?: (fn: Function) => Function, bound?: boolean): void;
|
|
94
94
|
declare function guardMethod<T extends Function>(fn: T, onError?: (e: any) => void): T;
|
|
95
95
|
|
|
96
|
-
export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isBool, isDef, isFunc, isIter, isNum, isObj, isSameURL, isStr,
|
|
96
|
+
export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isBool, isDef, isFunc, isIter, isNum, isObj, isPOJO, isSameURL, isStr, isSym, loadResource, onAllMethods, removeScrollAssist, uid };
|
package/dist/index.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ declare function isNum<T extends number = number>(val: any): val is T;
|
|
|
57
57
|
declare function isStr<T extends string = string>(val: any): val is T;
|
|
58
58
|
declare function isArr<T = unknown>(obj: any): obj is T[];
|
|
59
59
|
declare function isObj<T extends object = object>(obj: any, arraycheck?: boolean): obj is T;
|
|
60
|
-
declare function
|
|
60
|
+
declare function isPOJO<T extends object = object>(obj: any, crossRealms?: boolean, typecheck?: boolean): obj is T;
|
|
61
61
|
declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
|
|
62
62
|
declare function isFunc<T extends Function = Function>(val: any): val is T;
|
|
63
63
|
declare function inBoolArrOpt(opt: any, str: string): boolean;
|
|
@@ -88,9 +88,9 @@ declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>,
|
|
|
88
88
|
declare const VIRTUAL_RESOURCE: unique symbol;
|
|
89
89
|
declare function loadResource(req: string | symbol, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, w?: Window & typeof globalThis): Promise<HTMLElement | void>;
|
|
90
90
|
|
|
91
|
-
declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void): void;
|
|
91
|
+
declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void, skipNestedOwn?: boolean, nested?: boolean): void;
|
|
92
92
|
declare function bindAllMethods(owner: any): void;
|
|
93
93
|
declare function guardAllMethods(owner: any, guardFn?: (fn: Function) => Function, bound?: boolean): void;
|
|
94
94
|
declare function guardMethod<T extends Function>(fn: T, onError?: (e: any) => void): T;
|
|
95
95
|
|
|
96
|
-
export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isBool, isDef, isFunc, isIter, isNum, isObj, isSameURL, isStr,
|
|
96
|
+
export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isBool, isDef, isFunc, isIter, isNum, isObj, isPOJO, isSameURL, isStr, isSym, loadResource, onAllMethods, removeScrollAssist, uid };
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,7 @@ function isArr(obj) {
|
|
|
20
20
|
function isObj(obj, arraycheck = true) {
|
|
21
21
|
return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function isPOJO(obj, crossRealms = false, typecheck = true) {
|
|
24
24
|
return (typecheck ? isObj(obj, false) : true) && (crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
|
|
25
25
|
}
|
|
26
26
|
function isIter(obj) {
|
|
@@ -33,20 +33,6 @@ function inBoolArrOpt(opt, str) {
|
|
|
33
33
|
return opt?.includes?.(str) ?? opt;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
// src/core/str.ts
|
|
37
|
-
function uid(prefix = "") {
|
|
38
|
-
return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
|
|
39
|
-
}
|
|
40
|
-
function isSameURL(src1, src2) {
|
|
41
|
-
if (!isStr(src1) || !isStr(src2) || !src1 || !src2) return false;
|
|
42
|
-
try {
|
|
43
|
-
const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
|
|
44
|
-
return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
|
|
45
|
-
} catch {
|
|
46
|
-
return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
36
|
// src/core/dom.ts
|
|
51
37
|
function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
|
|
52
38
|
return assignEl(el, props, dataset, styles), el;
|
|
@@ -97,15 +83,30 @@ function clamp(min = 0, val, max = Infinity) {
|
|
|
97
83
|
return Math.min(Math.max(val, min), max);
|
|
98
84
|
}
|
|
99
85
|
|
|
86
|
+
// src/core/str.ts
|
|
87
|
+
function uid(prefix = "") {
|
|
88
|
+
return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
|
|
89
|
+
}
|
|
90
|
+
function isSameURL(src1, src2) {
|
|
91
|
+
if (!isStr(src1) || !isStr(src2) || !src1 || !src2) return false;
|
|
92
|
+
try {
|
|
93
|
+
const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
|
|
94
|
+
return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
|
|
95
|
+
} catch {
|
|
96
|
+
return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
100
|
// src/mixins/methodist.ts
|
|
101
|
-
function onAllMethods(owner, callback) {
|
|
101
|
+
function onAllMethods(owner, callback, skipNestedOwn = true, nested = false) {
|
|
102
102
|
let proto = owner;
|
|
103
103
|
while (proto && proto !== Object.prototype) {
|
|
104
104
|
for (const method of Object.getOwnPropertyNames(proto)) {
|
|
105
105
|
if (method === "constructor") continue;
|
|
106
|
+
if (nested && skipNestedOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
|
|
106
107
|
if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) callback(method, owner);
|
|
107
108
|
}
|
|
108
|
-
proto = Object.getPrototypeOf(proto);
|
|
109
|
+
proto = Object.getPrototypeOf(proto), nested = true;
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
function bindAllMethods(owner) {
|
|
@@ -246,9 +247,9 @@ export {
|
|
|
246
247
|
isIter,
|
|
247
248
|
isNum,
|
|
248
249
|
isObj,
|
|
250
|
+
isPOJO,
|
|
249
251
|
isSameURL,
|
|
250
252
|
isStr,
|
|
251
|
-
isStrictObj,
|
|
252
253
|
isSym,
|
|
253
254
|
loadResource,
|
|
254
255
|
onAllMethods,
|
package/package.json
CHANGED