toolbox-x 2.0.12 → 2.0.14

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.
@@ -19,6 +19,8 @@ import { E as NestedPrimitiveKey, ot as NormalPrimitiveKey, y as GenericObject }
19
19
  //#region src/types/array.d.ts
20
20
  /** * Flatten Array or Wrap in Array */
21
21
  type Flattened<T> = T extends (infer U)[] ? Flattened<U> : T;
22
+ /** * Union of type `T` and array of `T` */
23
+ type TypeOrArray<T> = T | Array<T>;
22
24
  /**
23
25
  * * Configuration for `createOptionsArray`.
24
26
  * - Defines the mapping between keys in the input objects and the keys in the output options.
@@ -127,4 +129,4 @@ interface FindOptions<T extends GenericObject = {}> {
127
129
  data?: T[] | (() => T[]);
128
130
  }
129
131
  //#endregion
130
- export { Flattened as a, OrderOption as c, SortOptions as d, FirstFieldValue as i, SortByOption as l, FindOptions as n, Option as o, FirstFieldKey as r, OptionsConfig as s, FieldValue as t, SortNature as u };
132
+ export { Flattened as a, OrderOption as c, SortOptions as d, TypeOrArray as f, FirstFieldValue as i, SortByOption as l, FindOptions as n, Option as o, FirstFieldKey as r, OptionsConfig as s, FieldValue as t, SortNature as u };
@@ -19,6 +19,8 @@ import { E as NestedPrimitiveKey, ot as NormalPrimitiveKey, y as GenericObject }
19
19
  //#region src/types/array.d.ts
20
20
  /** * Flatten Array or Wrap in Array */
21
21
  type Flattened<T> = T extends (infer U)[] ? Flattened<U> : T;
