nhb-toolbox 3.1.0 → 3.1.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../src/array/sort.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAC1B,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,EAClD,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAyE3C"}
1
+ {"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../src/array/sort.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAC1B,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,EAClD,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAsE3C"}
@@ -34,14 +34,13 @@ export function sortAnArray(array, options) {
34
34
  // Handle array of objects
35
35
  if (isArrayOfType(array, isObject) && options && 'sortByField' in options) {
36
36
  return [...array].sort((a, b) => {
37
- // const key = options.sortByField as keyof T;
38
- // const keyA = (a as T)[key];
39
- // const keyB = (b as T)[key];
40
- const getKeyValue = (obj, path) => path
41
- .split('.')
42
- .reduce((acc, key) => acc?.[key], obj);
43
- const keyA = getKeyValue(a, options?.sortByField);
44
- const keyB = getKeyValue(b, options?.sortByField);
37
+ const _getKeyValue = (obj, path) => {
38
+ return path
39
+ .split('.')
40
+ .reduce((acc, key) => acc?.[key], obj);
41
+ };
42
+ const keyA = _getKeyValue(a, options?.sortByField);
43
+ const keyB = _getKeyValue(b, options?.sortByField);
45
44
  if (keyA == null || keyB == null) {
46
45
  return keyA == null ? 1 : -1;
47
46
  }
@@ -7,7 +7,7 @@ import type { PrimitiveKey } from '../types';
7
7
  * */
8
8
  export type Flattened<T> = T extends (infer U)[] ? Flattened<U> : T;
9
9
  /**
10
- * - Configuration for `createOptionsArray`.
10
+ * * Configuration for `createOptionsArray`.
11
11
  * - Defines the mapping between keys in the input objects and the keys in the output options.
12
12
  *
13
13
  * @typeParam T - The type of the objects in the input array.
@@ -52,5 +52,6 @@ export interface SortByOption<T extends GenericObject> extends OrderOption {
52
52
  /** The field by which to sort the objects in the array. */
53
53
  sortByField: NestedPrimitiveKey<T>;
54
54
  }
55
+ /** * Options for sorting array. */
55
56
  export type SortOptions<T> = T extends GenericObject ? SortByOption<T> : OrderOption;
56
57
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/array/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C;;;;MAIM;AACN,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;IACvC;;;OAGG;IACH,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAE/B;;;OAGG;IACH,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAEhC;;;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;AAED,yEAAyE;AACzE,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,aAAa,CAAE,SAAQ,WAAW;IACzE,2DAA2D;IAC3D,WAAW,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;CACnC;AAED,mCAAmC;AACnC,MAAM,MAAM,WAAW,CAAC,CAAC,IACxB,CAAC,SAAS,aAAa,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC"}
@@ -4,11 +4,15 @@
4
4
  * @param offset Additional vertical offset in pixels (positive moves down, negative moves up).
5
5
  */
6
6
  export declare function smoothScrollTo(element: HTMLElement, offset?: number): void;
7
- /** * Toggle full-screen using browser API. */
8
- export declare function toggleFullScreen(): void;
9
7
  /**
10
- * * Copy text to clipboard.
11
- * @param text Text to copy in clipboard.
8
+ * * Toggles full-screen mode for a given element (or the `document` by default).
9
+ * @param element The element to toggle fullscreen mode for (default: document root).
10
+ */
11
+ export declare function toggleFullScreen(element?: HTMLElement): void;
12
+ /**
13
+ * * Copies text to the clipboard, falling back to legacy methods if needed.
14
+ * @param text - The text to copy.
15
+ * @returns A promise that resolves when the text is copied.
12
16
  */
13
17
  export declare function copyToClipboard(text: string): Promise<void>;
14
18
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +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"}
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;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,cAA2B,QAuBlE;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BjE"}
package/dist/dom/utils.js CHANGED
@@ -11,24 +11,56 @@ export function smoothScrollTo(element, offset = 0) {
11
11
  }, 300); // Delay to ensure smooth scrolling effect
12
12
  }
13
13
  }
14
- /** * Toggle full-screen using browser API. */
15
- export function toggleFullScreen() {
16
- if (!document.fullscreenElement) {
17
- document.documentElement.requestFullscreen();
14
+ /**
15
+ * * Toggles full-screen mode for a given element (or the `document` by default).
16
+ * @param element The element to toggle fullscreen mode for (default: document root).
17
+ */
18
+ export function toggleFullScreen(element = document.documentElement) {
19
+ const doc = document;
20
+ const elem = element;
21
+ if (!doc.fullscreenElement && !doc.webkitFullscreenElement) {
22
+ if (elem.requestFullscreen) {
23
+ elem.requestFullscreen();
24
+ }
25
+ else if (elem.webkitRequestFullscreen) {
26
+ elem.webkitRequestFullscreen();
27
+ }
18
28
  }
19
- else if (document.exitFullscreen) {
20
- document.exitFullscreen();
29
+ else {
30
+ if (doc.exitFullscreen) {
31
+ doc.exitFullscreen();
32
+ }
33
+ else if (doc.webkitExitFullscreen) {
34
+ doc.webkitExitFullscreen();
35
+ }
21
36
  }
22
37
  }
23
38
  /**
24
- * * Copy text to clipboard.
25
- * @param text Text to copy in clipboard.
39
+ * * Copies text to the clipboard, falling back to legacy methods if needed.
40
+ * @param text - The text to copy.
41
+ * @returns A promise that resolves when the text is copied.
26
42
  */
27
43
  export async function copyToClipboard(text) {
28
44
  try {
29
- await navigator.clipboard.writeText(text);
45
+ if (navigator?.clipboard?.writeText) {
46
+ await navigator.clipboard.writeText(text);
47
+ }
48
+ else {
49
+ const textArea = document.createElement('textarea');
50
+ textArea.value = text;
51
+ textArea.style.position = 'fixed';
52
+ textArea.style.opacity = '0';
53
+ document.body.appendChild(textArea);
54
+ textArea.select();
55
+ textArea.setSelectionRange(0, textArea.value.length);
56
+ const success = document.execCommand('copy');
57
+ document.body.removeChild(textArea);
58
+ if (!success) {
59
+ throw new Error('Cannot execute command in this environment!');
60
+ }
61
+ }
30
62
  }
31
- catch (err) {
32
- console.error('Failed to copy:', err);
63
+ catch (error) {
64
+ console.error('Failed to copy text:', error);
33
65
  }
34
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions for everyday development needs.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",