nhb-toolbox 3.0.0 → 3.1.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/dist/dom/query.d.ts +28 -0
- package/dist/dom/query.d.ts.map +1 -0
- package/dist/dom/query.js +50 -0
- package/dist/dom/storage.d.ts +41 -0
- package/dist/dom/storage.d.ts.map +1 -0
- package/dist/dom/storage.js +60 -0
- package/dist/dom/utils.d.ts +14 -0
- package/dist/dom/utils.d.ts.map +1 -0
- package/dist/dom/utils.js +34 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/object/basics.d.ts +1 -16
- package/dist/object/basics.d.ts.map +1 -1
- package/dist/object/basics.js +0 -33
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { QueryObject } from '../object/types';
|
|
2
|
+
/**
|
|
3
|
+
* * Utility to generate query parameters from an object.
|
|
4
|
+
*
|
|
5
|
+
* @template T - A generic type extending `QueryObject`.
|
|
6
|
+
* @param params - Object containing query parameters.
|
|
7
|
+
* @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
|
|
11
|
+
* generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
|
|
12
|
+
* generateQueryParams({ key1: '', key2: null }); // ""
|
|
13
|
+
* generateQueryParams({ key1: true, key2: false }); // "?key1=true&key2=false"
|
|
14
|
+
* generateQueryParams({ filters: { category: 'laptop', price: 1000 } }); // "?category=laptop&price=1000"
|
|
15
|
+
*/
|
|
16
|
+
export declare const generateQueryParams: <T extends QueryObject>(params?: T) => `?${string}` | "";
|
|
17
|
+
/**
|
|
18
|
+
* * Get query params as standard `JavaScript` Object `Record<string, string>`.
|
|
19
|
+
* @returns Query string as key-value paired object. `Record<string, string>`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getQueryParams(): Record<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* * Update query params in the browser URL with given key and value.
|
|
24
|
+
* @param key Key for the query to update.
|
|
25
|
+
* @param value Value to updated against the given key.
|
|
26
|
+
*/
|
|
27
|
+
export declare function updateQueryParam(key: string, value: string): void;
|
|
28
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/dom/query.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,WAAW,WAChD,CAAC,KACP,IAAI,MAAM,EAAE,GAAG,EAkCjB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAI1D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { flattenObjectKeyValue } from '../object/objectify';
|
|
2
|
+
/**
|
|
3
|
+
* * Utility to generate query parameters from an object.
|
|
4
|
+
*
|
|
5
|
+
* @template T - A generic type extending `QueryObject`.
|
|
6
|
+
* @param params - Object containing query parameters.
|
|
7
|
+
* @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
|
|
11
|
+
* generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
|
|
12
|
+
* generateQueryParams({ key1: '', key2: null }); // ""
|
|
13
|
+
* generateQueryParams({ key1: true, key2: false }); // "?key1=true&key2=false"
|
|
14
|
+
* generateQueryParams({ filters: { category: 'laptop', price: 1000 } }); // "?category=laptop&price=1000"
|
|
15
|
+
*/
|
|
16
|
+
export const generateQueryParams = (params = {}) => {
|
|
17
|
+
// Flatten the nested object into key-value pairs
|
|
18
|
+
const flattenedParams = flattenObjectKeyValue(params);
|
|
19
|
+
// Generate the query string
|
|
20
|
+
const queryParams = Object.entries(flattenedParams)
|
|
21
|
+
.filter(([_, value]) => value !== undefined &&
|
|
22
|
+
value !== null &&
|
|
23
|
+
!(typeof value === 'string' && value.trim() === ''))
|
|
24
|
+
.flatMap(([key, value]) => Array.isArray(value) ?
|
|
25
|
+
value
|
|
26
|
+
.filter((v) => v !== undefined &&
|
|
27
|
+
v !== null &&
|
|
28
|
+
!(typeof v === 'string' && v.trim() === ''))
|
|
29
|
+
.map((v) => `${encodeURIComponent(key)}=${encodeURIComponent(typeof v === 'boolean' ? String(v) : String(v))}`)
|
|
30
|
+
: `${encodeURIComponent(key)}=${encodeURIComponent(typeof value === 'boolean' ? String(value) : String(value))}`)
|
|
31
|
+
.join('&');
|
|
32
|
+
return queryParams ? `?${queryParams}` : '';
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* * Get query params as standard `JavaScript` Object `Record<string, string>`.
|
|
36
|
+
* @returns Query string as key-value paired object. `Record<string, string>`.
|
|
37
|
+
*/
|
|
38
|
+
export function getQueryParams() {
|
|
39
|
+
return Object.fromEntries(new URLSearchParams(window.location.search));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* * Update query params in the browser URL with given key and value.
|
|
43
|
+
* @param key Key for the query to update.
|
|
44
|
+
* @param value Value to updated against the given key.
|
|
45
|
+
*/
|
|
46
|
+
export function updateQueryParam(key, value) {
|
|
47
|
+
const url = new URL(window.location.href);
|
|
48
|
+
url.searchParams.set(key, value);
|
|
49
|
+
window.history.replaceState({}, '', url.toString());
|
|
50
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * Get item(s) from local storage.
|
|
3
|
+
*
|
|
4
|
+
* @param key - Key to get item(s) from local storage.
|
|
5
|
+
* @returns Returns saved item(s) from local storage if it exists with that key.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getFromLocalStorage: <T>(key: string) => T | null;
|
|
8
|
+
/**
|
|
9
|
+
* * Save item(s) in local storage.
|
|
10
|
+
*
|
|
11
|
+
* @param key - Key to save an item(s).
|
|
12
|
+
* @param value - The item(s)/value to save.
|
|
13
|
+
*/
|
|
14
|
+
export declare const saveToLocalStorage: <T>(key: string, value: T) => void;
|
|
15
|
+
/**
|
|
16
|
+
* * Remove item(s) from local storage.
|
|
17
|
+
*
|
|
18
|
+
* @param key - Key to delete item(s) from local storage.
|
|
19
|
+
*/
|
|
20
|
+
export declare const removeFromLocalStorage: (key: string) => void;
|
|
21
|
+
/**
|
|
22
|
+
* * Get item(s) from session storage.
|
|
23
|
+
*
|
|
24
|
+
* @param key - Key to get item(s) from session storage.
|
|
25
|
+
* @returns Returns saved item(s) from session storage if it exists with that key.
|
|
26
|
+
*/
|
|
27
|
+
export declare const getFromSessionStorage: <T>(key: string) => T | null;
|
|
28
|
+
/**
|
|
29
|
+
* * Save item(s) in session storage.
|
|
30
|
+
*
|
|
31
|
+
* @param key - Key to save an item(s).
|
|
32
|
+
* @param value - The item(s)/value to save.
|
|
33
|
+
*/
|
|
34
|
+
export declare const saveToSessionStorage: <T>(key: string, value: T) => void;
|
|
35
|
+
/**
|
|
36
|
+
* * Remove item(s) from session storage.
|
|
37
|
+
*
|
|
38
|
+
* @param key - Key to delete item(s) from session storage.
|
|
39
|
+
*/
|
|
40
|
+
export declare const removeFromSessionStorage: (key: string) => void;
|
|
41
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/dom/storage.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,OAAO,MAAM,KAAG,CAAC,GAAG,IAMxD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,OAAO,MAAM,SAAS,CAAC,KAAG,IAE7D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAAS,MAAM,KAAG,IAEpD,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,OAAO,MAAM,KAAG,CAAC,GAAG,IAM1D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,OAAO,MAAM,SAAS,CAAC,KAAG,IAE/D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,QAAS,MAAM,KAAG,IAEtD,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// * ****************** Local Storage ****************** * //
|
|
2
|
+
/**
|
|
3
|
+
* * Get item(s) from local storage.
|
|
4
|
+
*
|
|
5
|
+
* @param key - Key to get item(s) from local storage.
|
|
6
|
+
* @returns Returns saved item(s) from local storage if it exists with that key.
|
|
7
|
+
*/
|
|
8
|
+
export const getFromLocalStorage = (key) => {
|
|
9
|
+
const item = localStorage.getItem(key);
|
|
10
|
+
if (!item)
|
|
11
|
+
return null;
|
|
12
|
+
return JSON.parse(item);
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* * Save item(s) in local storage.
|
|
16
|
+
*
|
|
17
|
+
* @param key - Key to save an item(s).
|
|
18
|
+
* @param value - The item(s)/value to save.
|
|
19
|
+
*/
|
|
20
|
+
export const saveToLocalStorage = (key, value) => {
|
|
21
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* * Remove item(s) from local storage.
|
|
25
|
+
*
|
|
26
|
+
* @param key - Key to delete item(s) from local storage.
|
|
27
|
+
*/
|
|
28
|
+
export const removeFromLocalStorage = (key) => {
|
|
29
|
+
localStorage.removeItem(key);
|
|
30
|
+
};
|
|
31
|
+
// * ****************** Session Storage ****************** * //
|
|
32
|
+
/**
|
|
33
|
+
* * Get item(s) from session storage.
|
|
34
|
+
*
|
|
35
|
+
* @param key - Key to get item(s) from session storage.
|
|
36
|
+
* @returns Returns saved item(s) from session storage if it exists with that key.
|
|
37
|
+
*/
|
|
38
|
+
export const getFromSessionStorage = (key) => {
|
|
39
|
+
const item = sessionStorage.getItem(key);
|
|
40
|
+
if (!item)
|
|
41
|
+
return null;
|
|
42
|
+
return JSON.parse(item);
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* * Save item(s) in session storage.
|
|
46
|
+
*
|
|
47
|
+
* @param key - Key to save an item(s).
|
|
48
|
+
* @param value - The item(s)/value to save.
|
|
49
|
+
*/
|
|
50
|
+
export const saveToSessionStorage = (key, value) => {
|
|
51
|
+
sessionStorage.setItem(key, JSON.stringify(value));
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* * Remove item(s) from session storage.
|
|
55
|
+
*
|
|
56
|
+
* @param key - Key to delete item(s) from session storage.
|
|
57
|
+
*/
|
|
58
|
+
export const removeFromSessionStorage = (key) => {
|
|
59
|
+
sessionStorage.removeItem(key);
|
|
60
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * Scrolls smoothly to the given element with an optional vertical offset.
|
|
3
|
+
* @param element The target element to scroll to.
|
|
4
|
+
* @param offset Additional vertical offset in pixels (positive moves down, negative moves up).
|
|
5
|
+
*/
|
|
6
|
+
export declare function smoothScrollTo(element: HTMLElement, offset?: number): void;
|
|
7
|
+
/** * Toggle full-screen using browser API. */
|
|
8
|
+
export declare function toggleFullScreen(): void;
|
|
9
|
+
/**
|
|
10
|
+
* * Copy text to clipboard.
|
|
11
|
+
* @param text Text to copy in clipboard.
|
|
12
|
+
*/
|
|
13
|
+
export declare function copyToClipboard(text: string): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/dom/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAI,QAQ9D;AAED,8CAA8C;AAC9C,wBAAgB,gBAAgB,SAM/B;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,iBAMjD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * Scrolls smoothly to the given element with an optional vertical offset.
|
|
3
|
+
* @param element The target element to scroll to.
|
|
4
|
+
* @param offset Additional vertical offset in pixels (positive moves down, negative moves up).
|
|
5
|
+
*/
|
|
6
|
+
export function smoothScrollTo(element, offset = 0) {
|
|
7
|
+
element.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
8
|
+
if (offset !== 0) {
|
|
9
|
+
setTimeout(() => {
|
|
10
|
+
window.scrollBy({ top: offset, behavior: 'smooth' });
|
|
11
|
+
}, 300); // Delay to ensure smooth scrolling effect
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** * Toggle full-screen using browser API. */
|
|
15
|
+
export function toggleFullScreen() {
|
|
16
|
+
if (!document.fullscreenElement) {
|
|
17
|
+
document.documentElement.requestFullscreen();
|
|
18
|
+
}
|
|
19
|
+
else if (document.exitFullscreen) {
|
|
20
|
+
document.exitFullscreen();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* * Copy text to clipboard.
|
|
25
|
+
* @param text Text to copy in clipboard.
|
|
26
|
+
*/
|
|
27
|
+
export async function copyToClipboard(text) {
|
|
28
|
+
try {
|
|
29
|
+
await navigator.clipboard.writeText(text);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
console.error('Failed to copy:', err);
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -14,12 +14,15 @@ export { Color, Color as Colour } from './colors/Color';
|
|
|
14
14
|
export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
|
|
15
15
|
export { sortAnArray } from './array/sort';
|
|
16
16
|
export { createOptionsArray, removeDuplicatesFromArray, } from './array/transform';
|
|
17
|
-
export { createControlledFormData as convertIntoFormData, createControlledFormData, } from './form/convert';
|
|
18
|
-
export { isCustomFile, isCustomFileArray,
|
|
19
|
-
export { cloneObject, countObjectFields
|
|
17
|
+
export { createControlledFormData as convertIntoFormData, createControlledFormData, createControlledFormData as createFormData, } from './form/convert';
|
|
18
|
+
export { isCustomFile, isCustomFileArray, isFileArray, isFileList, isFileUpload, isOriginFileObj, isValidFormData, } from './form/guards';
|
|
19
|
+
export { cloneObject, countObjectFields } from './object/basics';
|
|
20
20
|
export { extractNewFields, extractUpdatedAndNewFields, extractUpdatedFields, flattenObjectDotNotation, flattenObjectKeyValue, mergeAndFlattenObjects, mergeObjects, } from './object/objectify';
|
|
21
21
|
export { sanitizeData } from './object/sanitize';
|
|
22
22
|
export { convertObjectValues } from './object/convert';
|
|
23
|
+
export { generateQueryParams, getQueryParams, updateQueryParam, } from './dom/query';
|
|
24
|
+
export { copyToClipboard, smoothScrollTo, toggleFullScreen } from './dom/utils';
|
|
25
|
+
export { getFromLocalStorage, getFromSessionStorage, removeFromLocalStorage, removeFromSessionStorage, saveToLocalStorage, saveToSessionStorage, } from './dom/storage';
|
|
23
26
|
export { convertArrayToString, debounceAction, isDeepEqual, throttleAction, } from './utils';
|
|
24
27
|
export { isBoolean, isFalsy, isInteger, isNonEmptyString, isNull, isNumber, isPositiveInteger, isPrimitive, isString, isSymbol, isTruthy, isUndefined, } from './guards/primitives';
|
|
25
28
|
export { isReturningPromise as doesReturnPromise, isArray, isArrayOfType, isValidArray as isArrayWithLength, isBigInt, isDate, isEmptyObject, isEmptyObject as isEmptyObjectGuard, isError, isFunction, isJSON, isJSON as isJSONObject, isMap, isNotEmptyObject, isObject, isEmptyObject as isObjectEmpty, isObjectWithKeys, isPromise, isRegExp, isRegExp as isRegularExpression, isReturningPromise, isSet, isValidArray, isJSON as isValidJSON, isMap as isValidMap, isNotEmptyObject as isValidObject, isSet as isValidSet, } from './guards/non-primitives';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EACN,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,aAAa,GACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,sBAAsB,IAAI,mBAAmB,GAC7C,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACN,YAAY,IAAI,YAAY,EAC5B,YAAY,EACZ,YAAY,IAAI,YAAY,EAC5B,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,MAAM,IAAI,YAAY,EACtB,UAAU,EACV,KAAK,EACL,KAAK,IAAI,WAAW,GACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,aAAa,IAAI,oBAAoB,EACrC,sBAAsB,EACtB,aAAa,GACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,gBAAgB,EAChB,OAAO,EACP,OAAO,IAAI,aAAa,GACxB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,WAAW,EACX,cAAc,IAAI,uBAAuB,EACzC,cAAc,EACd,cAAc,IAAI,gBAAgB,EAClC,cAAc,EACd,cAAc,IAAI,WAAW,EAC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AC;AAG7B,OAAO,EACN,kBAAkB,IAAI,iBAAiB,EACvC,OAAO,EACP,aAAa,EACb,YAAY,IAAI,iBAAiB,EACjC,QAAQ,EACR,MAAM,EACN,aAAa,EACb,aAAa,IAAI,kBAAkB,EACnC,OAAO,EACP,UAAU,EACV,MAAM,EACN,MAAM,IAAI,YAAY,EACtB,KAAK,EACL,gBAAgB,EAChB,QAAQ,EACR,aAAa,IAAI,aAAa,EAC9B,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,QAAQ,IAAI,mBAAmB,EAC/B,kBAAkB,EAClB,KAAK,EACL,YAAY,EACZ,MAAM,IAAI,WAAW,EACrB,KAAK,IAAI,UAAU,EACnB,gBAAgB,IAAI,aAAa,EACjC,KAAK,IAAI,UAAU,GACnB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACN,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,aAAa,EACb,aAAa,IAAI,iBAAiB,EAClC,WAAW,EACX,MAAM,EACN,aAAa,IAAI,SAAS,EAC1B,aAAa,IAAI,iBAAiB,EAClC,eAAe,EACf,aAAa,EACb,KAAK,EACL,MAAM,EACN,OAAO,IAAI,YAAY,EACvB,KAAK,IAAI,UAAU,GACnB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -19,13 +19,17 @@ export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmp
|
|
|
19
19
|
export { sortAnArray } from './array/sort';
|
|
20
20
|
export { createOptionsArray, removeDuplicatesFromArray, } from './array/transform';
|
|
21
21
|
// ! Form Utilities
|
|
22
|
-
export { createControlledFormData as convertIntoFormData, createControlledFormData, } from './form/convert';
|
|
23
|
-
export { isCustomFile, isCustomFileArray,
|
|
22
|
+
export { createControlledFormData as convertIntoFormData, createControlledFormData, createControlledFormData as createFormData, } from './form/convert';
|
|
23
|
+
export { isCustomFile, isCustomFileArray, isFileArray, isFileList, isFileUpload, isOriginFileObj, isValidFormData, } from './form/guards';
|
|
24
24
|
// ! Object Utilities
|
|
25
|
-
export { cloneObject, countObjectFields
|
|
25
|
+
export { cloneObject, countObjectFields } from './object/basics';
|
|
26
26
|
export { extractNewFields, extractUpdatedAndNewFields, extractUpdatedFields, flattenObjectDotNotation, flattenObjectKeyValue, mergeAndFlattenObjects, mergeObjects, } from './object/objectify';
|
|
27
27
|
export { sanitizeData } from './object/sanitize';
|
|
28
28
|
export { convertObjectValues } from './object/convert';
|
|
29
|
+
// ! DOM Utilities
|
|
30
|
+
export { generateQueryParams, getQueryParams, updateQueryParam, } from './dom/query';
|
|
31
|
+
export { copyToClipboard, smoothScrollTo, toggleFullScreen } from './dom/utils';
|
|
32
|
+
export { getFromLocalStorage, getFromSessionStorage, removeFromLocalStorage, removeFromSessionStorage, saveToLocalStorage, saveToSessionStorage, } from './dom/storage';
|
|
29
33
|
// ! Other Utilities
|
|
30
34
|
export { convertArrayToString, debounceAction, isDeepEqual, throttleAction, } from './utils';
|
|
31
35
|
// ! Primitive Type Guards
|
package/dist/object/basics.d.ts
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
import type { GenericObject
|
|
2
|
-
/**
|
|
3
|
-
* * Utility to generate query parameters from an object.
|
|
4
|
-
*
|
|
5
|
-
* @template T - A generic type extending `QueryObject`.
|
|
6
|
-
* @param params - Object containing query parameters.
|
|
7
|
-
* @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
|
|
11
|
-
* generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
|
|
12
|
-
* generateQueryParams({ key1: '', key2: null }); // ""
|
|
13
|
-
* generateQueryParams({ key1: true, key2: false }); // "?key1=true&key2=false"
|
|
14
|
-
* generateQueryParams({ filters: { category: 'laptop', price: 1000 } }); // "?category=laptop&price=1000"
|
|
15
|
-
*/
|
|
16
|
-
export declare const generateQueryParams: <T extends QueryObject>(params?: T) => string;
|
|
1
|
+
import type { GenericObject } from './types';
|
|
17
2
|
/**
|
|
18
3
|
* * Deep clone an object.
|
|
19
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/object/basics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"basics.d.ts","sourceRoot":"","sources":["../../src/object/basics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,OAAO,CAAC,KAAG,CAE7D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,aAAa,OAAO,CAAC,KAAG,MAInE,CAAC"}
|
package/dist/object/basics.js
CHANGED
|
@@ -1,36 +1,3 @@
|
|
|
1
|
-
import { flattenObjectKeyValue } from './objectify';
|
|
2
|
-
/**
|
|
3
|
-
* * Utility to generate query parameters from an object.
|
|
4
|
-
*
|
|
5
|
-
* @template T - A generic type extending `QueryObject`.
|
|
6
|
-
* @param params - Object containing query parameters.
|
|
7
|
-
* @returns A query string as a URL-encoded string, e.g., `?key1=value1&key2=value2`.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* generateQueryParams({ key1: 'value1', key2: 42 }); // "?key1=value1&key2=42"
|
|
11
|
-
* generateQueryParams({ key1: ['value1', 'value2'], key2: 42 }); // "?key1=value1&key1=value2&key2=42"
|
|
12
|
-
* generateQueryParams({ key1: '', key2: null }); // ""
|
|
13
|
-
* generateQueryParams({ key1: true, key2: false }); // "?key1=true&key2=false"
|
|
14
|
-
* generateQueryParams({ filters: { category: 'laptop', price: 1000 } }); // "?category=laptop&price=1000"
|
|
15
|
-
*/
|
|
16
|
-
export const generateQueryParams = (params = {}) => {
|
|
17
|
-
// Flatten the nested object into key-value pairs
|
|
18
|
-
const flattenedParams = flattenObjectKeyValue(params);
|
|
19
|
-
// Generate the query string
|
|
20
|
-
const queryParams = Object.entries(flattenedParams)
|
|
21
|
-
.filter(([_, value]) => value !== undefined &&
|
|
22
|
-
value !== null &&
|
|
23
|
-
!(typeof value === 'string' && value.trim() === ''))
|
|
24
|
-
.flatMap(([key, value]) => Array.isArray(value) ?
|
|
25
|
-
value
|
|
26
|
-
.filter((v) => v !== undefined &&
|
|
27
|
-
v !== null &&
|
|
28
|
-
!(typeof v === 'string' && v.trim() === ''))
|
|
29
|
-
.map((v) => `${encodeURIComponent(key)}=${encodeURIComponent(typeof v === 'boolean' ? String(v) : String(v))}`)
|
|
30
|
-
: `${encodeURIComponent(key)}=${encodeURIComponent(typeof value === 'boolean' ? String(value) : String(value))}`)
|
|
31
|
-
.join('&');
|
|
32
|
-
return queryParams ? `?${queryParams}` : '';
|
|
33
|
-
};
|
|
34
1
|
/**
|
|
35
2
|
* * Deep clone an object.
|
|
36
3
|
*
|
package/package.json
CHANGED