22
+ /** * Union of type `T` and array of `T` */
23
+ type TypeOrArray<T> = T | Array<T>;
22
24
  /**
23
25
  * * Configuration for `createOptionsArray`.
24
26
  * - Defines the mapping between keys in the input objects and the keys in the output options.
@@ -127,4 +129,4 @@ interface FindOptions<T extends GenericObject = {}> {
127
129
  data?: T[] | (() => T[]);
128
130
  }
129
131
  //#endregion
130
- export { Flattened as a, OrderOption as c, SortOptions as d, FirstFieldValue as i, SortByOption as l, FindOptions as n, Option as o, FirstFieldKey as r, OptionsConfig as s, FieldValue as t, SortNature as u };
132
+ export { Flattened as a, OrderOption as c, SortOptions as d, TypeOrArray as f, FirstFieldValue as i, SortByOption as l, FindOptions as n, Option as o, FirstFieldKey as r, OptionsConfig as s, FieldValue as t, SortNature as u };
package/dist/dom.cjs CHANGED
@@ -18,93 +18,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
18
18
  const require_primitives = require('./primitives-CBGICrDR.cjs');
19
19
  const require_specials = require('./specials-dkYP1Nh2.cjs');
20
20
  const require_basics = require('./basics-Bb5ovcvz.cjs');
21
- const require_objectify = require('./objectify--6hPlQ7r.cjs');
21
+ const require_query = require('./query-BUBCpo-q.cjs');
22
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 = require_objectify.flattenObjectKeyValue(params);
39
- const queryParams = Object.entries(flattenedParams)?.filter(([_, value]) => value != null && !(require_primitives.isString(value) && value?.trim() === ""))?.flatMap(([key, value]) => Array.isArray(value) ? value?.filter((v) => v != null && !(require_primitives.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 ? require_basics.deepParsePrimitives(array) : array;
82
- } else entries[key] = value;
83
- return parsePrimitives ? require_objectify.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
23
  //#region src/dom/storage.ts
109
24
  /**
110
25
  * * Get item from local storage.
@@ -338,15 +253,15 @@ const createFormData = (data, configs) => {
338
253
  const _addToFormData = (key, value) => {
339
254
  const transformedKey = _transformKey(key);
340
255
  if (_compareKeyPaths(transformedKey, ignoreKeys)) return;
341
- if (require_objectify.isCustomFileArray(value)) value?.forEach((file) => formData.append(transformedKey, file?.originFileObj));
342
- else if (require_objectify.isFileUpload(value)) {
343
- if (value?.fileList) value?.fileList.forEach((file) => formData.append(transformedKey, file?.originFileObj));
344
- else if (value?.file) if (require_objectify.isCustomFile(value?.file)) formData.append(transformedKey, value?.file?.originFileObj);
256
+ if (require_query.isCustomFileArray(value)) for (const file of value) formData.append(transformedKey, file?.originFileObj);
257
+ else if (require_query.isFileUpload(value)) {
258
+ if (value?.fileList) for (const file of value.fileList) formData.append(transformedKey, file?.originFileObj);
259
+ else if (value?.file) if (require_query.isCustomFile(value?.file)) formData.append(transformedKey, value?.file?.originFileObj);
345
260
  else formData.append(transformedKey, value?.file);
346
- } else if (require_objectify.isFileOrBlob(value)) formData.append(transformedKey, value);
347
- else if (require_objectify.isFileList(value)) for (let i = 0; i < value?.length; i++) formData.append(transformedKey, value.item(i));
261
+ } else if (require_query.isFileOrBlob(value)) formData.append(transformedKey, value);
262
+ else if (require_query.isFileList(value)) for (let i = 0; i < value?.length; i++) formData.append(transformedKey, value?.item(i));
348
263
  else if (Array.isArray(value)) {
349
- if (require_objectify.isFileArray(value)) if (_shouldBreakArray(key)) value?.forEach((item, index) => {
264
+ if (require_query.isFileArray(value)) if (_shouldBreakArray(key)) value?.forEach((item, index) => {
350
265
  _addToFormData(`${transformedKey}[${index}]`, item);
351
266
  });
352
267
  else value?.forEach((item) => {
@@ -381,7 +296,7 @@ const createFormData = (data, configs) => {
381
296
  if (_shouldDotNotate(fullKey)) _addToFormData(fullKey, value);
382
297
  else if (require_specials.isNotEmptyObject(value) && !_shouldStringify(fullKey)) if (require_basics.isDateLike(value)) _addToFormData(key, _parseDateLike(value));
383
298
  else _processObject(value, key);
384
- else if (require_objectify.isFileOrBlob(value)) _addToFormData(key, value);
299
+ else if (require_query.isFileOrBlob(value)) _addToFormData(key, value);
385
300
  else if (require_basics.isDateLike(value)) _addToFormData(key, _parseDateLike(value));
386
301
  else if (require_specials.isEmptyObject(value)) {
387
302
  if (_isRequiredKey(fullKey)) _addToFormData(key, JSON.stringify(value));
@@ -409,7 +324,7 @@ function serializeForm(form, toQueryString = false) {
409
324
  if (data[key]) data[key] = Array.isArray(data[key]) ? [...data[key], value.toString()] : [data[key], value.toString()];
410
325
  else data[key] = value.toString();
411
326
  });
412
- if (toQueryString) return generateQueryParams(data);
327
+ if (toQueryString) return require_query.generateQueryParams(data);
413
328
  return data;
414
329
  }
415
330
  /**
@@ -436,7 +351,7 @@ function parseFormData(data, parsePrimitives = true) {
436
351
  else if (Array.isArray(existing)) parsed[key] = [...existing, value];
437
352
  else parsed[key] = value;
438
353
  });
439
- if (parsePrimitives) return require_objectify.parseObjectValues(parsed);
354
+ if (parsePrimitives) return require_query.parseObjectValues(parsed);
440
355
  else return parsed;
441
356
  }
442
357
 
@@ -444,26 +359,26 @@ function parseFormData(data, parsePrimitives = true) {
444
359
  exports.convertToFormData = createFormData;
445
360
  exports.copyToClipboard = copyToClipboard;
446
361
  exports.createFormData = createFormData;
447
- exports.createQueryParams = generateQueryParams;
448
- exports.formatQueryParams = generateQueryParams;
449
- exports.generateQueryParams = generateQueryParams;
362
+ exports.createQueryParams = require_query.generateQueryParams;
363
+ exports.formatQueryParams = require_query.generateQueryParams;
364
+ exports.generateQueryParams = require_query.generateQueryParams;
450
365
  exports.getFromLocalStorage = getFromLocalStorage;
451
366
  exports.getFromSessionStorage = getFromSessionStorage;
452
- exports.getQueryParams = getQueryParams;
453
- exports.getQueryStringAsObject = parseQueryString;
454
- exports.isCustomFile = require_objectify.isCustomFile;
455
- exports.isCustomFileArray = require_objectify.isCustomFileArray;
456
- exports.isFileArray = require_objectify.isFileArray;
457
- exports.isFileList = require_objectify.isFileList;
458
- exports.isFileOrBlob = require_objectify.isFileOrBlob;
459
- exports.isFileUpload = require_objectify.isFileUpload;
460
- exports.isOriginFileObj = require_objectify.isOriginFileObj;
461
- exports.isValidFormData = require_objectify.isValidFormData;
462
- exports.literalQueryStringToObject = parseQueryStringLiteral;
367
+ exports.getQueryParams = require_query.getQueryParams;
368
+ exports.getQueryStringAsObject = require_query.parseQueryString;
369
+ exports.isCustomFile = require_query.isCustomFile;
370
+ exports.isCustomFileArray = require_query.isCustomFileArray;
371
+ exports.isFileArray = require_query.isFileArray;
372
+ exports.isFileList = require_query.isFileList;
373
+ exports.isFileOrBlob = require_query.isFileOrBlob;
374
+ exports.isFileUpload = require_query.isFileUpload;
375
+ exports.isOriginFileObj = require_query.isOriginFileObj;
376
+ exports.isValidFormData = require_query.isValidFormData;
377
+ exports.literalQueryStringToObject = require_query.parseQueryStringLiteral;
463
378
  exports.parseFormData = parseFormData;
464
- exports.parseQueryString = parseQueryString;
465
- exports.parseQueryStringLiteral = parseQueryStringLiteral;
466
- exports.queryStringToObject = parseQueryString;
379
+ exports.parseQueryString = require_query.parseQueryString;
380
+ exports.parseQueryStringLiteral = require_query.parseQueryStringLiteral;
381
+ exports.queryStringToObject = require_query.parseQueryString;
467
382
  exports.removeFromLocalStorage = removeFromLocalStorage;
468
383
  exports.removeFromSessionStorage = removeFromSessionStorage;
469
384
  exports.saveToLocalStorage = saveToLocalStorage;
@@ -471,4 +386,4 @@ exports.saveToSessionStorage = saveToSessionStorage;
471
386
  exports.serializeForm = serializeForm;
472
387
  exports.smoothScrollTo = smoothScrollTo;
473
388
  exports.toggleFullScreen = toggleFullScreen;
474
- exports.updateQueryParam = updateQueryParam;
389
+ exports.updateQueryParam = require_query.updateQueryParam;
package/dist/dom.d.cts CHANGED
@@ -14,67 +14,10 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { J as Deserializer, M as ParsedQueryGeneric, N as QueryObject, ft as Serializer, j as ParsedQuery, y as GenericObject } from "./object-DyVg8BFt.cjs";
18
- import { F as QueryString } from "./string-EMT7czsU.cjs";
19
- import { a as OriginFileObj, i as FormDataConfigs, o as ParsedFormData, r as FileUpload, s as SerializedForm, t as CustomFile } from "./form-CHFqlgPr.cjs";
17
+ import { J as Deserializer, ft as Serializer, y as GenericObject } from "./object-DyVg8BFt.cjs";
18
+ import { a as updateQueryParam, i as parseQueryStringLiteral, n as getQueryParams, r as parseQueryString, t as generateQueryParams } from "./query-BLsaWi3q.cjs";
19
+ import { a as OriginFileObj, i as FormDataConfigs, o as ParsedFormData, r as FileUpload, s as SerializedForm, t as CustomFile } from "./form-DA-YShnM.cjs";
20
20
 
21
- //#region src/dom/query.d.ts
22
- /**
23
- * * Utility to generate query parameters from an object.
24
- *
25
- * @param params - Object containing query parameters.
26
- * @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
27
- *
28
- * @example
29
- * generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
30
- * generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
31
- * generateQueryParams({ key1: '', key2: null }); // ""
32
- * generateQueryParams({ key1: true, key2: false }); // "?key1=true&key2=false"
33
- * generateQueryParams({ filters: { category: 'laptop', price: 1000 } }); // "?category=laptop&price=1000"
34
- */
35
- declare function generateQueryParams<T extends QueryObject>(params?: T): QueryString;
36
- /**
37
- * * Get query params as standard `JavaScript` Object `Record<string, string>`. You can define the type by passing a type argument.
38
- *
39
- * - **Note:** *Extracts query parameters from the current URL (window.location.search).*
40
- *
41
- * @returns Query string as key-value paired object. `Record<string, string>`.
42
- */
43
- declare function getQueryParams<QParams extends Record<string, string>>(): QParams;
44
- /**
45
- * * Update query params in the browser URL with given key and value.
46
- * @param key Key for the query to update.
47
- * @param value Value to updated against the given key.
48
- */
49
- declare function updateQueryParam(key: string, value: string): void;
50
- /**
51
- * Parses a query string (with optional `?` prefix) into an object.
52
- * Supports multiple values for the same key by returning arrays.
53
- * Optionally parses primitive string values into actual types (e.g., "1" → 1, "true" → true).
54
- *
55
- * @remarks This utility is designed to parse generic string, for literal use, try {@link parseQueryStringLiteral}.
56
- *
57
- * - **Note:** *This function does **not** access or depend on `current URL` a.k.a `window.location.search`.*
58
- *
59
- * @param query - The query string to parse.
60
- * @param parsePrimitives - Whether to convert stringified primitives into real values (default: true).
61
- * @returns An object where keys are strings and values can be string, array, number, boolean, or null/undefined.
62
- */
63
- declare function parseQueryString<QParams extends ParsedQueryGeneric>(query: string, parsePrimitives?: boolean): QParams;
64
- /**
65
- * Parses a query string (with optional `?` prefix) into an object.
66
- * Supports multiple values for the same key by returning arrays.
67
- * It returns properly typed object.
68
- *
69
- * @remarks This utility is designed to parse literal string, for generic use, try {@link parseQueryString}.
70
- *
71
- * - **Note:** *This function does **not** access or depend on `current URL` a.k.a `window.location.search`.*
72
- *
73
- * @param query - The literal query string to parse.
74
- * @returns An object where keys are strings and values can be string, array, or null/undefined.
75
- */
76
- declare function parseQueryStringLiteral<Q extends string>(query: Q): ParsedQuery<Q>;
77
- //#endregion
78
21
  //#region src/dom/storage.d.ts
