@sohanemon/utils 4.0.32 → 4.0.33

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.
@@ -60,3 +60,41 @@ export declare const copyToClipboard: (value: string, onSuccess?: () => void) =>
60
60
  * @returns - Normal Case
61
61
  */
62
62
  export declare function convertToNormalCase(inputString: string): string;
63
+ /**
64
+ * Checks if the code is running in a server-side environment.
65
+ *
66
+ * @returns - True if the code is executed in SSR (Server-Side Rendering) context, false otherwise
67
+ */
68
+ export declare const isSSR: boolean;
69
+ /**
70
+ * Converts an SVG string to a Base64-encoded string.
71
+ *
72
+ * @param str - The SVG string to encode
73
+ * @returns - Base64-encoded string representation of the SVG
74
+ */
75
+ export declare const svgToBase64: (str: string) => string;
76
+ /**
77
+ * Pauses execution for the specified time.
78
+ *
79
+ * @param time - Time in milliseconds to sleep (default is 1000ms)
80
+ * @returns - A Promise that resolves after the specified time
81
+ */
82
+ export declare const sleep: (time?: number) => Promise<unknown>;
83
+ /**
84
+ * Creates a debounced function that delays invoking the provided function until
85
+ * after the specified wait time has elapsed since the last invocation.
86
+ *
87
+ * @param func - The function to debounce
88
+ * @param wait - The number of milliseconds to delay (default is 1000ms)
89
+ * @returns - A debounced version of the function
90
+ */
91
+ export declare function debounce<T extends (...args: any[]) => void>(func: T, wait?: number): (...args: Parameters<T>) => void;
92
+ /**
93
+ * Creates a throttled function that invokes the provided function at most once
94
+ * every specified wait time.
95
+ *
96
+ * @param func - The function to throttle
97
+ * @param wait - The number of milliseconds to wait (default is 1000ms)
98
+ * @returns - A throttled version of the function
99
+ */
100
+ export declare function throttle<T extends (...args: any[]) => void>(func: T, wait?: number): (...args: Parameters<T>) => void;
@@ -105,7 +105,62 @@ export const copyToClipboard = (value, onSuccess = () => { }) => {
105
105
  export function convertToNormalCase(inputString) {
106
106
  const splittedString = inputString.split('.').pop();
107
107
  const string = splittedString || inputString;
108
- const words = string.replace(/([a-z])([A-Z])/g, '$1 $2').split(/[-_|\s]+/);
108
+ const words = string.replace(/([a-z])([A-Z])/g, '$1 $2').split(/[-_|​\s]+/);
109
109
  const capitalizedWords = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1));
110
110
  return capitalizedWords.join(' ');
111
111
  }
112
+ /**
113
+ * Checks if the code is running in a server-side environment.
114
+ *
115
+ * @returns - True if the code is executed in SSR (Server-Side Rendering) context, false otherwise
116
+ */
117
+ export const isSSR = typeof window === 'undefined';
118
+ /**
119
+ * Converts an SVG string to a Base64-encoded string.
120
+ *
121
+ * @param str - The SVG string to encode
122
+ * @returns - Base64-encoded string representation of the SVG
123
+ */
124
+ export const svgToBase64 = (str) => isSSR ? Buffer.from(str).toString('base64') : window.btoa(str);
125
+ /**
126
+ * Pauses execution for the specified time.
127
+ *
128
+ * @param time - Time in milliseconds to sleep (default is 1000ms)
129
+ * @returns - A Promise that resolves after the specified time
130
+ */
131
+ export const sleep = (time = 1000) => new Promise((resolve) => setTimeout(resolve, time));
132
+ /**
133
+ * Creates a debounced function that delays invoking the provided function until
134
+ * after the specified wait time has elapsed since the last invocation.
135
+ *
136
+ * @param func - The function to debounce
137
+ * @param wait - The number of milliseconds to delay (default is 1000ms)
138
+ * @returns - A debounced version of the function
139
+ */
140
+ export function debounce(func, wait = 1000) {
141
+ let timeout;
142
+ return function (...args) {
143
+ clearTimeout(timeout);
144
+ timeout = setTimeout(() => func.apply(this, args), wait);
145
+ };
146
+ }
147
+ /**
148
+ * Creates a throttled function that invokes the provided function at most once
149
+ * every specified wait time.
150
+ *
151
+ * @param func - The function to throttle
152
+ * @param wait - The number of milliseconds to wait (default is 1000ms)
153
+ * @returns - A throttled version of the function
154
+ */
155
+ export function throttle(func, wait = 1000) {
156
+ let inThrottle = false;
157
+ return function (...args) {
158
+ if (!inThrottle) {
159
+ func.apply(this, args);
160
+ inThrottle = true;
161
+ setTimeout(() => {
162
+ inThrottle = false;
163
+ }, wait);
164
+ }
165
+ };
166
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sohanemon/utils",
3
- "version": "4.0.32",
3
+ "version": "4.0.33",
4
4
  "author": "Sohan Emon <sohanemon@outlook.com>",
5
5
  "description": "",
6
6
  "type": "module",
@@ -15,33 +15,19 @@
15
15
  },
16
16
  "typesVersions": {
17
17
  "*": {
18
- "core": [
19
- "dist/index.d.ts"
20
- ],
21
- "types": [
22
- "dist/types/index.d.ts"
23
- ],
24
- "hooks": [
25
- "dist/hooks/index.d.ts"
26
- ],
27
- "components": [
28
- "dist/components/index.d.ts"
29
- ]
18
+ "core": ["dist/index.d.ts"],
19
+ "types": ["dist/types/index.d.ts"],
20
+ "hooks": ["dist/hooks/index.d.ts"],
21
+ "components": ["dist/components/index.d.ts"]
30
22
  }
31
23
  },
32
- "files": [
33
- "dist",
34
- "README.md"
35
- ],
24
+ "files": ["dist", "README.md"],
36
25
  "scripts": {
37
26
  "build": "tsc",
38
27
  "build:watch": "tsc --watch",
39
28
  "export": "tsc && npm publish"
40
29
  },
41
- "keywords": [
42
- "utils",
43
- "cn"
44
- ],
30
+ "keywords": ["utils", "cn"],
45
31
  "license": "ISC",
46
32
  "devDependencies": {
47
33
  "@types/node": "^22.4.0",