@t007/utils 0.0.11 → 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 +31 -23
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +27 -19
- package/package.json +2 -5
package/dist/index.cjs
CHANGED
|
@@ -32,14 +32,14 @@ __export(index_exports, {
|
|
|
32
32
|
initVScrollerator: () => initVScrollerator,
|
|
33
33
|
isArr: () => isArr,
|
|
34
34
|
isBool: () => isBool,
|
|
35
|
-
isDef: () =>
|
|
35
|
+
isDef: () => isDef,
|
|
36
36
|
isFunc: () => isFunc,
|
|
37
37
|
isIter: () => isIter,
|
|
38
38
|
isNum: () => isNum,
|
|
39
|
-
isObj: () =>
|
|
39
|
+
isObj: () => isObj,
|
|
40
|
+
isPOJO: () => isPOJO,
|
|
40
41
|
isSameURL: () => isSameURL,
|
|
41
42
|
isStr: () => isStr,
|
|
42
|
-
isStrictObj: () => import_utils2.isStrictObj,
|
|
43
43
|
isSym: () => isSym,
|
|
44
44
|
loadResource: () => loadResource,
|
|
45
45
|
onAllMethods: () => onAllMethods,
|
|
@@ -49,8 +49,9 @@ __export(index_exports, {
|
|
|
49
49
|
module.exports = __toCommonJS(index_exports);
|
|
50
50
|
|
|
51
51
|
// src/core/obj.ts
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
function isDef(val) {
|
|
53
|
+
return "undefined" !== typeof val;
|
|
54
|
+
}
|
|
54
55
|
function isSym(val) {
|
|
55
56
|
return "symbol" === typeof val;
|
|
56
57
|
}
|
|
@@ -66,6 +67,12 @@ function isStr(val) {
|
|
|
66
67
|
function isArr(obj) {
|
|
67
68
|
return Array.isArray(obj);
|
|
68
69
|
}
|
|
70
|
+
function isObj(obj, arraycheck = true) {
|
|
71
|
+
return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
|
|
72
|
+
}
|
|
73
|
+
function isPOJO(obj, crossRealms = false, typecheck = true) {
|
|
74
|
+
return (typecheck ? isObj(obj, false) : true) && (crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
|
|
75
|
+
}
|
|
69
76
|
function isIter(obj) {
|
|
70
77
|
return obj != null && "function" === typeof obj[Symbol.iterator];
|
|
71
78
|
}
|
|
@@ -76,20 +83,6 @@ function inBoolArrOpt(opt, str) {
|
|
|
76
83
|
return opt?.includes?.(str) ?? opt;
|
|
77
84
|
}
|
|
78
85
|
|
|
79
|
-
// src/core/str.ts
|
|
80
|
-
function uid(prefix = "") {
|
|
81
|
-
return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
|
|
82
|
-
}
|
|
83
|
-
function isSameURL(src1, src2) {
|
|
84
|
-
if (!isStr(src1) || !isStr(src2) || !src1 || !src2) return false;
|
|
85
|
-
try {
|
|
86
|
-
const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
|
|
87
|
-
return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
|
|
88
|
-
} catch {
|
|
89
|
-
return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
86
|
// src/core/dom.ts
|
|
94
87
|
function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
|
|
95
88
|
return assignEl(el, props, dataset, styles), el;
|
|
@@ -140,15 +133,30 @@ function clamp(min = 0, val, max = Infinity) {
|
|
|
140
133
|
return Math.min(Math.max(val, min), max);
|
|
141
134
|
}
|
|
142
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
|
+
|
|
143
150
|
// src/mixins/methodist.ts
|
|
144
|
-
function onAllMethods(owner, callback) {
|
|
151
|
+
function onAllMethods(owner, callback, skipNestedOwn = true, nested = false) {
|
|
145
152
|
let proto = owner;
|
|
146
153
|
while (proto && proto !== Object.prototype) {
|
|
147
154
|
for (const method of Object.getOwnPropertyNames(proto)) {
|
|
148
155
|
if (method === "constructor") continue;
|
|
156
|
+
if (nested && skipNestedOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
|
|
149
157
|
if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) callback(method, owner);
|
|
150
158
|
}
|
|
151
|
-
proto = Object.getPrototypeOf(proto);
|
|
159
|
+
proto = Object.getPrototypeOf(proto), nested = true;
|
|
152
160
|
}
|
|
153
161
|
}
|
|
154
162
|
function bindAllMethods(owner) {
|
|
@@ -261,7 +269,7 @@ function initScrollAssist(el, { pxPerSecond = 80, assistClassName = "tmg-video-c
|
|
|
261
269
|
var removeScrollAssist = (el) => t007._scrollers.get(el)?.destroy();
|
|
262
270
|
|
|
263
271
|
// src/index.ts
|
|
264
|
-
if (
|
|
272
|
+
if (isDef(window)) {
|
|
265
273
|
window.t007 ??= {};
|
|
266
274
|
t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
|
|
267
275
|
window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
|
|
@@ -290,9 +298,9 @@ if ((0, import_utils.isDef)(window)) {
|
|
|
290
298
|
isIter,
|
|
291
299
|
isNum,
|
|
292
300
|
isObj,
|
|
301
|
+
isPOJO,
|
|
293
302
|
isSameURL,
|
|
294
303
|
isStr,
|
|
295
|
-
isStrictObj,
|
|
296
304
|
isSym,
|
|
297
305
|
loadResource,
|
|
298
306
|
onAllMethods,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { isDef, isObj, isStrictObj } from 'sia-reactor/utils';
|
|
2
|
-
|
|
3
1
|
interface ScrolleratorOptions {
|
|
4
2
|
baseSpeed?: number;
|
|
5
3
|
maxSpeed?: number;
|
|
@@ -52,12 +50,14 @@ declare global {
|
|
|
52
50
|
var t007: T007Namespace;
|
|
53
51
|
}
|
|
54
52
|
|
|
53
|
+
declare function isDef(val: any): boolean;
|
|
55
54
|
declare function isSym<T extends symbol = symbol>(val: any): val is T;
|
|
56
55
|
declare function isBool<T extends boolean = boolean>(val: any): val is T;
|
|
57
56
|
declare function isNum<T extends number = number>(val: any): val is T;
|
|
58
57
|
declare function isStr<T extends string = string>(val: any): val is T;
|
|
59
58
|
declare function isArr<T = unknown>(obj: any): obj is T[];
|
|
60
|
-
|
|
59
|
+
declare function isObj<T extends object = object>(obj: any, arraycheck?: boolean): obj is T;
|
|
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, isFunc, isIter, isNum, isSameURL, isStr, isSym, loadResource, onAllMethods, removeScrollAssist, uid };
|
|
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
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { isDef, isObj, isStrictObj } from 'sia-reactor/utils';
|
|
2
|
-
|
|
3
1
|
interface ScrolleratorOptions {
|
|
4
2
|
baseSpeed?: number;
|
|
5
3
|
maxSpeed?: number;
|
|
@@ -52,12 +50,14 @@ declare global {
|
|
|
52
50
|
var t007: T007Namespace;
|
|
53
51
|
}
|
|
54
52
|
|
|
53
|
+
declare function isDef(val: any): boolean;
|
|
55
54
|
declare function isSym<T extends symbol = symbol>(val: any): val is T;
|
|
56
55
|
declare function isBool<T extends boolean = boolean>(val: any): val is T;
|
|
57
56
|
declare function isNum<T extends number = number>(val: any): val is T;
|
|
58
57
|
declare function isStr<T extends string = string>(val: any): val is T;
|
|
59
58
|
declare function isArr<T = unknown>(obj: any): obj is T[];
|
|
60
|
-
|
|
59
|
+
declare function isObj<T extends object = object>(obj: any, arraycheck?: boolean): obj is T;
|
|
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, isFunc, isIter, isNum, isSameURL, isStr, isSym, loadResource, onAllMethods, removeScrollAssist, uid };
|
|
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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/core/obj.ts
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
function isDef(val) {
|
|
3
|
+
return "undefined" !== typeof val;
|
|
4
|
+
}
|
|
4
5
|
function isSym(val) {
|
|
5
6
|
return "symbol" === typeof val;
|
|
6
7
|
}
|
|
@@ -16,6 +17,12 @@ function isStr(val) {
|
|
|
16
17
|
function isArr(obj) {
|
|
17
18
|
return Array.isArray(obj);
|
|
18
19
|
}
|
|
20
|
+
function isObj(obj, arraycheck = true) {
|
|
21
|
+
return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
|
|
22
|
+
}
|
|
23
|
+
function isPOJO(obj, crossRealms = false, typecheck = true) {
|
|
24
|
+
return (typecheck ? isObj(obj, false) : true) && (crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
|
|
25
|
+
}
|
|
19
26
|
function isIter(obj) {
|
|
20
27
|
return obj != null && "function" === typeof obj[Symbol.iterator];
|
|
21
28
|
}
|
|
@@ -26,20 +33,6 @@ function inBoolArrOpt(opt, str) {
|
|
|
26
33
|
return opt?.includes?.(str) ?? opt;
|
|
27
34
|
}
|
|
28
35
|
|
|
29
|
-
// src/core/str.ts
|
|
30
|
-
function uid(prefix = "") {
|
|
31
|
-
return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
|
|
32
|
-
}
|
|
33
|
-
function isSameURL(src1, src2) {
|
|
34
|
-
if (!isStr(src1) || !isStr(src2) || !src1 || !src2) return false;
|
|
35
|
-
try {
|
|
36
|
-
const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
|
|
37
|
-
return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
|
|
38
|
-
} catch {
|
|
39
|
-
return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
36
|
// src/core/dom.ts
|
|
44
37
|
function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
|
|
45
38
|
return assignEl(el, props, dataset, styles), el;
|
|
@@ -90,15 +83,30 @@ function clamp(min = 0, val, max = Infinity) {
|
|
|
90
83
|
return Math.min(Math.max(val, min), max);
|
|
91
84
|
}
|
|
92
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
|
+
|
|
93
100
|
// src/mixins/methodist.ts
|
|
94
|
-
function onAllMethods(owner, callback) {
|
|
101
|
+
function onAllMethods(owner, callback, skipNestedOwn = true, nested = false) {
|
|
95
102
|
let proto = owner;
|
|
96
103
|
while (proto && proto !== Object.prototype) {
|
|
97
104
|
for (const method of Object.getOwnPropertyNames(proto)) {
|
|
98
105
|
if (method === "constructor") continue;
|
|
106
|
+
if (nested && skipNestedOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
|
|
99
107
|
if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) callback(method, owner);
|
|
100
108
|
}
|
|
101
|
-
proto = Object.getPrototypeOf(proto);
|
|
109
|
+
proto = Object.getPrototypeOf(proto), nested = true;
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
112
|
function bindAllMethods(owner) {
|
|
@@ -239,9 +247,9 @@ export {
|
|
|
239
247
|
isIter,
|
|
240
248
|
isNum,
|
|
241
249
|
isObj,
|
|
250
|
+
isPOJO,
|
|
242
251
|
isSameURL,
|
|
243
252
|
isStr,
|
|
244
|
-
isStrictObj,
|
|
245
253
|
isSym,
|
|
246
254
|
loadResource,
|
|
247
255
|
onAllMethods,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t007/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "High-performance, zero-dependency utility functions for the t007 ecosystem.",
|
|
5
5
|
"author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,8 +43,5 @@
|
|
|
43
43
|
"dom-manipulation",
|
|
44
44
|
"shared-logic",
|
|
45
45
|
"performance"
|
|
46
|
-
]
|
|
47
|
-
"dependencies": {
|
|
48
|
-
"sia-reactor": "^0.0.12"
|
|
49
|
-
}
|
|
46
|
+
]
|
|
50
47
|
}
|