@t007/utils 0.0.2 → 0.0.4

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 CHANGED
@@ -56,14 +56,20 @@ function isSameURL(src1, src2) {
56
56
  }
57
57
 
58
58
  // src/core/dom.ts
59
- function createEl(tag, props = {}, dataset = {}, styles = {}) {
60
- return assignEl(tag ? document?.createElement(tag) : void 0, props, dataset, styles) ?? null;
59
+ function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
60
+ return assignEl(el, props, dataset, styles), el;
61
61
  }
62
- function assignEl(el, props = {}, dataset = {}, styles = {}) {
62
+ function assignEl(el, props, dataset, styles) {
63
63
  if (!el) return;
64
- for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
65
- for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
66
- for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
64
+ if (props) {
65
+ for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
66
+ }
67
+ if (dataset) {
68
+ for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
69
+ }
70
+ if (styles) {
71
+ for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
72
+ }
67
73
  }
68
74
  function loadResource(src, type = "style", { module: module2, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
69
75
  w.t007._resourceCache ??= {};
@@ -218,9 +224,9 @@ if (typeof window !== "undefined") {
218
224
  window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
219
225
  window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
220
226
  window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
221
- window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/style.css`;
222
- window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/style.css`;
223
- window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/style.css`;
227
+ window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/style.css`;
228
+ window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/style.css`;
229
+ window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/style.css`;
224
230
  }
225
231
  // Annotate the CommonJS export names for ESM import in node:
226
232
  0 && (module.exports = {
package/dist/index.d.cts CHANGED
@@ -70,7 +70,7 @@ type LoadResourceOptions = Partial<{
70
70
  declare function createEl<K extends keyof HTMLElementTagNameMap>(tag: K, props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): HTMLElementTagNameMap[K];
71
71
  declare function createEl(tag: string, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): HTMLElement | null;
72
72
  declare function assignEl<K extends keyof HTMLElementTagNameMap>(el?: HTMLElementTagNameMap[K], props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): void;
73
- declare function assignEl(el?: HTMLElement, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
73
+ declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
74
74
  declare function loadResource(src: string, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, w?: Window & typeof globalThis): Promise<HTMLElement | void>;
75
75
 
76
76
  declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void): void;
package/dist/index.d.ts CHANGED
@@ -70,7 +70,7 @@ type LoadResourceOptions = Partial<{
70
70
  declare function createEl<K extends keyof HTMLElementTagNameMap>(tag: K, props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): HTMLElementTagNameMap[K];
71
71
  declare function createEl(tag: string, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): HTMLElement | null;
72
72
  declare function assignEl<K extends keyof HTMLElementTagNameMap>(el?: HTMLElementTagNameMap[K], props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): void;
73
- declare function assignEl(el?: HTMLElement, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
73
+ declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
74
74
  declare function loadResource(src: string, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, w?: Window & typeof globalThis): Promise<HTMLElement | void>;
75
75
 
76
76
  declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void): void;
package/dist/index.js CHANGED
@@ -18,14 +18,20 @@ function isSameURL(src1, src2) {
18
18
  }
19
19
 
20
20
  // src/core/dom.ts
21
- function createEl(tag, props = {}, dataset = {}, styles = {}) {
22
- return assignEl(tag ? document?.createElement(tag) : void 0, props, dataset, styles) ?? null;
21
+ function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
22
+ return assignEl(el, props, dataset, styles), el;
23
23
  }
24
- function assignEl(el, props = {}, dataset = {}, styles = {}) {
24
+ function assignEl(el, props, dataset, styles) {
25
25
  if (!el) return;
26
- for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
27
- for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
28
- for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
26
+ if (props) {
27
+ for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
28
+ }
29
+ if (dataset) {
30
+ for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
31
+ }
32
+ if (styles) {
33
+ for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
34
+ }
29
35
  }
30
36
  function loadResource(src, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
31
37
  w.t007._resourceCache ??= {};
@@ -180,9 +186,9 @@ if (typeof window !== "undefined") {
180
186
  window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
181
187
  window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
182
188
  window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
183
- window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/style.css`;
184
- window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/style.css`;
185
- window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/style.css`;
189
+ window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/style.css`;
190
+ window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/style.css`;
191
+ window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/style.css`;
186
192
  }
187
193
  export {
188
194
  assignEl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
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",