toolbox-x 1.0.0
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/LICENSE +201 -0
- package/dist/Color-B3mgF9Dh.d.cts +486 -0
- package/dist/Color-D38Xrw65.d.mts +486 -0
- package/dist/Stylog-Df7eq3-j.d.cts +519 -0
- package/dist/Stylog-jvlLcMQq.d.mts +519 -0
- package/dist/array-DvW0zIu6.d.mts +130 -0
- package/dist/array-rUnEVisO.d.cts +130 -0
- package/dist/basics-D_eSv0cu.cjs +132 -0
- package/dist/basics-Dp_aEK81.mjs +115 -0
- package/dist/basics-WEYWlnRO.d.cts +95 -0
- package/dist/basics-uBSfkBEI.d.mts +95 -0
- package/dist/case-BWIt8Ash.mjs +449 -0
- package/dist/case-C-S-b5YP.d.cts +327 -0
- package/dist/case-CS8Ii3A7.cjs +526 -0
- package/dist/case-CybASFPD.d.mts +327 -0
- package/dist/change-case.cjs +32 -0
- package/dist/change-case.d.cts +18 -0
- package/dist/change-case.d.mts +18 -0
- package/dist/change-case.mjs +19 -0
- package/dist/colors.cjs +574 -0
- package/dist/colors.d.cts +355 -0
- package/dist/colors.d.mts +355 -0
- package/dist/colors.mjs +547 -0
- package/dist/constants-2gAw23_7.mjs +144 -0
- package/dist/constants-B34K0QPi.d.cts +21 -0
- package/dist/constants-BIBDKY1u.cjs +924 -0
- package/dist/constants-BWT-810U.cjs +158 -0
- package/dist/constants-BwbHnXlM.mjs +662 -0
- package/dist/constants-BxN9l5el.cjs +74 -0
- package/dist/constants-CLS_bgKD.d.mts +847 -0
- package/dist/constants-D73iFu8g.mjs +171 -0
- package/dist/constants-DAfRxaa8.mjs +62 -0
- package/dist/constants-DQYeCjlx.cjs +207 -0
- package/dist/constants-Deeie-iH.d.mts +21 -0
- package/dist/constants-DpTG9RP6.d.mts +29 -0
- package/dist/constants-DqwnkJ_d.cjs +740 -0
- package/dist/constants-DvRUY_FY.cjs +150 -0
- package/dist/constants-VcRtQu0K.d.cts +29 -0
- package/dist/constants-X5hm1UtB.mjs +912 -0
- package/dist/constants-eNd-iYsV.mjs +134 -0
- package/dist/constants-qm8FafmD.d.cts +847 -0
- package/dist/constants.cjs +415 -0
- package/dist/constants.d.cts +184 -0
- package/dist/constants.d.mts +184 -0
- package/dist/constants.mjs +378 -0
- package/dist/convert-BOCgUv2D.cjs +252 -0
- package/dist/convert-Bn4jFomQ.mjs +169 -0
- package/dist/convert-BrzlG-m_.cjs +475 -0
- package/dist/convert-DhaUoPVU.mjs +368 -0
- package/dist/converter-1P90_RcP.d.mts +402 -0
- package/dist/converter-CmkcAppi.d.cts +402 -0
- package/dist/converter.cjs +780 -0
- package/dist/converter.d.cts +29 -0
- package/dist/converter.d.mts +29 -0
- package/dist/converter.mjs +771 -0
- package/dist/countries-CIpmtEzV.cjs +1469 -0
- package/dist/countries-Cy0xiqS3.mjs +1463 -0
- package/dist/css-colors-Bx947Ng3.d.cts +179 -0
- package/dist/css-colors-CXCDqQbG.cjs +186 -0
- package/dist/css-colors-CXTp1vvy.d.mts +179 -0
- package/dist/css-colors-DfUW3nTR.mjs +180 -0
- package/dist/date.cjs +332 -0
- package/dist/date.d.cts +213 -0
- package/dist/date.d.mts +213 -0
- package/dist/date.mjs +298 -0
- package/dist/dom.cjs +461 -0
- package/dist/dom.d.cts +228 -0
- package/dist/dom.d.mts +228 -0
- package/dist/dom.mjs +429 -0
- package/dist/form-BMFVGUrN.d.mts +118 -0
- package/dist/form-DRFbryvK.d.cts +118 -0
- package/dist/guards-3kaUX66g.mjs +157 -0
- package/dist/guards-C8gkvIHb.cjs +240 -0
- package/dist/guards-DdyU4h4o.mjs +110 -0
- package/dist/guards-Efhp1mNy.cjs +151 -0
- package/dist/guards.cjs +172 -0
- package/dist/guards.d.cts +399 -0
- package/dist/guards.d.mts +399 -0
- package/dist/guards.mjs +75 -0
- package/dist/hash-B6JPEyAz.d.mts +131 -0
- package/dist/hash-NTpeKYB_.d.cts +131 -0
- package/dist/hash.cjs +2126 -0
- package/dist/hash.d.cts +1239 -0
- package/dist/hash.d.mts +1239 -0
- package/dist/hash.mjs +2095 -0
- package/dist/http-status-BAZdtr7-.d.mts +65 -0
- package/dist/http-status-U_3MtoGb.d.cts +65 -0
- package/dist/http-status.cjs +173 -0
- package/dist/http-status.d.cts +142 -0
- package/dist/http-status.d.mts +142 -0
- package/dist/http-status.mjs +171 -0
- package/dist/index.cjs +2551 -0
- package/dist/index.d.cts +1493 -0
- package/dist/index.d.mts +1493 -0
- package/dist/index.mjs +2357 -0
- package/dist/object-B0TV3eHx.d.mts +8052 -0
- package/dist/object-Blq0Amdv.d.cts +8052 -0
- package/dist/objectify-CDs0Fbr1.mjs +417 -0
- package/dist/objectify-DIJ-OBmo.cjs +524 -0
- package/dist/paginator.cjs +245 -0
- package/dist/paginator.d.cts +144 -0
- package/dist/paginator.d.mts +144 -0
- package/dist/paginator.mjs +243 -0
- package/dist/parse-2ubxXZRp.cjs +211 -0
- package/dist/parse-N7g942uy.mjs +164 -0
- package/dist/pluralizer-BjMIc6uT.d.mts +42 -0
- package/dist/pluralizer-Cb6ZmrDl.d.cts +42 -0
- package/dist/pluralizer.cjs +678 -0
- package/dist/pluralizer.d.cts +152 -0
- package/dist/pluralizer.d.mts +152 -0
- package/dist/pluralizer.mjs +676 -0
- package/dist/primitives-B26uZolQ.cjs +228 -0
- package/dist/primitives-KsFUp3kQ.mjs +144 -0
- package/dist/specials-D48_IZbd.d.mts +108 -0
- package/dist/specials-DzLr1ZgU.cjs +477 -0
- package/dist/specials-LVONlKbQ.d.cts +108 -0
- package/dist/specials-uhDuRg8H.mjs +292 -0
- package/dist/string-CBAbxaG1.d.mts +258 -0
- package/dist/string-CsNsm_65.d.cts +258 -0
- package/dist/stylog.cjs +621 -0
- package/dist/stylog.d.cts +49 -0
- package/dist/stylog.d.mts +49 -0
- package/dist/stylog.mjs +614 -0
- package/dist/timezone-B2OYK6Fh.mjs +5589 -0
- package/dist/timezone-Beh9IGpw.cjs +5625 -0
- package/dist/types/array.cjs +16 -0
- package/dist/types/array.d.cts +18 -0
- package/dist/types/array.d.mts +18 -0
- package/dist/types/array.mjs +17 -0
- package/dist/types/colors.cjs +16 -0
- package/dist/types/colors.d.cts +18 -0
- package/dist/types/colors.d.mts +18 -0
- package/dist/types/colors.mjs +17 -0
- package/dist/types/converter.cjs +16 -0
- package/dist/types/converter.d.cts +18 -0
- package/dist/types/converter.d.mts +18 -0
- package/dist/types/converter.mjs +17 -0
- package/dist/types/form.cjs +16 -0
- package/dist/types/form.d.cts +18 -0
- package/dist/types/form.d.mts +18 -0
- package/dist/types/form.mjs +17 -0
- package/dist/types/hash.cjs +16 -0
- package/dist/types/hash.d.cts +18 -0
- package/dist/types/hash.d.mts +18 -0
- package/dist/types/hash.mjs +17 -0
- package/dist/types/http-status.cjs +16 -0
- package/dist/types/http-status.d.cts +18 -0
- package/dist/types/http-status.d.mts +18 -0
- package/dist/types/http-status.mjs +17 -0
- package/dist/types/index.cjs +16 -0
- package/dist/types/index.d.cts +18 -0
- package/dist/types/index.d.mts +18 -0
- package/dist/types/index.mjs +17 -0
- package/dist/types/number.cjs +16 -0
- package/dist/types/number.d.cts +18 -0
- package/dist/types/number.d.mts +18 -0
- package/dist/types/number.mjs +17 -0
- package/dist/types/object.cjs +16 -0
- package/dist/types/object.d.cts +18 -0
- package/dist/types/object.d.mts +18 -0
- package/dist/types/object.mjs +17 -0
- package/dist/types/pluralizer.cjs +16 -0
- package/dist/types/pluralizer.d.cts +18 -0
- package/dist/types/pluralizer.d.mts +18 -0
- package/dist/types/pluralizer.mjs +17 -0
- package/dist/types/string.cjs +16 -0
- package/dist/types/string.d.cts +18 -0
- package/dist/types/string.d.mts +18 -0
- package/dist/types/string.mjs +17 -0
- package/dist/types/stylog.cjs +16 -0
- package/dist/types/stylog.d.cts +18 -0
- package/dist/types/stylog.d.mts +18 -0
- package/dist/types/stylog.mjs +17 -0
- package/dist/types/utils.cjs +16 -0
- package/dist/types/utils.d.cts +18 -0
- package/dist/types/utils.d.mts +18 -0
- package/dist/types/utils.mjs +17 -0
- package/dist/types/verbalizer.cjs +16 -0
- package/dist/types/verbalizer.d.cts +30 -0
- package/dist/types/verbalizer.d.mts +30 -0
- package/dist/types/verbalizer.mjs +17 -0
- package/dist/utilities-CLUmdQeV.cjs +140 -0
- package/dist/utilities-m5yFKqLd.mjs +105 -0
- package/dist/utils-ClW9LA6f.mjs +449 -0
- package/dist/utils-DLFRgXUC.cjs +568 -0
- package/dist/verbalizer.cjs +998 -0
- package/dist/verbalizer.d.cts +148 -0
- package/dist/verbalizer.d.mts +148 -0
- package/dist/verbalizer.mjs +996 -0
- package/package.json +249 -0
package/dist/dom.mjs
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { a as isNonEmptyString, d as isString } from "./primitives-KsFUp3kQ.mjs";
|
|
18
|
+
import { j as isValidArray, v as isEmptyObject, w as isNotEmptyObject } from "./specials-uhDuRg8H.mjs";
|
|
19
|
+
import { t as isDateLike } from "./guards-DdyU4h4o.mjs";
|
|
20
|
+
import { _ as isOriginFileObj, a as flattenObjectKeyValue, d as isCustomFile, f as isCustomFileArray, g as isFileUpload, h as isFileOrBlob, l as parseObjectValues, m as isFileList, p as isFileArray, v as isValidFormData } from "./objectify-CDs0Fbr1.mjs";
|
|
21
|
+
import { a as deepParsePrimitives } from "./utils-ClW9LA6f.mjs";
|
|
22
|
+
|
|
23
|
+
//#region src/dom/query.ts
|
|
24
|
+
/**
|
|
25
|
+
* * Utility to generate query parameters from an object.
|
|
26
|
+
*
|
|
27
|
+
* @param params - Object containing query parameters.
|
|
28
|
+
* @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
|
|
32
|
+
* generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
|
|
33
|
+
* generateQueryParams({ key1: '', key2: null }); // ""
|
|
34
|
+
* generateQueryParams({ key1: true, key2: false }); // "?key1=true&key2=false"
|
|
35
|
+
* generateQueryParams({ filters: { category: 'laptop', price: 1000 } }); // "?category=laptop&price=1000"
|
|
36
|
+
*/
|
|
37
|
+
function generateQueryParams(params = {}) {
|
|
38
|
+
const flattenedParams = flattenObjectKeyValue(params);
|
|
39
|
+
const queryParams = Object.entries(flattenedParams)?.filter(([_, value]) => value != null && !(isString(value) && value?.trim() === ""))?.flatMap(([key, value]) => Array.isArray(value) ? value?.filter((v) => v != null && !(isString(v) && v.trim() === ""))?.map((v) => `${encodeURIComponent(key)}=${encodeURIComponent(String(v))}`) : `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`).join("&");
|
|
40
|
+
return queryParams ? `?${queryParams}` : "";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* * Get query params as standard `JavaScript` Object `Record<string, string>`. You can define the type by passing a type argument.
|
|
44
|
+
*
|
|
45
|
+
* - **Note:** *Extracts query parameters from the current URL (window.location.search).*
|
|
46
|
+
*
|
|
47
|
+
* @returns Query string as key-value paired object. `Record<string, string>`.
|
|
48
|
+
*/
|
|
49
|
+
function getQueryParams() {
|
|
50
|
+
return Object.fromEntries(new URLSearchParams(window?.location?.search));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* * Update query params in the browser URL with given key and value.
|
|
54
|
+
* @param key Key for the query to update.
|
|
55
|
+
* @param value Value to updated against the given key.
|
|
56
|
+
*/
|
|
57
|
+
function updateQueryParam(key, value) {
|
|
58
|
+
const url = new URL(window.location.href);
|
|
59
|
+
url.searchParams.set(key, value);
|
|
60
|
+
window.history.replaceState({}, "", url?.toString());
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Parses a query string (with optional `?` prefix) into an object.
|
|
64
|
+
* Supports multiple values for the same key by returning arrays.
|
|
65
|
+
* Optionally parses primitive string values into actual types (e.g., "1" → 1, "true" → true).
|
|
66
|
+
*
|
|
67
|
+
* @remarks This utility is designed to parse generic string, for literal use, try {@link parseQueryStringLiteral}.
|
|
68
|
+
*
|
|
69
|
+
* - **Note:** *This function does **not** access or depend on `current URL` a.k.a `window.location.search`.*
|
|
70
|
+
*
|
|
71
|
+
* @param query - The query string to parse.
|
|
72
|
+
* @param parsePrimitives - Whether to convert stringified primitives into real values (default: true).
|
|
73
|
+
* @returns An object where keys are strings and values can be string, array, number, boolean, or null/undefined.
|
|
74
|
+
*/
|
|
75
|
+
function parseQueryString(query, parsePrimitives = true) {
|
|
76
|
+
const params = new URLSearchParams(query.startsWith("?") ? query.slice(1) : query);
|
|
77
|
+
const entries = {};
|
|
78
|
+
for (const [key, value] of params.entries()) if (key in entries) {
|
|
79
|
+
const current = entries[key];
|
|
80
|
+
const array = Array.isArray(current) ? [...current, value] : [current, value];
|
|
81
|
+
entries[key] = parsePrimitives ? deepParsePrimitives(array) : array;
|
|
82
|
+
} else entries[key] = value;
|
|
83
|
+
return parsePrimitives ? parseObjectValues(entries) : entries;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Parses a query string (with optional `?` prefix) into an object.
|
|
87
|
+
* Supports multiple values for the same key by returning arrays.
|
|
88
|
+
* It returns properly typed object.
|
|
89
|
+
*
|
|
90
|
+
* @remarks This utility is designed to parse literal string, for generic use, try {@link parseQueryString}.
|
|
91
|
+
*
|
|
92
|
+
* - **Note:** *This function does **not** access or depend on `current URL` a.k.a `window.location.search`.*
|
|
93
|
+
*
|
|
94
|
+
* @param query - The literal query string to parse.
|
|
95
|
+
* @returns An object where keys are strings and values can be string, array, or null/undefined.
|
|
96
|
+
*/
|
|
97
|
+
function parseQueryStringLiteral(query) {
|
|
98
|
+
const params = new URLSearchParams(query.startsWith("?") ? query.slice(1) : query);
|
|
99
|
+
const entries = {};
|
|
100
|
+
for (const [key, value] of params.entries()) if (key in entries) {
|
|
101
|
+
const current = entries[key];
|
|
102
|
+
entries[key] = Array.isArray(current) ? [...current, value] : [current, value];
|
|
103
|
+
} else entries[key] = value;
|
|
104
|
+
return entries;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/dom/storage.ts
|
|
109
|
+
/**
|
|
110
|
+
* * Get item from local storage.
|
|
111
|
+
*
|
|
112
|
+
* @param key - Key to get item from local storage.
|
|
113
|
+
* @param deserialize - Optional deserializer function to convert the stored value back to type `T`. Defaults to `JSON.parse`.
|
|
114
|
+
* @returns Returns saved item from local storage if it exists with that key.
|
|
115
|
+
*/
|
|
116
|
+
function getFromLocalStorage(key, deserialize) {
|
|
117
|
+
const deserializer = deserialize ?? JSON.parse;
|
|
118
|
+
try {
|
|
119
|
+
const item = localStorage.getItem(key);
|
|
120
|
+
return item ? deserializer(item) : null;
|
|
121
|
+
} catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* * Save item in local storage.
|
|
127
|
+
*
|
|
128
|
+
* @param key - Key to save an item.
|
|
129
|
+
* @param value - The item/value to save.
|
|
130
|
+
* @param serialize - Optional serializer function to convert the value of type `T` to a string. Defaults to `JSON.stringify`.
|
|
131
|
+
*/
|
|
132
|
+
function saveToLocalStorage(key, value, serialize) {
|
|
133
|
+
const serializer = serialize ?? JSON.stringify;
|
|
134
|
+
try {
|
|
135
|
+
localStorage.setItem(key, serializer(value));
|
|
136
|
+
} catch (error) {
|
|
137
|
+
console.error(`Error saving item with key "${key}" in local storage:`, error);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* * Remove item from local storage.
|
|
142
|
+
*
|
|
143
|
+
* @param key - Key to delete item from local storage.
|
|
144
|
+
*/
|
|
145
|
+
function removeFromLocalStorage(key) {
|
|
146
|
+
try {
|
|
147
|
+
localStorage.removeItem(key);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error(`Error removing item with key "${key}" from local storage:`, error);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* * Get item from session storage.
|
|
154
|
+
*
|
|
155
|
+
* @param key - Key to get item from session storage.
|
|
156
|
+
* @param deserialize - Optional deserializer function to convert the stored value back to type `T`. Defaults to `JSON.parse`.
|
|
157
|
+
* @returns Returns saved item from session storage if it exists with that key.
|
|
158
|
+
*/
|
|
159
|
+
function getFromSessionStorage(key, deserialize) {
|
|
160
|
+
const deserializer = deserialize ?? JSON.parse;
|
|
161
|
+
try {
|
|
162
|
+
const item = sessionStorage.getItem(key);
|
|
163
|
+
return item ? deserializer(item) : null;
|
|
164
|
+
} catch {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* * Save item in session storage.
|
|
170
|
+
*
|
|
171
|
+
* @param key - Key to save an item.
|
|
172
|
+
* @param value - The item/value to save.
|
|
173
|
+
* @param serialize - Optional serializer function to convert the value of type `T` to a string. Defaults to `JSON.stringify`.
|
|
174
|
+
*/
|
|
175
|
+
function saveToSessionStorage(key, value, serialize) {
|
|
176
|
+
const serializer = serialize ?? JSON.stringify;
|
|
177
|
+
try {
|
|
178
|
+
sessionStorage.setItem(key, serializer(value));
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.error(`Error saving item with key "${key}" in session storage:`, error);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* * Remove item from session storage.
|
|
185
|
+
*
|
|
186
|
+
* @param key - Key to delete item from session storage.
|
|
187
|
+
*/
|
|
188
|
+
function removeFromSessionStorage(key) {
|
|
189
|
+
try {
|
|
190
|
+
sessionStorage.removeItem(key);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error(`Error removing item with key "${key}" from session storage:`, error);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/dom/utils.ts
|
|
198
|
+
/**
|
|
199
|
+
* * Scrolls smoothly to the given element with an optional vertical offset.
|
|
200
|
+
* @param element The target element to scroll to.
|
|
201
|
+
* @param offset Additional vertical offset in pixels (positive moves down, negative moves up).
|
|
202
|
+
*/
|
|
203
|
+
function smoothScrollTo(element, offset = 0) {
|
|
204
|
+
element.scrollIntoView({
|
|
205
|
+
behavior: "smooth",
|
|
206
|
+
block: "start"
|
|
207
|
+
});
|
|
208
|
+
if (offset !== 0) setTimeout(() => {
|
|
209
|
+
window.scrollBy({
|
|
210
|
+
top: offset,
|
|
211
|
+
behavior: "smooth"
|
|
212
|
+
});
|
|
213
|
+
}, 300);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* * Toggles full-screen mode for a given element (or the `document` by default).
|
|
217
|
+
* @param element The element to toggle fullscreen mode for (default: document root).
|
|
218
|
+
*/
|
|
219
|
+
function toggleFullScreen(element = document.documentElement) {
|
|
220
|
+
const doc = document;
|
|
221
|
+
const elem = element;
|
|
222
|
+
if (!doc.fullscreenElement && !doc.webkitFullscreenElement) {
|
|
223
|
+
if (elem.requestFullscreen) elem.requestFullscreen();
|
|
224
|
+
else if (elem.webkitRequestFullscreen) elem.webkitRequestFullscreen();
|
|
225
|
+
} else if (doc.exitFullscreen) doc.exitFullscreen();
|
|
226
|
+
else if (doc.webkitExitFullscreen) doc.webkitExitFullscreen();
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* * Copies text to the clipboard, falling back to legacy methods if needed.
|
|
230
|
+
* @param text - The text to copy.
|
|
231
|
+
* @returns A promise that resolves when the text is copied.
|
|
232
|
+
*/
|
|
233
|
+
async function copyToClipboard(text) {
|
|
234
|
+
try {
|
|
235
|
+
if (navigator?.clipboard?.writeText) await navigator.clipboard.writeText(text);
|
|
236
|
+
else {
|
|
237
|
+
const textArea = document.createElement("textarea");
|
|
238
|
+
textArea.value = text;
|
|
239
|
+
textArea.style.position = "fixed";
|
|
240
|
+
textArea.style.opacity = "0";
|
|
241
|
+
document.body.appendChild(textArea);
|
|
242
|
+
textArea.select();
|
|
243
|
+
textArea.setSelectionRange(0, textArea.value?.length);
|
|
244
|
+
const success = document.execCommand("copy");
|
|
245
|
+
document.body.removeChild(textArea);
|
|
246
|
+
if (!success) throw new Error("Cannot execute command in this environment!");
|
|
247
|
+
}
|
|
248
|
+
} catch (error) {
|
|
249
|
+
console.error("Failed to copy text:", error);
|
|
250
|
+
throw error;
|
|
251
|
+
} finally {
|
|
252
|
+
const textArea = document.querySelector("textarea[style*=\"fixed\"]");
|
|
253
|
+
if (textArea) document.body.removeChild(textArea);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/form/convert.ts
|
|
259
|
+
/**
|
|
260
|
+
* * Utility to convert object into FormData in a controlled way.
|
|
261
|
+
* - **N.B.** Be cautious when using this in SSR (Server-Side Rendering) environments (such as `Next.js` Server Components), as it may not work as expected.
|
|
262
|
+
*
|
|
263
|
+
* @param data - The source object to control and convert to FormData.
|
|
264
|
+
* @param configs - Configuration options to control the formData.
|
|
265
|
+
* @returns `FormData` instance containing the sanitized and transformed data.
|
|
266
|
+
*/
|
|
267
|
+
const createControlledFormData = (data, configs) => {
|
|
268
|
+
const formData = new FormData();
|
|
269
|
+
const { stringifyNested = "*" } = configs || {};
|
|
270
|
+
/** - Helper to check if a key should be lowercase */
|
|
271
|
+
const _shouldLowercaseKeys = (key) => {
|
|
272
|
+
return Array.isArray(configs?.lowerCaseKeys) ? configs?.lowerCaseKeys?.some((path) => key === path || key.startsWith(`${path}.`)) : configs?.lowerCaseKeys === "*";
|
|
273
|
+
};
|
|
274
|
+
/** - Helper to check if a key should be lowercase */
|
|
275
|
+
const _shouldLowercaseValue = (key) => {
|
|
276
|
+
return Array.isArray(configs?.lowerCaseValues) ? configs.lowerCaseValues?.some((path) => key === path || key?.startsWith(`${path}.`)) : configs?.lowerCaseValues === "*";
|
|
277
|
+
};
|
|
278
|
+
/** - Transforms key to lowercase if needed */
|
|
279
|
+
const _transformKey = (key) => {
|
|
280
|
+
return _shouldLowercaseKeys(key) ? key.toLowerCase() : key;
|
|
281
|
+
};
|
|
282
|
+
/** - Helper function to check if a key matches a breakArray key. */
|
|
283
|
+
const _isRequiredKey = (key) => {
|
|
284
|
+
const transformedKey = _transformKey(key);
|
|
285
|
+
return Array.isArray(configs?.requiredKeys) ? configs?.requiredKeys?.some((path) => transformedKey === path || transformedKey?.startsWith(`${path}.`)) : configs?.requiredKeys === "*";
|
|
286
|
+
};
|
|
287
|
+
/** - Helper function to check if a key matches a dotNotation path to preserve. */
|
|
288
|
+
const _shouldDotNotate = (key) => {
|
|
289
|
+
const transformedKey = _transformKey(key);
|
|
290
|
+
return Array.isArray(configs?.dotNotateNested) ? configs.dotNotateNested.includes(transformedKey) : configs?.dotNotateNested === "*";
|
|
291
|
+
};
|
|
292
|
+
/** - Helper function to check if a key matches a stringifyNested key. */
|
|
293
|
+
const _shouldStringify = (key) => {
|
|
294
|
+
const transformedKey = _transformKey(key);
|
|
295
|
+
return Array.isArray(stringifyNested) ? stringifyNested.includes(transformedKey) : stringifyNested === "*";
|
|
296
|
+
};
|
|
297
|
+
/** - Helper function to check if a key matches a breakArray key. */
|
|
298
|
+
const _shouldBreakArray = (key) => {
|
|
299
|
+
const transformedKey = _transformKey(key);
|
|
300
|
+
return Array.isArray(configs?.breakArray) ? configs.breakArray.includes(transformedKey) : configs?.breakArray === "*";
|
|
301
|
+
};
|
|
302
|
+
/** - Helper to clean object by removing null/undefined/empty values while respecting required keys */
|
|
303
|
+
const _cleanObject = (obj, parentKey = "") => {
|
|
304
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
305
|
+
const transformedKey = _transformKey(key);
|
|
306
|
+
const fullKey = parentKey ? `${parentKey}.${transformedKey}` : transformedKey;
|
|
307
|
+
if (configs?.ignoreKeys?.includes(fullKey)) return acc;
|
|
308
|
+
if (value != null && value !== "" || _isRequiredKey(fullKey) || isNonEmptyString(value) || isValidArray(value) || isNotEmptyObject(value)) if (isNotEmptyObject(value)) if (isDateLike(value)) acc[transformedKey] = value;
|
|
309
|
+
else {
|
|
310
|
+
const cleaned = _cleanObject(value, fullKey);
|
|
311
|
+
if (_isRequiredKey(fullKey) || isNotEmptyObject(cleaned)) acc[transformedKey] = cleaned;
|
|
312
|
+
}
|
|
313
|
+
else if (isString(value)) if (isNonEmptyString(value)) {
|
|
314
|
+
let cleanString = value;
|
|
315
|
+
if (configs?.trimStrings) cleanString = cleanString?.trim();
|
|
316
|
+
if (_shouldLowercaseValue(fullKey)) cleanString = cleanString?.toLowerCase();
|
|
317
|
+
acc[transformedKey] = cleanString;
|
|
318
|
+
} else acc[transformedKey] = value;
|
|
319
|
+
else if (Array.isArray(value)) {
|
|
320
|
+
if (_isRequiredKey(fullKey) || isValidArray(value)) acc[transformedKey] = value;
|
|
321
|
+
} else if (isEmptyObject(value)) {
|
|
322
|
+
if (_isRequiredKey(fullKey)) acc[transformedKey] = value;
|
|
323
|
+
} else acc[transformedKey] = value;
|
|
324
|
+
return acc;
|
|
325
|
+
}, {});
|
|
326
|
+
};
|
|
327
|
+
/** * Helper function to add values to formData */
|
|
328
|
+
const _addToFormData = (key, value) => {
|
|
329
|
+
const transformedKey = _transformKey(key);
|
|
330
|
+
if (isCustomFileArray(value)) value?.forEach((file) => formData.append(transformedKey, file?.originFileObj));
|
|
331
|
+
else if (isFileUpload(value)) {
|
|
332
|
+
if (value?.fileList) value?.fileList.forEach((file) => formData.append(transformedKey, file?.originFileObj));
|
|
333
|
+
else if (value?.file) if (isCustomFile(value?.file)) formData.append(transformedKey, value?.file?.originFileObj);
|
|
334
|
+
else formData.append(transformedKey, value?.file);
|
|
335
|
+
} else if (isFileOrBlob(value)) formData.append(transformedKey, value);
|
|
336
|
+
else if (isFileList(value)) for (let i = 0; i < value?.length; i++) formData.append(transformedKey, value.item(i));
|
|
337
|
+
else if (Array.isArray(value)) {
|
|
338
|
+
if (isFileArray(value)) if (_shouldBreakArray(key)) value?.forEach((item, index) => {
|
|
339
|
+
_addToFormData(`${transformedKey}[${index}]`, item);
|
|
340
|
+
});
|
|
341
|
+
else value?.forEach((item) => {
|
|
342
|
+
formData.append(transformedKey, item);
|
|
343
|
+
});
|
|
344
|
+
else if (isValidArray(value)) if (_shouldBreakArray(key)) value?.forEach((item, index) => {
|
|
345
|
+
_addToFormData(`${transformedKey}[${index}]`, item);
|
|
346
|
+
});
|
|
347
|
+
else formData.append(transformedKey, JSON.stringify(value));
|
|
348
|
+
else if (_isRequiredKey(key)) formData.append(transformedKey, JSON.stringify(value));
|
|
349
|
+
} else if (isDateLike(value)) formData.append(transformedKey, JSON.parse(JSON.stringify(value)));
|
|
350
|
+
else if (isNotEmptyObject(value)) if (_shouldStringify(key) && !_shouldDotNotate(key)) {
|
|
351
|
+
const cleanedValue = _cleanObject(value, key);
|
|
352
|
+
if (isNotEmptyObject(cleanedValue) || _isRequiredKey(key)) formData.append(transformedKey, JSON.stringify(cleanedValue));
|
|
353
|
+
} else Object.entries(value).forEach(([nestedKey, nestedValue]) => {
|
|
354
|
+
_addToFormData(`${key}.${nestedKey}`, nestedValue);
|
|
355
|
+
});
|
|
356
|
+
else if (value != null && value !== "" || _isRequiredKey(key)) if (isString(value) && _shouldLowercaseValue(key)) formData.append(transformedKey, value?.toLowerCase());
|
|
357
|
+
else formData.append(transformedKey, value);
|
|
358
|
+
};
|
|
359
|
+
/** - Helper to process object */
|
|
360
|
+
const _processObject = (obj, parentKey = "") => {
|
|
361
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
362
|
+
const transformedKey = _transformKey(key);
|
|
363
|
+
const fullKey = parentKey ? `${parentKey}.${transformedKey}` : transformedKey;
|
|
364
|
+
if (configs?.ignoreKeys?.includes(fullKey)) return;
|
|
365
|
+
if (configs?.trimStrings && isNonEmptyString(value)) value = value?.trim();
|
|
366
|
+
if (_shouldDotNotate(fullKey)) _addToFormData(fullKey, value);
|
|
367
|
+
else if (isNotEmptyObject(value) && !_shouldStringify(fullKey)) if (isDateLike(value)) _addToFormData(key, JSON.parse(JSON.stringify(value)));
|
|
368
|
+
else _processObject(value, key);
|
|
369
|
+
else if (isFileOrBlob(value)) _addToFormData(key, value);
|
|
370
|
+
else if (isDateLike(value)) _addToFormData(key, JSON.parse(JSON.stringify(value)));
|
|
371
|
+
else if (isEmptyObject(value)) {
|
|
372
|
+
if (_isRequiredKey(fullKey)) _addToFormData(key, JSON.stringify(value));
|
|
373
|
+
} else _addToFormData(key, value);
|
|
374
|
+
});
|
|
375
|
+
};
|
|
376
|
+
if (isNotEmptyObject(data)) _processObject(data);
|
|
377
|
+
return formData;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/form/transform.ts
|
|
382
|
+
/**
|
|
383
|
+
* * Serialize form data into an object or a query string.
|
|
384
|
+
* - **N.B.** Be cautious when using this in SSR (Server-Side Rendering) environments (such as `Next.js` Server Components), as it may not work as expected.
|
|
385
|
+
*
|
|
386
|
+
* @param form - The form element to serialize.
|
|
387
|
+
* @param toQueryString - Whether to return the result as a query string. If false, returns an object.
|
|
388
|
+
* @returns The serialized form data as an object or query string.
|
|
389
|
+
*/
|
|
390
|
+
function serializeForm(form, toQueryString = false) {
|
|
391
|
+
const formData = new FormData(form);
|
|
392
|
+
const data = {};
|
|
393
|
+
formData?.forEach((value, key) => {
|
|
394
|
+
if (data[key]) data[key] = Array.isArray(data[key]) ? [...data[key], value.toString()] : [data[key], value.toString()];
|
|
395
|
+
else data[key] = value.toString();
|
|
396
|
+
});
|
|
397
|
+
if (toQueryString) return generateQueryParams(data);
|
|
398
|
+
return data;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* * Parse form data from a `FormData` object or query string into a structured object format.
|
|
402
|
+
*
|
|
403
|
+
* @param data - The `FormData` object or query string to parse.
|
|
404
|
+
* @param parsePrimitives - Whether to parse string values into primitive types (e.g., boolean, number, array, object). Defaults to `true`.
|
|
405
|
+
* @returns The parsed form data as an object.
|
|
406
|
+
*/
|
|
407
|
+
function parseFormData(data, parsePrimitives = true) {
|
|
408
|
+
const parsed = {};
|
|
409
|
+
if (isString(data)) new URLSearchParams(data)?.forEach((value, key) => {
|
|
410
|
+
const existing = parsed[key];
|
|
411
|
+
if (isString(existing)) parsed[key] = [existing, value];
|
|
412
|
+
else if (Array.isArray(existing)) parsed[key] = [...existing, value];
|
|
413
|
+
else parsed[key] = value;
|
|
414
|
+
});
|
|
415
|
+
else data?.forEach((value, key) => {
|
|
416
|
+
const existing = parsed[key];
|
|
417
|
+
if (value instanceof File) if (Array.isArray(existing)) parsed[key] = [...existing, value];
|
|
418
|
+
else if (existing instanceof File) parsed[key] = [existing, value];
|
|
419
|
+
else parsed[key] = value;
|
|
420
|
+
else if (isString(existing)) parsed[key] = [existing, value];
|
|
421
|
+
else if (Array.isArray(existing)) parsed[key] = [...existing, value];
|
|
422
|
+
else parsed[key] = value;
|
|
423
|
+
});
|
|
424
|
+
if (parsePrimitives) return parseObjectValues(parsed);
|
|
425
|
+
else return parsed;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
//#endregion
|
|
429
|
+
export { createControlledFormData as convertIntoFormData, createControlledFormData, createControlledFormData as createFormData, copyToClipboard, generateQueryParams as createQueryParams, generateQueryParams as formatQueryParams, generateQueryParams, getFromLocalStorage, getFromSessionStorage, getQueryParams, parseQueryString as getQueryStringAsObject, parseQueryString, parseQueryString as queryStringToObject, isCustomFile, isCustomFileArray, isFileArray, isFileList, isFileOrBlob, isFileUpload, isOriginFileObj, isValidFormData, parseQueryStringLiteral as literalQueryStringToObject, parseQueryStringLiteral, parseFormData, removeFromLocalStorage, removeFromSessionStorage, saveToLocalStorage, saveToSessionStorage, serializeForm, smoothScrollTo, toggleFullScreen, updateQueryParam };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { S as KeyForObject, T as NestedKeyString, u as DotNotationKey, x as KeyForArray } from "./object-B0TV3eHx.mjs";
|
|
18
|
+
import { P as QueryString } from "./string-CBAbxaG1.mjs";
|
|
19
|
+
|
|
20
|
+
//#region src/types/form.d.ts
|
|
21
|
+
/** - Configuration options to control FormData generation behavior. */
|
|
22
|
+
interface FormDataConfigs<T> {
|
|
23
|
+
/**
|
|
24
|
+
* * An array of dot-notation keys to exclude from processing.
|
|
25
|
+
* * Ignored keys are omitted entirely, even if included in other options.
|
|
26
|
+
*/
|
|
27
|
+
ignoreKeys?: DotNotationKey<T>[];
|
|
28
|
+
/**
|
|
29
|
+
* * Specifies which keys should be included even if their values are falsy.
|
|
30
|
+
* * Use `*` to preserve all keys.
|
|
31
|
+
*/
|
|
32
|
+
requiredKeys?: '*' | DotNotationKey<T>[];
|
|
33
|
+
/**
|
|
34
|
+
* * Defines which keys should be converted to lowercase.
|
|
35
|
+
* * Use `*` to apply to all keys.
|
|
36
|
+
*/
|
|
37
|
+
lowerCaseKeys?: '*' | DotNotationKey<T>[];
|
|
38
|
+
/**
|
|
39
|
+
* * Defines which values should be converted to lowercase.
|
|
40
|
+
* * Use `*` to apply to all keys.
|
|
41
|
+
*/
|
|
42
|
+
lowerCaseValues?: '*' | NestedKeyString<T>[];
|
|
43
|
+
/**
|
|
44
|
+
* * An array of keys (values must be object) to preserve in their original structure.
|
|
45
|
+
* - Use `*` to preserve all keys with object values in their dot-notation format.
|
|
46
|
+
* - If a key exists in both `dotNotateNested` and `stringifyNested`, `dotNotateNested` takes precedence.
|
|
47
|
+
*/
|
|
48
|
+
dotNotateNested?: '*' | KeyForObject<T>[];
|
|
49
|
+
/**
|
|
50
|
+
* * Specifies which keys (values must be objects) should be stringified instead of being dot-notated.
|
|
51
|
+
* - Defaults to `*`, meaning all keys with object values will be stringified. Which is standard in modern form submissions.
|
|
52
|
+
* - Use `*` to stringify all nested objects.
|
|
53
|
+
* - If a key exists in both `dotNotateNested` and `stringifyNested`, `dotNotateNested` takes precedence.
|
|
54
|
+
*/
|
|
55
|
+
stringifyNested?: '*' | KeyForObject<T>[];
|
|
56
|
+
/**
|
|
57
|
+
* * Controls how arrays should be serialized in FormData.
|
|
58
|
+
* - If a key is included, the array will be broken into individual key-value pairs (`key[0]: value, key[1]: value`).
|
|
59
|
+
* - Use `*` to apply this behavior to all array keys.
|
|
60
|
+
*/
|
|
61
|
+
breakArray?: '*' | KeyForArray<T>[];
|
|
62
|
+
/** - Enables automatic trimming of string values before appending them to FormData. */
|
|
63
|
+
trimStrings?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/** * Represents a file upload operation, commonly used in libraries like `FilePond` or `Ant Design Upload`. */
|
|
66
|
+
interface FileUpload {
|
|
67
|
+
/** The primary file being uploaded. */
|
|
68
|
+
file: File | CustomFile;
|
|
69
|
+
/** The list of files associated with the upload. */
|
|
70
|
+
fileList: CustomFile[];
|
|
71
|
+
}
|
|
72
|
+
/** * Represents a custom file structure used in file upload components. */
|
|
73
|
+
interface CustomFile {
|
|
74
|
+
/** Unique identifier for the file. */
|
|
75
|
+
uid: string;
|
|
76
|
+
/** The timestamp (milliseconds) when the file was last modified. */
|
|
77
|
+
lastModified: number;
|
|
78
|
+
/** A string representation of the last modified date. */
|
|
79
|
+
lastModifiedDate: Date;
|
|
80
|
+
/** The name of the file. */
|
|
81
|
+
name: string;
|
|
82
|
+
/** The size of the file in bytes. */
|
|
83
|
+
size: number;
|
|
84
|
+
/** The MIME type of the file. */
|
|
85
|
+
type: string;
|
|
86
|
+
/** Upload progress percentage (0-100). */
|
|
87
|
+
percent: number;
|
|
88
|
+
/** The original file object before any transformations. */
|
|
89
|
+
originFileObj: OriginFileObj;
|
|
90
|
+
/** The URL for a thumbnail preview of the file. */
|
|
91
|
+
thumbUrl: string;
|
|
92
|
+
/** Optional error information if the upload fails. */
|
|
93
|
+
error?: FileError;
|
|
94
|
+
/** Optional server response after a successful upload. */
|
|
95
|
+
response?: string;
|
|
96
|
+
/** Optional status of the file upload (e.g., "uploading", "done", "error"). */
|
|
97
|
+
status?: string;
|
|
98
|
+
}
|
|
99
|
+
/** * Represents the original file object before any modifications. */
|
|
100
|
+
interface OriginFileObj extends File {
|
|
101
|
+
/** Unique identifier for the original file. */
|
|
102
|
+
uid: string;
|
|
103
|
+
}
|
|
104
|
+
/** * Represents an error that occurs during a file upload. */
|
|
105
|
+
interface FileError extends Error {
|
|
106
|
+
/** HTTP status code of the error. */
|
|
107
|
+
status: number;
|
|
108
|
+
/** The HTTP method used for the request (e.g., "POST", "PUT"). */
|
|
109
|
+
method: string;
|
|
110
|
+
/** The URL where the upload was attempted. */
|
|
111
|
+
url: string;
|
|
112
|
+
}
|
|
113
|
+
/** THe return type of `serializeForm` wither as object or query string. */
|
|
114
|
+
type SerializedForm<T extends boolean> = T extends false ? Record<string, string | string[]> : QueryString;
|
|
115
|
+
/** * Represents the parsed form data. */
|
|
116
|
+
type ParsedFormData<T> = T extends string ? Record<string, string | string[]> : Record<string, string | string[] | File | File[]>;
|
|
117
|
+
//#endregion
|
|
118
|
+
export { OriginFileObj as a, FormDataConfigs as i, FileError as n, ParsedFormData as o, FileUpload as r, SerializedForm as s, CustomFile as t };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 - present Nazmul Hassan
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { S as KeyForObject, T as NestedKeyString, u as DotNotationKey, x as KeyForArray } from "./object-Blq0Amdv.cjs";
|
|
18
|
+
import { P as QueryString } from "./string-CsNsm_65.cjs";
|
|
19
|
+
|
|
20
|
+
//#region src/types/form.d.ts
|
|
21
|
+
/** - Configuration options to control FormData generation behavior. */
|
|
22
|
+
interface FormDataConfigs<T> {
|
|
23
|
+
/**
|
|
24
|
+
* * An array of dot-notation keys to exclude from processing.
|
|
25
|
+
* * Ignored keys are omitted entirely, even if included in other options.
|
|
26
|
+
*/
|
|
27
|
+
ignoreKeys?: DotNotationKey<T>[];
|
|
28
|
+
/**
|
|
29
|
+
* * Specifies which keys should be included even if their values are falsy.
|
|
30
|
+
* * Use `*` to preserve all keys.
|
|
31
|
+
*/
|
|
32
|
+
requiredKeys?: '*' | DotNotationKey<T>[];
|
|
33
|
+
/**
|
|
34
|
+
* * Defines which keys should be converted to lowercase.
|
|
35
|
+
* * Use `*` to apply to all keys.
|
|
36
|
+
*/
|
|
37
|
+
lowerCaseKeys?: '*' | DotNotationKey<T>[];
|
|
38
|
+
/**
|
|
39
|
+
* * Defines which values should be converted to lowercase.
|
|
40
|
+
* * Use `*` to apply to all keys.
|
|
41
|
+
*/
|
|
42
|
+
lowerCaseValues?: '*' | NestedKeyString<T>[];
|
|
43
|
+
/**
|
|
44
|
+
* * An array of keys (values must be object) to preserve in their original structure.
|
|
45
|
+
* - Use `*` to preserve all keys with object values in their dot-notation format.
|
|
46
|
+
* - If a key exists in both `dotNotateNested` and `stringifyNested`, `dotNotateNested` takes precedence.
|
|
47
|
+
*/
|
|
48
|
+
dotNotateNested?: '*' | KeyForObject<T>[];
|
|
49
|
+
/**
|
|
50
|
+
* * Specifies which keys (values must be objects) should be stringified instead of being dot-notated.
|
|
51
|
+
* - Defaults to `*`, meaning all keys with object values will be stringified. Which is standard in modern form submissions.
|
|
52
|
+
* - Use `*` to stringify all nested objects.
|
|
53
|
+
* - If a key exists in both `dotNotateNested` and `stringifyNested`, `dotNotateNested` takes precedence.
|
|
54
|
+
*/
|
|
55
|
+
stringifyNested?: '*' | KeyForObject<T>[];
|
|
56
|
+
/**
|
|
57
|
+
* * Controls how arrays should be serialized in FormData.
|
|
58
|
+
* - If a key is included, the array will be broken into individual key-value pairs (`key[0]: value, key[1]: value`).
|
|
59
|
+
* - Use `*` to apply this behavior to all array keys.
|
|
60
|
+
*/
|
|
61
|
+
breakArray?: '*' | KeyForArray<T>[];
|
|
62
|
+
/** - Enables automatic trimming of string values before appending them to FormData. */
|
|
63
|
+
trimStrings?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/** * Represents a file upload operation, commonly used in libraries like `FilePond` or `Ant Design Upload`. */
|
|
66
|
+
interface FileUpload {
|
|
67
|
+
/** The primary file being uploaded. */
|
|
68
|
+
file: File | CustomFile;
|
|
69
|
+
/** The list of files associated with the upload. */
|
|
70
|
+
fileList: CustomFile[];
|
|
71
|
+
}
|
|
72
|
+
/** * Represents a custom file structure used in file upload components. */
|
|
73
|
+
interface CustomFile {
|
|
74
|
+
/** Unique identifier for the file. */
|
|
75
|
+
uid: string;
|
|
76
|
+
/** The timestamp (milliseconds) when the file was last modified. */
|
|
77
|
+
lastModified: number;
|
|
78
|
+
/** A string representation of the last modified date. */
|
|
79
|
+
lastModifiedDate: Date;
|
|
80
|
+
/** The name of the file. */
|
|
81
|
+
name: string;
|
|
82
|
+
/** The size of the file in bytes. */
|
|
83
|
+
size: number;
|
|
84
|
+
/** The MIME type of the file. */
|
|
85
|
+
type: string;
|
|
86
|
+
/** Upload progress percentage (0-100). */
|
|
87
|
+
percent: number;
|
|
88
|
+
/** The original file object before any transformations. */
|
|
89
|
+
originFileObj: OriginFileObj;
|
|
90
|
+
/** The URL for a thumbnail preview of the file. */
|
|
91
|
+
thumbUrl: string;
|
|
92
|
+
/** Optional error information if the upload fails. */
|
|
93
|
+
error?: FileError;
|
|
94
|
+
/** Optional server response after a successful upload. */
|
|
95
|
+
response?: string;
|
|
96
|
+
/** Optional status of the file upload (e.g., "uploading", "done", "error"). */
|
|
97
|
+
status?: string;
|
|
98
|
+
}
|
|
99
|
+
/** * Represents the original file object before any modifications. */
|
|
100
|
+
interface OriginFileObj extends File {
|
|
101
|
+
/** Unique identifier for the original file. */
|
|
102
|
+
uid: string;
|
|
103
|
+
}
|
|
104
|
+
/** * Represents an error that occurs during a file upload. */
|
|
105
|
+
interface FileError extends Error {
|
|
106
|
+
/** HTTP status code of the error. */
|
|
107
|
+
status: number;
|
|
108
|
+
/** The HTTP method used for the request (e.g., "POST", "PUT"). */
|
|
109
|
+
method: string;
|
|
110
|
+
/** The URL where the upload was attempted. */
|
|
111
|
+
url: string;
|
|
112
|
+
}
|
|
113
|
+
/** THe return type of `serializeForm` wither as object or query string. */
|
|
114
|
+
type SerializedForm<T extends boolean> = T extends false ? Record<string, string | string[]> : QueryString;
|
|
115
|
+
/** * Represents the parsed form data. */
|
|
116
|
+
type ParsedFormData<T> = T extends string ? Record<string, string | string[]> : Record<string, string | string[] | File | File[]>;
|
|
117
|
+
//#endregion
|
|
118
|
+
export { OriginFileObj as a, FormDataConfigs as i, FileError as n, ParsedFormData as o, FileUpload as r, SerializedForm as s, CustomFile as t };
|