@hybridly/utils 0.7.19 → 0.8.1
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 +9 -16
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +9 -16
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -19,8 +19,8 @@ function hasFiles(data) {
|
|
|
19
19
|
return data instanceof File || data instanceof Blob || data instanceof FileList && data.length > 0 || data instanceof FormData && Array.from(data.values()).some((value) => hasFiles(value)) || typeof data === "object" && data !== null && Object.values(data).some((value) => hasFiles(value));
|
|
20
20
|
}
|
|
21
21
|
function objectToFormData(source, form, parentKey) {
|
|
22
|
-
source
|
|
23
|
-
form
|
|
22
|
+
source ??= {};
|
|
23
|
+
form ??= new FormData();
|
|
24
24
|
if (typeof source !== "object" || source instanceof Set || Array.isArray(source) || source instanceof Blob || source instanceof Date || source instanceof FormData) {
|
|
25
25
|
throw new TypeError("Source must be an object literal to be converted to a FormData object.");
|
|
26
26
|
}
|
|
@@ -59,23 +59,11 @@ function append(form, key, value) {
|
|
|
59
59
|
objectToFormData(value, form, key);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
var __defProp = Object.defineProperty;
|
|
63
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
64
|
-
var __publicField = (obj, key, value) => {
|
|
65
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
66
|
-
return value;
|
|
67
|
-
};
|
|
68
62
|
const stack = [];
|
|
69
63
|
class Modal {
|
|
70
64
|
constructor(html, id) {
|
|
71
65
|
this.html = html;
|
|
72
66
|
this.id = id;
|
|
73
|
-
__publicField(this, "main");
|
|
74
|
-
__publicField(this, "overlay");
|
|
75
|
-
__publicField(this, "iframe");
|
|
76
|
-
__publicField(this, "style");
|
|
77
|
-
__publicField(this, "hideOnEscape");
|
|
78
|
-
__publicField(this, "animationDurationInMs", 200);
|
|
79
67
|
if (stack.includes(id)) {
|
|
80
68
|
return;
|
|
81
69
|
}
|
|
@@ -84,6 +72,12 @@ class Modal {
|
|
|
84
72
|
}
|
|
85
73
|
this.show();
|
|
86
74
|
}
|
|
75
|
+
main;
|
|
76
|
+
overlay;
|
|
77
|
+
iframe;
|
|
78
|
+
style;
|
|
79
|
+
hideOnEscape;
|
|
80
|
+
animationDurationInMs = 200;
|
|
87
81
|
static fromException(response, id) {
|
|
88
82
|
if (typeof response === "string" && response.trim() !== "") {
|
|
89
83
|
return new Modal(`<style>${htmlStyle()}</style>${response.toString()}`, id);
|
|
@@ -305,8 +299,7 @@ function match(value2, lookup, ...args) {
|
|
|
305
299
|
return typeof returnValue === "function" ? returnValue(...args) : returnValue;
|
|
306
300
|
}
|
|
307
301
|
const handlers = Object.keys(lookup).map((key) => `"${key}"`).join(", ");
|
|
308
|
-
|
|
309
|
-
throw error;
|
|
302
|
+
throw new Error(`Tried to handle "${value2}" but there is no handler defined. Only defined handlers are: ${handlers}.`);
|
|
310
303
|
}
|
|
311
304
|
function value(value2) {
|
|
312
305
|
if (typeof value2 === "function") {
|
package/dist/index.d.cts
CHANGED
|
@@ -36,7 +36,7 @@ declare function showViewComponentErrorModal(response: string): Modal;
|
|
|
36
36
|
|
|
37
37
|
declare function random(length?: number): string;
|
|
38
38
|
/** Simple pattern matching util. */
|
|
39
|
-
declare function match<TValue extends string | number = string, TReturnValue = unknown>(value: TValue, lookup: Record<TValue | 'default', TReturnValue | ((...args:
|
|
39
|
+
declare function match<TValue extends string | number = string, TReturnValue = unknown, TArgs extends readonly unknown[] = []>(value: TValue, lookup: Record<TValue | 'default', TReturnValue | ((...args: TArgs) => TReturnValue | Promise<TReturnValue>)>, ...args: TArgs): TReturnValue | Promise<TReturnValue>;
|
|
40
40
|
declare function value<T>(value: T | (() => T)): T;
|
|
41
41
|
declare function when<T, D>(condition: any, data: T, _default?: D): T | D | undefined;
|
|
42
42
|
interface MergeOptions {
|
|
@@ -80,4 +80,5 @@ declare const debug: {
|
|
|
80
80
|
adapter: (name: string, ...args: any[]) => void;
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
export {
|
|
83
|
+
export { debug, hasFiles, match, merge, objectToFormData, random, removeTrailingSlash, setValueAtPath, showResponseErrorModal, showViewComponentErrorModal, unsetPropertyAtPath, value, when };
|
|
84
|
+
export type { FormDataConvertible, RequestData };
|
package/dist/index.d.mts
CHANGED
|
@@ -36,7 +36,7 @@ declare function showViewComponentErrorModal(response: string): Modal;
|
|
|
36
36
|
|
|
37
37
|
declare function random(length?: number): string;
|
|
38
38
|
/** Simple pattern matching util. */
|
|
39
|
-
declare function match<TValue extends string | number = string, TReturnValue = unknown>(value: TValue, lookup: Record<TValue | 'default', TReturnValue | ((...args:
|
|
39
|
+
declare function match<TValue extends string | number = string, TReturnValue = unknown, TArgs extends readonly unknown[] = []>(value: TValue, lookup: Record<TValue | 'default', TReturnValue | ((...args: TArgs) => TReturnValue | Promise<TReturnValue>)>, ...args: TArgs): TReturnValue | Promise<TReturnValue>;
|
|
40
40
|
declare function value<T>(value: T | (() => T)): T;
|
|
41
41
|
declare function when<T, D>(condition: any, data: T, _default?: D): T | D | undefined;
|
|
42
42
|
interface MergeOptions {
|
|
@@ -80,4 +80,5 @@ declare const debug: {
|
|
|
80
80
|
adapter: (name: string, ...args: any[]) => void;
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
export {
|
|
83
|
+
export { debug, hasFiles, match, merge, objectToFormData, random, removeTrailingSlash, setValueAtPath, showResponseErrorModal, showViewComponentErrorModal, unsetPropertyAtPath, value, when };
|
|
84
|
+
export type { FormDataConvertible, RequestData };
|
package/dist/index.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ declare function showViewComponentErrorModal(response: string): Modal;
|
|
|
36
36
|
|
|
37
37
|
declare function random(length?: number): string;
|
|
38
38
|
/** Simple pattern matching util. */
|
|
39
|
-
declare function match<TValue extends string | number = string, TReturnValue = unknown>(value: TValue, lookup: Record<TValue | 'default', TReturnValue | ((...args:
|
|
39
|
+
declare function match<TValue extends string | number = string, TReturnValue = unknown, TArgs extends readonly unknown[] = []>(value: TValue, lookup: Record<TValue | 'default', TReturnValue | ((...args: TArgs) => TReturnValue | Promise<TReturnValue>)>, ...args: TArgs): TReturnValue | Promise<TReturnValue>;
|
|
40
40
|
declare function value<T>(value: T | (() => T)): T;
|
|
41
41
|
declare function when<T, D>(condition: any, data: T, _default?: D): T | D | undefined;
|
|
42
42
|
interface MergeOptions {
|
|
@@ -80,4 +80,5 @@ declare const debug: {
|
|
|
80
80
|
adapter: (name: string, ...args: any[]) => void;
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
export {
|
|
83
|
+
export { debug, hasFiles, match, merge, objectToFormData, random, removeTrailingSlash, setValueAtPath, showResponseErrorModal, showViewComponentErrorModal, unsetPropertyAtPath, value, when };
|
|
84
|
+
export type { FormDataConvertible, RequestData };
|
package/dist/index.mjs
CHANGED
|
@@ -11,8 +11,8 @@ function hasFiles(data) {
|
|
|
11
11
|
return data instanceof File || data instanceof Blob || data instanceof FileList && data.length > 0 || data instanceof FormData && Array.from(data.values()).some((value) => hasFiles(value)) || typeof data === "object" && data !== null && Object.values(data).some((value) => hasFiles(value));
|
|
12
12
|
}
|
|
13
13
|
function objectToFormData(source, form, parentKey) {
|
|
14
|
-
source
|
|
15
|
-
form
|
|
14
|
+
source ??= {};
|
|
15
|
+
form ??= new FormData();
|
|
16
16
|
if (typeof source !== "object" || source instanceof Set || Array.isArray(source) || source instanceof Blob || source instanceof Date || source instanceof FormData) {
|
|
17
17
|
throw new TypeError("Source must be an object literal to be converted to a FormData object.");
|
|
18
18
|
}
|
|
@@ -51,23 +51,11 @@ function append(form, key, value) {
|
|
|
51
51
|
objectToFormData(value, form, key);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
var __defProp = Object.defineProperty;
|
|
55
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
56
|
-
var __publicField = (obj, key, value) => {
|
|
57
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
58
|
-
return value;
|
|
59
|
-
};
|
|
60
54
|
const stack = [];
|
|
61
55
|
class Modal {
|
|
62
56
|
constructor(html, id) {
|
|
63
57
|
this.html = html;
|
|
64
58
|
this.id = id;
|
|
65
|
-
__publicField(this, "main");
|
|
66
|
-
__publicField(this, "overlay");
|
|
67
|
-
__publicField(this, "iframe");
|
|
68
|
-
__publicField(this, "style");
|
|
69
|
-
__publicField(this, "hideOnEscape");
|
|
70
|
-
__publicField(this, "animationDurationInMs", 200);
|
|
71
59
|
if (stack.includes(id)) {
|
|
72
60
|
return;
|
|
73
61
|
}
|
|
@@ -76,6 +64,12 @@ class Modal {
|
|
|
76
64
|
}
|
|
77
65
|
this.show();
|
|
78
66
|
}
|
|
67
|
+
main;
|
|
68
|
+
overlay;
|
|
69
|
+
iframe;
|
|
70
|
+
style;
|
|
71
|
+
hideOnEscape;
|
|
72
|
+
animationDurationInMs = 200;
|
|
79
73
|
static fromException(response, id) {
|
|
80
74
|
if (typeof response === "string" && response.trim() !== "") {
|
|
81
75
|
return new Modal(`<style>${htmlStyle()}</style>${response.toString()}`, id);
|
|
@@ -297,8 +291,7 @@ function match(value2, lookup, ...args) {
|
|
|
297
291
|
return typeof returnValue === "function" ? returnValue(...args) : returnValue;
|
|
298
292
|
}
|
|
299
293
|
const handlers = Object.keys(lookup).map((key) => `"${key}"`).join(", ");
|
|
300
|
-
|
|
301
|
-
throw error;
|
|
294
|
+
throw new Error(`Tried to handle "${value2}" but there is no handler defined. Only defined handlers are: ${handlers}.`);
|
|
302
295
|
}
|
|
303
296
|
function value(value2) {
|
|
304
297
|
if (typeof value2 === "function") {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hybridly/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.1",
|
|
5
5
|
"description": "Utils used in Hybridly packages",
|
|
6
6
|
"author": "Enzo Innocenzi <enzo@innocenzi.dev>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dist"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"debug": "^4.4.
|
|
41
|
+
"debug": "^4.4.1",
|
|
42
42
|
"deepmerge": "^4.3.1",
|
|
43
43
|
"is-plain-object": "^5.0.0",
|
|
44
44
|
"lodash.clonedeep": "^4.5.0",
|