79
22
  /**
80
23
  * * Get item from local storage.
@@ -223,6 +166,6 @@ declare function serializeForm<T extends boolean = false>(form: HTMLFormElement,
223
166
  * @param parsePrimitives - Whether to parse string values into primitive types (e.g., boolean, number, array, object). Defaults to `true`.
224
167
  * @returns The parsed form data as an object.
225
168
  */
226
- declare function parseFormData<T extends FormData | string>(data: T, parsePrimitives?: boolean): ParsedFormData<T>;
169
+ declare function parseFormData<D extends FormData | string, P extends boolean = true>(data: D, parsePrimitives?: P): ParsedFormData<D, P>;
227
170
  //#endregion
228
171
  export { createFormData as convertToFormData, 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 };
package/dist/dom.d.mts CHANGED
@@ -14,67 +14,10 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { J as Deserializer, M as ParsedQueryGeneric, N as QueryObject, ft as Serializer, j as ParsedQuery, y as GenericObject } from "./object-DyVg8BFt.mjs";
18
- import { F as QueryString } from "./string-GQsmDdYa.mjs";
19
- import { a as OriginFileObj, i as FormDataConfigs, o as ParsedFormData, r as FileUpload, s as SerializedForm, t as CustomFile } from "./form-crhNgN40.mjs";
17
+ import { J as Deserializer, ft as Serializer, y as GenericObject } from "./object-DyVg8BFt.mjs";
18
+ import { a as updateQueryParam, i as parseQueryStringLiteral, n as getQueryParams, r as parseQueryString, t as generateQueryParams } from "./query-Bi_ofCBp.mjs";
19
+ import { a as OriginFileObj, i as FormDataConfigs, o as ParsedFormData, r as FileUpload, s as SerializedForm, t as CustomFile } from "./form-DIYoIS0E.mjs";
20
20
 
