@bikiran/utils 2.3.3 → 2.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -29,13 +29,13 @@ export { getBikiranUrl, getAccountUrl, getApiUrl, getApi2Url, getApi3Url, getBas
29
29
  export type { TInputChangeEvent, TTextAreaChangeEvent, TMouseEvent, TFormEvent, TKeyboardEvent, TFocusEvent, TDragEvent, TState, } from "./lib/types/GlobalType";
30
30
  export type { TDomainProperty, TDomainDuration, TDomainInfo, } from "./lib/types/domain";
31
31
  export type { TApp } from "./lib/types/app";
32
- export type { TInputChangeEvent as TInputChangeEventAlt, TTextAreaChangeEvent as TTextAreaChangeEventAlt, TMouseEvent as TMouseEventAlt, TFormEvent as TFormEventAlt, TKeyboardEvent as TKeyboardEventAlt, TFocusEvent as TFocusEventAlt, TDragEvent as TDragEventAlt, TState as TStateAlt, } from "./lib/types/event";
33
32
  export type { TUser } from "./lib/types/user";
34
33
  export type { TApiResponse, TPagination } from "./lib/types/response";
35
- export type { TInvoiceInfo, TAddressBilling, TAddressShipping, } from "./lib/types/invoice";
34
+ export type { TInvoiceInfo, TAddressBilling, TAddressPayload, TAddressShipping, TInvoiceData, TInvoiceProduct, TPaymentIssue, TPaymentOption, } from "./lib/types/invoice";
36
35
  export { default as countries } from "./lib/utils/country.json";
37
36
  export { win, doc, storage } from "./lib/utils/dom";
38
37
  export { setLocalStorage, getLocalStorage } from "./lib/utils/storage";
39
38
  export { mkQueryString, mkToken, mkStrongPassword, } from "./lib/utils/StringOperation";
40
39
  export { default as StatusColor } from "./lib/utils/statusColor";
41
40
  export { useOutsideClick } from "./lib/utils/OutsideClick";
41
+ export { showSize } from "./lib/utils/showSize";
package/dist/index.js CHANGED
@@ -34,3 +34,4 @@ export { mkQueryString, mkToken, mkStrongPassword, } from "./lib/utils/StringOpe
34
34
  export { default as StatusColor } from "./lib/utils/statusColor";
35
35
  // React hooks
36
36
  export { useOutsideClick } from "./lib/utils/OutsideClick";
37
+ export { showSize } from "./lib/utils/showSize";
package/dist/index.ts CHANGED
@@ -71,19 +71,6 @@ export type {
71
71
 
72
72
  // App types
73
73
  export type { TApp } from "./lib/types/app";
74
-
75
- // Event types (alternative to GlobalType)
76
- export type {
77
- TInputChangeEvent as TInputChangeEventAlt,
78
- TTextAreaChangeEvent as TTextAreaChangeEventAlt,
79
- TMouseEvent as TMouseEventAlt,
80
- TFormEvent as TFormEventAlt,
81
- TKeyboardEvent as TKeyboardEventAlt,
82
- TFocusEvent as TFocusEventAlt,
83
- TDragEvent as TDragEventAlt,
84
- TState as TStateAlt,
85
- } from "./lib/types/event";
86
-
87
74
  // User types
88
75
  export type { TUser } from "./lib/types/user";
89
76
 
@@ -94,7 +81,12 @@ export type { TApiResponse, TPagination } from "./lib/types/response";
94
81
  export type {
95
82
  TInvoiceInfo,
96
83
  TAddressBilling,
84
+ TAddressPayload,
97
85
  TAddressShipping,
86
+ TInvoiceData,
87
+ TInvoiceProduct,
88
+ TPaymentIssue,
89
+ TPaymentOption,
98
90
  } from "./lib/types/invoice";
99
91
  export { default as countries } from "./lib/utils/country.json";
100
92
  export { win, doc, storage } from "./lib/utils/dom";
@@ -110,3 +102,4 @@ export { default as StatusColor } from "./lib/utils/statusColor";
110
102
 
111
103
  // React hooks
112
104
  export { useOutsideClick } from "./lib/utils/OutsideClick";
105
+ export { showSize } from "./lib/utils/showSize";
@@ -1,2 +1 @@
1
- import React from "react";
2
- export declare function useOutsideClick(ref: React.RefObject<HTMLElement>, callback: () => void): void;
1
+ export declare function useOutsideClick(ref: React.RefObject<HTMLElement>, callback: () => void, ignoreClassNames?: string[]): void;
@@ -1,8 +1,29 @@
1
1
  import { useEffect } from "react";
2
- export function useOutsideClick(ref, callback) {
2
+ export function useOutsideClick(ref, callback, ignoreClassNames) {
3
3
  useEffect(() => {
4
4
  function handleClickOutside(event) {
5
- if (ref.current && !ref.current.contains(event.target)) {
5
+ const target = event.target;
6
+ // Check if the click is outside the referenced element
7
+ if (ref.current && !ref.current.contains(target)) {
8
+ // If ignoreClassNames is provided, check if the clicked element has any of those classes
9
+ if (ignoreClassNames && ignoreClassNames.length > 0) {
10
+ const hasIgnoredClass = ignoreClassNames.some((className) => {
11
+ var _a;
12
+ // Check if the clicked element or any of its parents has the ignored class
13
+ let element = target;
14
+ while (element) {
15
+ if ((_a = element.classList) === null || _a === void 0 ? void 0 : _a.contains(className)) {
16
+ return true;
17
+ }
18
+ element = element.parentElement;
19
+ }
20
+ return false;
21
+ });
22
+ // Don't trigger callback if clicked element has an ignored class
23
+ if (hasIgnoredClass) {
24
+ return;
25
+ }
26
+ }
6
27
  callback();
7
28
  }
8
29
  }
@@ -10,5 +31,5 @@ export function useOutsideClick(ref, callback) {
10
31
  return () => {
11
32
  document.removeEventListener("mousedown", handleClickOutside);
12
33
  };
13
- }, [ref, callback]);
34
+ }, [ref, callback, ignoreClassNames]);
14
35
  }
@@ -1,12 +1,36 @@
1
- import React, { useEffect } from "react";
1
+ import { useEffect } from "react";
2
2
 
3
3
  export function useOutsideClick(
4
4
  ref: React.RefObject<HTMLElement>,
5
- callback: () => void
5
+ callback: () => void,
6
+ ignoreClassNames?: string[]
6
7
  ) {
7
8
  useEffect(() => {
8
9
  function handleClickOutside(event: MouseEvent) {
9
- if (ref.current && !ref.current.contains(event.target as Node)) {
10
+ const target = event.target as HTMLElement;
11
+
12
+ // Check if the click is outside the referenced element
13
+ if (ref.current && !ref.current.contains(target)) {
14
+ // If ignoreClassNames is provided, check if the clicked element has any of those classes
15
+ if (ignoreClassNames && ignoreClassNames.length > 0) {
16
+ const hasIgnoredClass = ignoreClassNames.some((className) => {
17
+ // Check if the clicked element or any of its parents has the ignored class
18
+ let element: HTMLElement | null = target;
19
+ while (element) {
20
+ if (element.classList?.contains(className)) {
21
+ return true;
22
+ }
23
+ element = element.parentElement;
24
+ }
25
+ return false;
26
+ });
27
+
28
+ // Don't trigger callback if clicked element has an ignored class
29
+ if (hasIgnoredClass) {
30
+ return;
31
+ }
32
+ }
33
+
10
34
  callback();
11
35
  }
12
36
  }
@@ -15,5 +39,5 @@ export function useOutsideClick(
15
39
  return () => {
16
40
  document.removeEventListener("mousedown", handleClickOutside);
17
41
  };
18
- }, [ref, callback]);
42
+ }, [ref, callback, ignoreClassNames]);
19
43
  }
@@ -0,0 +1 @@
1
+ export declare function showSize(value: number, fromUnit?: string): string;
@@ -0,0 +1,18 @@
1
+ export function showSize(value, fromUnit = "bytes") {
2
+ const units = ["bytes", "KB", "MB", "GB", "TB"];
3
+ const normalizedUnit = fromUnit.toLowerCase();
4
+ // Convert units array to lowercase for comparison
5
+ const unitIndex = units.map((u) => u.toLowerCase()).indexOf(normalizedUnit);
6
+ if (unitIndex === -1) {
7
+ console.error(`Invalid unit: ${fromUnit}. Using 'bytes' as default.`);
8
+ return showSize(value, "bytes"); // Recursively call with default unit
9
+ }
10
+ // Convert the input value to bytes first
11
+ const bytes = value * Math.pow(1024, unitIndex);
12
+ // Then convert bytes to the most appropriate unit
13
+ if (bytes === 0)
14
+ return "0 bytes";
15
+ const k = 1024;
16
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
17
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + units[i];
18
+ }
@@ -0,0 +1,23 @@
1
+ export function showSize(value: number, fromUnit: string = "bytes"): string {
2
+ const units = ["bytes", "KB", "MB", "GB", "TB"];
3
+ const normalizedUnit = fromUnit.toLowerCase();
4
+
5
+ // Convert units array to lowercase for comparison
6
+ const unitIndex = units.map((u) => u.toLowerCase()).indexOf(normalizedUnit);
7
+
8
+ if (unitIndex === -1) {
9
+ console.error(`Invalid unit: ${fromUnit}. Using 'bytes' as default.`);
10
+ return showSize(value, "bytes"); // Recursively call with default unit
11
+ }
12
+
13
+ // Convert the input value to bytes first
14
+ const bytes = value * Math.pow(1024, unitIndex);
15
+
16
+ // Then convert bytes to the most appropriate unit
17
+ if (bytes === 0) return "0 bytes";
18
+
19
+ const k = 1024;
20
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
21
+
22
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + units[i];
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikiran/utils",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [