@t007/utils 0.0.7 → 0.0.9
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/README.md +8 -1
- package/dist/index.cjs +49 -4
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +39 -4
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
- [Usage](#usage)
|
|
21
21
|
- [Author](#author)
|
|
22
22
|
- [Acknowledgments](#acknowledgments)
|
|
23
|
+
- [Star History](#star-history)
|
|
23
24
|
|
|
24
25
|
---
|
|
25
26
|
|
|
@@ -97,4 +98,10 @@ await loadResource('https://cdn.example.com/styles.css, 'link');
|
|
|
97
98
|
|
|
98
99
|
## Acknowledgments
|
|
99
100
|
|
|
100
|
-
The invisible backbone of the `@t007` ecosystem. Engineered to make complex DOM operations feel effortless.
|
|
101
|
+
The invisible backbone of the `@t007` ecosystem. Engineered to make complex DOM operations feel effortless.
|
|
102
|
+
|
|
103
|
+
## Star History
|
|
104
|
+
|
|
105
|
+
If you find this project useful, please consider giving it a star! ⭐
|
|
106
|
+
|
|
107
|
+
[](https://github.com/Tobi007-del/t007-tools)
|
package/dist/index.cjs
CHANGED
|
@@ -27,9 +27,19 @@ __export(index_exports, {
|
|
|
27
27
|
createEl: () => createEl,
|
|
28
28
|
guardAllMethods: () => guardAllMethods,
|
|
29
29
|
guardMethod: () => guardMethod,
|
|
30
|
+
inBoolArrOpt: () => inBoolArrOpt,
|
|
30
31
|
initScrollAssist: () => initScrollAssist,
|
|
31
32
|
initVScrollerator: () => initVScrollerator,
|
|
33
|
+
isArr: () => isArr,
|
|
34
|
+
isDef: () => import_utils.isDef,
|
|
35
|
+
isFunc: () => isFunc,
|
|
36
|
+
isIter: () => isIter,
|
|
37
|
+
isNum: () => isNum,
|
|
38
|
+
isObj: () => import_utils2.isObj,
|
|
32
39
|
isSameURL: () => isSameURL,
|
|
40
|
+
isStr: () => isStr,
|
|
41
|
+
isStrictObj: () => import_utils2.isStrictObj,
|
|
42
|
+
isSym: () => isSym,
|
|
33
43
|
loadResource: () => loadResource,
|
|
34
44
|
onAllMethods: () => onAllMethods,
|
|
35
45
|
removeScrollAssist: () => removeScrollAssist,
|
|
@@ -37,12 +47,37 @@ __export(index_exports, {
|
|
|
37
47
|
});
|
|
38
48
|
module.exports = __toCommonJS(index_exports);
|
|
39
49
|
|
|
50
|
+
// src/core/obj.ts
|
|
51
|
+
var import_utils = require("sia-reactor/utils");
|
|
52
|
+
var import_utils2 = require("sia-reactor/utils");
|
|
53
|
+
function isSym(val) {
|
|
54
|
+
return "symbol" === typeof val;
|
|
55
|
+
}
|
|
56
|
+
function isNum(val) {
|
|
57
|
+
return "number" === typeof val;
|
|
58
|
+
}
|
|
59
|
+
function isStr(val) {
|
|
60
|
+
return "string" === typeof val;
|
|
61
|
+
}
|
|
62
|
+
function isArr(obj) {
|
|
63
|
+
return Array.isArray(obj);
|
|
64
|
+
}
|
|
65
|
+
function isIter(obj) {
|
|
66
|
+
return obj != null && "function" === typeof obj[Symbol.iterator];
|
|
67
|
+
}
|
|
68
|
+
function isFunc(val) {
|
|
69
|
+
return "function" === typeof val;
|
|
70
|
+
}
|
|
71
|
+
function inBoolArrOpt(opt, str) {
|
|
72
|
+
return opt?.includes?.(str) ?? opt;
|
|
73
|
+
}
|
|
74
|
+
|
|
40
75
|
// src/core/str.ts
|
|
41
76
|
function uid(prefix = "") {
|
|
42
77
|
return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
|
|
43
78
|
}
|
|
44
79
|
function isSameURL(src1, src2) {
|
|
45
|
-
if (
|
|
80
|
+
if (!isStr(src1) || !isStr(src2) || !src1 || !src2) return false;
|
|
46
81
|
try {
|
|
47
82
|
const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
|
|
48
83
|
return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
|
|
@@ -70,7 +105,7 @@ function assignEl(el, props, dataset, styles) {
|
|
|
70
105
|
var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
|
|
71
106
|
function loadResource(req, type = "style", { module: module2, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
|
|
72
107
|
w.t007 ??= {}, w.t007._resourceCache ??= {};
|
|
73
|
-
if (req === VIRTUAL_RESOURCE ||
|
|
108
|
+
if (req === VIRTUAL_RESOURCE || isSym(req)) return Promise.resolve();
|
|
74
109
|
const src = req;
|
|
75
110
|
if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
|
|
76
111
|
const existing = type === "script" ? Array.prototype.find.call(w.document.scripts, (s) => isSameURL(s.src, src)) : type === "style" ? Array.prototype.find.call(w.document.styleSheets, (s) => isSameURL(s.href, src)) : null;
|
|
@@ -107,7 +142,7 @@ function onAllMethods(owner, callback) {
|
|
|
107
142
|
while (proto && proto !== Object.prototype) {
|
|
108
143
|
for (const method of Object.getOwnPropertyNames(proto)) {
|
|
109
144
|
if (method === "constructor") continue;
|
|
110
|
-
if (
|
|
145
|
+
if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) continue;
|
|
111
146
|
callback(method, owner);
|
|
112
147
|
}
|
|
113
148
|
proto = Object.getPrototypeOf(proto);
|
|
@@ -223,7 +258,7 @@ function initScrollAssist(el, { pxPerSecond = 80, assistClassName = "tmg-video-c
|
|
|
223
258
|
var removeScrollAssist = (el) => t007._scrollers.get(el)?.destroy();
|
|
224
259
|
|
|
225
260
|
// src/index.ts
|
|
226
|
-
if (
|
|
261
|
+
if ((0, import_utils.isDef)(window)) {
|
|
227
262
|
window.t007 ??= {};
|
|
228
263
|
t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
|
|
229
264
|
window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
|
|
@@ -242,9 +277,19 @@ if (typeof window !== "undefined") {
|
|
|
242
277
|
createEl,
|
|
243
278
|
guardAllMethods,
|
|
244
279
|
guardMethod,
|
|
280
|
+
inBoolArrOpt,
|
|
245
281
|
initScrollAssist,
|
|
246
282
|
initVScrollerator,
|
|
283
|
+
isArr,
|
|
284
|
+
isDef,
|
|
285
|
+
isFunc,
|
|
286
|
+
isIter,
|
|
287
|
+
isNum,
|
|
288
|
+
isObj,
|
|
247
289
|
isSameURL,
|
|
290
|
+
isStr,
|
|
291
|
+
isStrictObj,
|
|
292
|
+
isSym,
|
|
248
293
|
loadResource,
|
|
249
294
|
onAllMethods,
|
|
250
295
|
removeScrollAssist,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { isDef, isObj, isStrictObj } from 'sia-reactor/utils';
|
|
2
|
+
|
|
1
3
|
interface ScrolleratorOptions {
|
|
2
4
|
baseSpeed?: number;
|
|
3
5
|
maxSpeed?: number;
|
|
@@ -50,6 +52,15 @@ declare global {
|
|
|
50
52
|
var t007: T007Namespace;
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
declare function isSym<T = symbol>(val: any): val is T;
|
|
56
|
+
declare function isNum<T = number>(val: any): val is T;
|
|
57
|
+
declare function isStr<T = string>(val: any): val is T;
|
|
58
|
+
declare function isArr<T = unknown>(obj: any): obj is T[];
|
|
59
|
+
|
|
60
|
+
declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
|
|
61
|
+
declare function isFunc<T = Function>(val: any): val is T;
|
|
62
|
+
declare function inBoolArrOpt(opt: any, str: string): boolean;
|
|
63
|
+
|
|
53
64
|
declare function clamp(min: number | undefined, val: number, max?: number): number;
|
|
54
65
|
|
|
55
66
|
declare function uid(prefix?: string): string;
|
|
@@ -81,4 +92,4 @@ declare function bindAllMethods(owner: any): void;
|
|
|
81
92
|
declare function guardAllMethods(owner: any, guardFn?: (fn: Function) => Function, bound?: boolean): void;
|
|
82
93
|
declare function guardMethod<T extends Function>(fn: T, onError?: (e: any) => void): T;
|
|
83
94
|
|
|
84
|
-
export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, initScrollAssist, initVScrollerator, isSameURL, loadResource, onAllMethods, removeScrollAssist, uid };
|
|
95
|
+
export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isFunc, isIter, isNum, isSameURL, isStr, isSym, loadResource, onAllMethods, removeScrollAssist, uid };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { isDef, isObj, isStrictObj } from 'sia-reactor/utils';
|
|
2
|
+
|
|
1
3
|
interface ScrolleratorOptions {
|
|
2
4
|
baseSpeed?: number;
|
|
3
5
|
maxSpeed?: number;
|
|
@@ -50,6 +52,15 @@ declare global {
|
|
|
50
52
|
var t007: T007Namespace;
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
declare function isSym<T = symbol>(val: any): val is T;
|
|
56
|
+
declare function isNum<T = number>(val: any): val is T;
|
|
57
|
+
declare function isStr<T = string>(val: any): val is T;
|
|
58
|
+
declare function isArr<T = unknown>(obj: any): obj is T[];
|
|
59
|
+
|
|
60
|
+
declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
|
|
61
|
+
declare function isFunc<T = Function>(val: any): val is T;
|
|
62
|
+
declare function inBoolArrOpt(opt: any, str: string): boolean;
|
|
63
|
+
|
|
53
64
|
declare function clamp(min: number | undefined, val: number, max?: number): number;
|
|
54
65
|
|
|
55
66
|
declare function uid(prefix?: string): string;
|
|
@@ -81,4 +92,4 @@ declare function bindAllMethods(owner: any): void;
|
|
|
81
92
|
declare function guardAllMethods(owner: any, guardFn?: (fn: Function) => Function, bound?: boolean): void;
|
|
82
93
|
declare function guardMethod<T extends Function>(fn: T, onError?: (e: any) => void): T;
|
|
83
94
|
|
|
84
|
-
export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, initScrollAssist, initVScrollerator, isSameURL, loadResource, onAllMethods, removeScrollAssist, uid };
|
|
95
|
+
export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isFunc, isIter, isNum, isSameURL, isStr, isSym, loadResource, onAllMethods, removeScrollAssist, uid };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
|
+
// src/core/obj.ts
|
|
2
|
+
import { isDef } from "sia-reactor/utils";
|
|
3
|
+
import { isObj, isStrictObj } from "sia-reactor/utils";
|
|
4
|
+
function isSym(val) {
|
|
5
|
+
return "symbol" === typeof val;
|
|
6
|
+
}
|
|
7
|
+
function isNum(val) {
|
|
8
|
+
return "number" === typeof val;
|
|
9
|
+
}
|
|
10
|
+
function isStr(val) {
|
|
11
|
+
return "string" === typeof val;
|
|
12
|
+
}
|
|
13
|
+
function isArr(obj) {
|
|
14
|
+
return Array.isArray(obj);
|
|
15
|
+
}
|
|
16
|
+
function isIter(obj) {
|
|
17
|
+
return obj != null && "function" === typeof obj[Symbol.iterator];
|
|
18
|
+
}
|
|
19
|
+
function isFunc(val) {
|
|
20
|
+
return "function" === typeof val;
|
|
21
|
+
}
|
|
22
|
+
function inBoolArrOpt(opt, str) {
|
|
23
|
+
return opt?.includes?.(str) ?? opt;
|
|
24
|
+
}
|
|
25
|
+
|
|
1
26
|
// src/core/str.ts
|
|
2
27
|
function uid(prefix = "") {
|
|
3
28
|
return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
|
|
4
29
|
}
|
|
5
30
|
function isSameURL(src1, src2) {
|
|
6
|
-
if (
|
|
31
|
+
if (!isStr(src1) || !isStr(src2) || !src1 || !src2) return false;
|
|
7
32
|
try {
|
|
8
33
|
const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
|
|
9
34
|
return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
|
|
@@ -31,7 +56,7 @@ function assignEl(el, props, dataset, styles) {
|
|
|
31
56
|
var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
|
|
32
57
|
function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
|
|
33
58
|
w.t007 ??= {}, w.t007._resourceCache ??= {};
|
|
34
|
-
if (req === VIRTUAL_RESOURCE ||
|
|
59
|
+
if (req === VIRTUAL_RESOURCE || isSym(req)) return Promise.resolve();
|
|
35
60
|
const src = req;
|
|
36
61
|
if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
|
|
37
62
|
const existing = type === "script" ? Array.prototype.find.call(w.document.scripts, (s) => isSameURL(s.src, src)) : type === "style" ? Array.prototype.find.call(w.document.styleSheets, (s) => isSameURL(s.href, src)) : null;
|
|
@@ -68,7 +93,7 @@ function onAllMethods(owner, callback) {
|
|
|
68
93
|
while (proto && proto !== Object.prototype) {
|
|
69
94
|
for (const method of Object.getOwnPropertyNames(proto)) {
|
|
70
95
|
if (method === "constructor") continue;
|
|
71
|
-
if (
|
|
96
|
+
if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) continue;
|
|
72
97
|
callback(method, owner);
|
|
73
98
|
}
|
|
74
99
|
proto = Object.getPrototypeOf(proto);
|
|
@@ -184,7 +209,7 @@ function initScrollAssist(el, { pxPerSecond = 80, assistClassName = "tmg-video-c
|
|
|
184
209
|
var removeScrollAssist = (el) => t007._scrollers.get(el)?.destroy();
|
|
185
210
|
|
|
186
211
|
// src/index.ts
|
|
187
|
-
if (
|
|
212
|
+
if (isDef(window)) {
|
|
188
213
|
window.t007 ??= {};
|
|
189
214
|
t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
|
|
190
215
|
window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
|
|
@@ -202,9 +227,19 @@ export {
|
|
|
202
227
|
createEl,
|
|
203
228
|
guardAllMethods,
|
|
204
229
|
guardMethod,
|
|
230
|
+
inBoolArrOpt,
|
|
205
231
|
initScrollAssist,
|
|
206
232
|
initVScrollerator,
|
|
233
|
+
isArr,
|
|
234
|
+
isDef,
|
|
235
|
+
isFunc,
|
|
236
|
+
isIter,
|
|
237
|
+
isNum,
|
|
238
|
+
isObj,
|
|
207
239
|
isSameURL,
|
|
240
|
+
isStr,
|
|
241
|
+
isStrictObj,
|
|
242
|
+
isSym,
|
|
208
243
|
loadResource,
|
|
209
244
|
onAllMethods,
|
|
210
245
|
removeScrollAssist,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t007/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
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,5 +43,8 @@
|
|
|
43
43
|
"dom-manipulation",
|
|
44
44
|
"shared-logic",
|
|
45
45
|
"performance"
|
|
46
|
-
]
|
|
46
|
+
],
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"sia-reactor": "^0.0.10"
|
|
49
|
+
}
|
|
47
50
|
}
|