21
- //#region src/dom/query.d.ts
22
- /**
23
- * * Utility to generate query parameters from an object.
24
- *
25
- * @param params - Object containing query parameters.
26
- * @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
27
- *
28
- * @example
29
- * generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
30
- * generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
31
- * generateQueryParams({ key1: '', key2: null }); // ""
32
- * generateQueryParams({ key1: true, key2: false }); // "?key1=true&key2=false"
33
- * generateQueryParams({ filters: { category: 'laptop', price: 1000 } }); // "?category=laptop&price=1000"
34
- */
35
- declare function generateQueryParams<T extends QueryObject>(params?: T): QueryString;
36
- /**
37
- * * Get query params as standard `JavaScript` Object `Record<string, string>`. You can define the type by passing a type argument.
38
- *
39
- * - **Note:** *Extracts query parameters from the current URL (window.location.search).*
40
- *
41
- * @returns Query string as key-value paired object. `Record<string, string>`.
42
- */
43
- declare function getQueryParams<QParams extends Record<string, string>>(): QParams;
44
- /**
45
- * * Update query params in the browser URL with given key and value.
46
- * @param key Key for the query to update.
47
- * @param value Value to updated against the given key.
48
- */
49
- declare function updateQueryParam(key: string, value: string): void;
50
- /**
51
- * Parses a query string (with optional `?` prefix) into an object.
52
- * Supports multiple values for the same key by returning arrays.
53
- * Optionally parses primitive string values into actual types (e.g., "1" → 1, "true" → true).
54
- *
55
- * @remarks This utility is designed to parse generic string, for literal use, try {@link parseQueryStringLiteral}.
56
- *
57
- * - **Note:** *This function does **not** access or depend on `current URL` a.k.a `window.location.search`.*
58
- *
59
- * @param query - The query string to parse.
60
- * @param parsePrimitives - Whether to convert stringified primitives into real values (default: true).
61
- * @returns An object where keys are strings and values can be string, array, number, boolean, or null/undefined.
62
- */
63
- declare function parseQueryString<QParams extends ParsedQueryGeneric>(query: string, parsePrimitives?: boolean): QParams;
64
- /**
65
- * Parses a query string (with optional `?` prefix) into an object.
66
- * Supports multiple values for the same key by returning arrays.
67
- * It returns properly typed object.
68
- *
69
- * @remarks This utility is designed to parse literal string, for generic use, try {@link parseQueryString}.
70
- *
71
- * - **Note:** *This function does **not** access or depend on `current URL` a.k.a `window.location.search`.*
72
- *
73
- * @param query - The literal query string to parse.
74
- * @returns An object where keys are strings and values can be string, array, or null/undefined.
75
- */
76
- declare function parseQueryStringLiteral<Q extends string>(query: Q): ParsedQuery<Q>;
77
- //#endregion
78
21
  //#region src/dom/storage.d.ts
79
22
  /**
80
23
  * * Get item from local storage.
@@ -223,6 +166,6 @@ declare function serializeForm<T extends boolean = false>(form: HTMLFormElement,
223
166
  * @param parsePrimitives - Whether to parse string values into primitive types (e.g., boolean, number, array, object). Defaults to `true`.
224
167
  * @returns The parsed form data as an object.
225
168
  */
226
- declare function parseFormData<T extends FormData | string>(data: T, parsePrimitives?: boolean): ParsedFormData<T>;
169
+ declare function parseFormData<D extends FormData | string, P extends boolean = true>(data: D, parsePrimitives?: P): ParsedFormData<D, P>;
227
170
  //#endregion
228
171
  export { createFormData as convertToFormData, 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 };
package/dist/dom.mjs CHANGED
@@ -16,94 +16,9 @@
16
16
 
17
17
  import { a as isNonEmptyString, d as isString } from "./primitives-Djsevc69.mjs";
18
18
  import { j as isValidArray, v as isEmptyObject, w as isNotEmptyObject } from "./specials-Hq5Ncd6y.mjs";
19
- import { I as deepParsePrimitives, J as isDateLike, n as trimString } from "./basics-Dald7J6c.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-BoIZEKOL.mjs";
19
+ import { J as isDateLike, n as trimString } from "./basics-Dald7J6c.mjs";
20
+ import { C as isValidFormData, S as isOriginFileObj, _ as isCustomFileArray, a as updateQueryParam, b as isFileOrBlob, g as isCustomFile, i as parseQueryStringLiteral, m as parseObjectValues, n as getQueryParams, r as parseQueryString, t as generateQueryParams, v as isFileArray, x as isFileUpload, y as isFileList } from "./query-B4Lrr5Vt.mjs";
21
21
 
22
- //#region src/dom/query.ts
23
- /**
24
- * * Utility to generate query parameters from an object.
25
- *
26
- * @param params - Object containing query parameters.
27
- * @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
28
- *
29
- * @example
30
- * generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
31
- * generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
32
- * generateQueryParams({ key1: '', key2: null }); // ""
33
- * generateQueryParams({ key1: true, key2: false }); // "?key1=true&key2=false"
34
- * generateQueryParams({ filters: { category: 'laptop', price: 1000 } }); // "?category=laptop&price=1000"
35
- */
36
- function generateQueryParams(params = {}) {
37
- const flattenedParams = flattenObjectKeyValue(params);
38
- 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("&");
39
- return queryParams ? `?${queryParams}` : "";
40
- }
41
- /**
42
- * * Get query params as standard `JavaScript` Object `Record<string, string>`. You can define the type by passing a type argument.
43
- *
44
- * - **Note:** *Extracts query parameters from the current URL (window.location.search).*
45
- *
46
- * @returns Query string as key-value paired object. `Record<string, string>`.
47
- */
48
- function getQueryParams() {
49
- return Object.fromEntries(new URLSearchParams(window?.location?.search));
50
- }
51
- /**
52
- * * Update query params in the browser URL with given key and value.
53
- * @param key Key for the query to update.
54
- * @param value Value to updated against the given key.
55
- */
56
- function updateQueryParam(key, value) {
57
- const url = new URL(window.location.href);
58
- url.searchParams.set(key, value);
59
- window.history.replaceState({}, "", url?.toString());
60
- }
61
- /**
62
- * Parses a query string (with optional `?` prefix) into an object.
63
- * Supports multiple values for the same key by returning arrays.
64
- * Optionally parses primitive string values into actual types (e.g., "1" → 1, "true" → true).
65
- *
66
- * @remarks This utility is designed to parse generic string, for literal use, try {@link parseQueryStringLiteral}.
67
- *
68
- * - **Note:** *This function does **not** access or depend on `current URL` a.k.a `window.location.search`.*
69
- *
70
- * @param query - The query string to parse.
71
- * @param parsePrimitives - Whether to convert stringified primitives into real values (default: true).
72
- * @returns An object where keys are strings and values can be string, array, number, boolean, or null/undefined.
73
- */
74
- function parseQueryString(query, parsePrimitives = true) {
75
- const params = new URLSearchParams(query.startsWith("?") ? query.slice(1) : query);
76
- const entries = {};
77
- for (const [key, value] of params.entries()) if (key in entries) {
78
- const current = entries[key];
79
- const array = Array.isArray(current) ? [...current, value] : [current, value];
80
- entries[key] = parsePrimitives ? deepParsePrimitives(array) : array;
81
- } else entries[key] = value;
82
- return parsePrimitives ? parseObjectValues(entries) : entries;
83
- }
84
- /**
85
- * Parses a query string (with optional `?` prefix) into an object.
86
- * Supports multiple values for the same key by returning arrays.
87
- * It returns properly typed object.
88
- *
89
- * @remarks This utility is designed to parse literal string, for generic use, try {@link parseQueryString}.
90
- *
91
- * - **Note:** *This function does **not** access or depend on `current URL` a.k.a `window.location.search`.*
92
- *
93
- * @param query - The literal query string to parse.
94
- * @returns An object where keys are strings and values can be string, array, or null/undefined.
95
- */
96
- function parseQueryStringLiteral(query) {
97
- const params = new URLSearchParams(query.startsWith("?") ? query.slice(1) : query);
98
- const entries = {};
99
- for (const [key, value] of params.entries()) if (key in entries) {
100
- const current = entries[key];
101
- entries[key] = Array.isArray(current) ? [...current, value] : [current, value];
102
- } else entries[key] = value;
103
- return entries;
104
- }
105
-
106
- //#endregion
107
22
  //#region src/dom/storage.ts
108
23
  /**
109
24
  * * Get item from local storage.
@@ -337,13 +252,13 @@ const createFormData = (data, configs) => {
337
252
  const _addToFormData = (key, value) => {
338
253
  const transformedKey = _transformKey(key);
339
254
  if (_compareKeyPaths(transformedKey, ignoreKeys)) return;
340
- if (isCustomFileArray(value)) value?.forEach((file) => formData.append(transformedKey, file?.originFileObj));
255
+ if (isCustomFileArray(value)) for (const file of value) formData.append(transformedKey, file?.originFileObj);
341
256
  else if (isFileUpload(value)) {
342
- if (value?.fileList) value?.fileList.forEach((file) => formData.append(transformedKey, file?.originFileObj));
257
+ if (value?.fileList) for (const file of value.fileList) formData.append(transformedKey, file?.originFileObj);
343
258
  else if (value?.file) if (isCustomFile(value?.file)) formData.append(transformedKey, value?.file?.originFileObj);
344
259
  else formData.append(transformedKey, value?.file);
345
260
  } else if (isFileOrBlob(value)) formData.append(transformedKey, value);
346
- else if (isFileList(value)) for (let i = 0; i < value?.length; i++) formData.append(transformedKey, value.item(i));
261
+ else if (isFileList(value)) for (let i = 0; i < value?.length; i++) formData.append(transformedKey, value?.item(i));
347
262
  else if (Array.isArray(value)) {
348
263
  if (isFileArray(value)) if (_shouldBreakArray(key)) value?.forEach((item, index) => {
349
264
  _addToFormData(`${transformedKey}[${index}]`, item);
@@ -14,8 +14,9 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { S as KeyForObject, T as NestedKeyString, ai as RequireExactly, u as DotNotationKey, x as KeyForArray } from "./object-DyVg8BFt.cjs";
17
+ import { S as KeyForObject, T as NestedKeyString, ai as RequireExactly, at as NormalPrimitive, u as DotNotationKey, x as KeyForArray } from "./object-DyVg8BFt.cjs";
18
18
  import { F as QueryString } from "./string-EMT7czsU.cjs";
19
+ import { f as TypeOrArray } from "./array-EVkwcL_k.cjs";
19
20
 
20
21
  //#region src/types/form.d.ts
21
22
  /** - Configuration options to control FormData generation behavior. */
@@ -111,6 +112,6 @@ interface FileError extends Error {
111
112
  /** THe return type of `serializeForm` wither as object or query string. */
112
113
  type SerializedForm<T extends boolean> = T extends false ? Record<string, string | string[]> : QueryString;
113
114
  /** * Represents the parsed form data. */
114
- type ParsedFormData<T> = T extends string ? Record<string, string | string[]> : Record<string, string | string[] | File | File[]>;
115
+ type ParsedFormData<T extends FormData | string, P extends boolean> = T extends string ? Record<string, P extends true ? TypeOrArray<NormalPrimitive> : TypeOrArray<string>> : Record<string, P extends true ? TypeOrArray<NormalPrimitive | File> : TypeOrArray<string | File>>;
115
116
  //#endregion
116
117
  export { OriginFileObj as a, FormDataConfigs as i, FileError as n, ParsedFormData as o, FileUpload as r, SerializedForm as s, CustomFile as t };
@@ -14,8 +14,9 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { S as KeyForObject, T as NestedKeyString, ai as RequireExactly, u as DotNotationKey, x as KeyForArray } from "./object-DyVg8BFt.mjs";
17
+ import { S as KeyForObject, T as NestedKeyString, ai as RequireExactly, at as NormalPrimitive, u as DotNotationKey, x as KeyForArray } from "./object-DyVg8BFt.mjs";
18
18
  import { F as QueryString } from "./string-GQsmDdYa.mjs";
19
+ import { f as TypeOrArray } from "./array-CbAKXvhH.mjs";
19
20
 
20
21
  //#region src/types/form.d.ts
21
22
  /** - Configuration options to control FormData generation behavior. */
@@ -111,6 +112,6 @@ interface FileError extends Error {
111
112
  /** THe return type of `serializeForm` wither as object or query string. */
112
113
  type SerializedForm<T extends boolean> = T extends false ? Record<string, string | string[]> : QueryString;
113
114
  /** * Represents the parsed form data. */
114
- type ParsedFormData<T> = T extends string ? Record<string, string | string[]> : Record<string, string | string[] | File | File[]>;
115
+ type ParsedFormData<T extends FormData | string, P extends boolean> = T extends string ? Record<string, P extends true ? TypeOrArray<NormalPrimitive> : TypeOrArray<string>> : Record<string, P extends true ? TypeOrArray<NormalPrimitive | File> : TypeOrArray<string | File>>;
115
116
  //#endregion
116
117
  export { OriginFileObj as a, FormDataConfigs as i, FileError as n, ParsedFormData as o, FileUpload as r, SerializedForm as s, CustomFile as t };
package/dist/guards.d.cts CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  import { $ as GenericFn, B as AsyncFunction, Dn as UTCOffset, Ft as DateLike, Z as FalsyPrimitive, _n as TimeWithUnit, at as NormalPrimitive, ct as Numeric, dt as Primitive, jt as ClockTime, nt as Maybe, pt as ValidArray, rt as MethodDescriptor, wt as $TimeZoneIdentifier, xn as TimeZoneIdNative, y as GenericObject } from "./object-DyVg8BFt.cjs";
18
18
  import { b as RGB, g as HSLA, h as HSL, s as CSSColor, v as Hex6, x as RGBA, y as Hex8 } from "./Color-asKZqwDF.cjs";
19
- import { S as isInvalidOrEmptyArray, f as isDeepEqual, v as isPrime } from "./index-BgomIbws.cjs";
19
+ import { S as isInvalidOrEmptyArray, f as isDeepEqual, v as isPrime } from "./index-D00Uqm9S.cjs";
20
20
  import { C as isURL, S as isPhoneNumber, _ as isEnvironment, a as isUUIDv4, b as isNode, c as isUUIDv7, d as isBase64, f as isBinaryString, g as isEmailArray, h as isEmail, i as isUUIDv3, l as isUUIDv8, m as isDateString, n as isUUIDv1, o as isUUIDv5, p as isBrowser, r as isUUIDv2, s as isUUIDv6, v as isHexString, w as isUUID, x as isNumericString, y as isIPAddress } from "./uuid-CMNRM9NO.cjs";
21
21
 
22
22
  //#region src/colors/guards.d.ts
package/dist/guards.d.mts CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  import { $ as GenericFn, B as AsyncFunction, Dn as UTCOffset, Ft as DateLike, Z as FalsyPrimitive, _n as TimeWithUnit, at as NormalPrimitive, ct as Numeric, dt as Primitive, jt as ClockTime, nt as Maybe, pt as ValidArray, rt as MethodDescriptor, wt as $TimeZoneIdentifier, xn as TimeZoneIdNative, y as GenericObject } from "./object-DyVg8BFt.mjs";
18
18
  import { b as RGB, g as HSLA, h as HSL, s as CSSColor, v as Hex6, x as RGBA, y as Hex8 } from "./Color-B2SgCGbm.mjs";
19
- import { S as isInvalidOrEmptyArray, f as isDeepEqual, v as isPrime } from "./index-C9x0f9jU.mjs";
19
+ import { S as isInvalidOrEmptyArray, f as isDeepEqual, v as isPrime } from "./index-BbBnKdBb.mjs";
20
20
  import { C as isURL, S as isPhoneNumber, _ as isEnvironment, a as isUUIDv4, b as isNode, c as isUUIDv7, d as isBase64, f as isBinaryString, g as isEmailArray, h as isEmail, i as isUUIDv3, l as isUUIDv8, m as isDateString, n as isUUIDv1, o as isUUIDv5, p as isBrowser, r as isUUIDv2, s as isUUIDv6, v as isHexString, w as isUUID, x as isNumericString, y as isIPAddress } from "./uuid-DvQsIl9p.mjs";
21
21
 
22
22
  //#region src/colors/guards.d.ts
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  import { G as ConditionFns, K as Constructor, U as ClassDetails, Xr as ProtoMethodOptions, br as ArrayOfObjectsToStringOptions, dt as Primitive, mt as VoidFn, nt as Maybe, q as DelayedFn, xr as ArrayOfPrimitivesToStringOptions, y as GenericObject } from "./object-DyVg8BFt.mjs";
18
- import { a as Flattened } from "./array-D8VGEDBI.mjs";
18
+ import { a as Flattened } from "./array-CbAKXvhH.mjs";
19
19
 
20
20
  //#region src/array/basics.d.ts
21
21
  /**
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  import { G as ConditionFns, K as Constructor, U as ClassDetails, Xr as ProtoMethodOptions, br as ArrayOfObjectsToStringOptions, dt as Primitive, mt as VoidFn, nt as Maybe, q as DelayedFn, xr as ArrayOfPrimitivesToStringOptions, y as GenericObject } from "./object-DyVg8BFt.cjs";
18
- import { a as Flattened } from "./array-ChT6TxQ7.cjs";
18
+ import { a as Flattened } from "./array-EVkwcL_k.cjs";
19
19
 
20
20
  //#region src/array/basics.d.ts
21
21
  /**