@herowcode/utils 1.0.1 → 1.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.
Files changed (94) hide show
  1. package/README.md +101 -81
  2. package/dist/date/{fixTimezoneOffset.d.ts → fix-timezone-offset.d.ts} +1 -1
  3. package/dist/date/fix-timezone-offset.d.ts.map +1 -0
  4. package/dist/date/fix-timezone-offset.js.map +1 -0
  5. package/dist/date/{formatDate.d.ts → format-date.d.ts} +1 -1
  6. package/dist/date/format-date.d.ts.map +1 -0
  7. package/dist/date/format-date.js.map +1 -0
  8. package/dist/date/{getCurrentDateInUTC.d.ts → get-current-date-in-utc.d.ts} +1 -1
  9. package/dist/date/get-current-date-in-utc.d.ts.map +1 -0
  10. package/dist/date/get-current-date-in-utc.js.map +1 -0
  11. package/dist/date/{getDateInUTC.d.ts → get-date-in-utc.d.ts} +1 -1
  12. package/dist/date/get-date-in-utc.d.ts.map +1 -0
  13. package/dist/date/get-date-in-utc.js.map +1 -0
  14. package/dist/date/index.d.ts +5 -5
  15. package/dist/date/index.d.ts.map +1 -1
  16. package/dist/date/index.esm.js +5 -5
  17. package/dist/date/index.js +5 -5
  18. package/dist/date/index.js.map +1 -1
  19. package/dist/date/{parseTimeSpent.d.ts → parse-time-spent.d.ts} +1 -1
  20. package/dist/date/parse-time-spent.d.ts.map +1 -0
  21. package/dist/date/{parseTimeSpent.esm.js → parse-time-spent.esm.js} +1 -1
  22. package/dist/date/{parseTimeSpent.js → parse-time-spent.js} +1 -1
  23. package/dist/date/parse-time-spent.js.map +1 -0
  24. package/dist/files/compress-image.d.ts +10 -0
  25. package/dist/files/compress-image.d.ts.map +1 -0
  26. package/dist/files/compress-image.esm.js +57 -0
  27. package/dist/files/compress-image.js +57 -0
  28. package/dist/files/compress-image.js.map +1 -0
  29. package/dist/files/download-url.d.ts +2 -0
  30. package/dist/files/download-url.d.ts.map +1 -0
  31. package/dist/files/download-url.esm.js +24 -0
  32. package/dist/files/download-url.js +24 -0
  33. package/dist/files/download-url.js.map +1 -0
  34. package/dist/files/format-bytes.d.ts +2 -0
  35. package/dist/files/format-bytes.d.ts.map +1 -0
  36. package/dist/files/format-bytes.esm.js +13 -0
  37. package/dist/files/format-bytes.js +13 -0
  38. package/dist/files/format-bytes.js.map +1 -0
  39. package/dist/files/index.d.ts +4 -0
  40. package/dist/files/index.d.ts.map +1 -0
  41. package/dist/files/index.esm.js +3 -0
  42. package/dist/files/index.js +3 -0
  43. package/dist/files/index.js.map +1 -0
  44. package/dist/{function.d.ts → function/debounce.d.ts} +1 -8
  45. package/dist/function/debounce.d.ts.map +1 -0
  46. package/dist/function/debounce.esm.js +22 -0
  47. package/dist/function/debounce.js +22 -0
  48. package/dist/function/debounce.js.map +1 -0
  49. package/dist/function/index.d.ts +4 -0
  50. package/dist/function/index.d.ts.map +1 -0
  51. package/dist/function/index.esm.js +3 -0
  52. package/dist/function/index.js +3 -0
  53. package/dist/function/index.js.map +1 -0
  54. package/dist/function/throttle.d.ts +10 -0
  55. package/dist/function/throttle.d.ts.map +1 -0
  56. package/dist/{function.esm.js → function/throttle.esm.js} +0 -22
  57. package/dist/{function.js → function/throttle.js} +0 -22
  58. package/dist/function/throttle.js.map +1 -0
  59. package/dist/function/try-catch.d.ts +32 -0
  60. package/dist/function/try-catch.d.ts.map +1 -0
  61. package/dist/function/try-catch.esm.js +35 -0
  62. package/dist/function/try-catch.js +35 -0
  63. package/dist/function/try-catch.js.map +1 -0
  64. package/dist/index.d.ts +2 -2
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.esm.js +5 -10
  67. package/dist/index.js +5 -10
  68. package/dist/index.js.map +1 -1
  69. package/package.json +10 -9
  70. package/dist/date/fixTimezoneOffset.d.ts.map +0 -1
  71. package/dist/date/fixTimezoneOffset.js.map +0 -1
  72. package/dist/date/formatDate.d.ts.map +0 -1
  73. package/dist/date/formatDate.js.map +0 -1
  74. package/dist/date/getCurrentDateInUTC.d.ts.map +0 -1
  75. package/dist/date/getCurrentDateInUTC.js.map +0 -1
  76. package/dist/date/getDateInUTC.d.ts.map +0 -1
  77. package/dist/date/getDateInUTC.js.map +0 -1
  78. package/dist/date/parseTimeSpent.d.ts.map +0 -1
  79. package/dist/date/parseTimeSpent.js.map +0 -1
  80. package/dist/function.d.ts.map +0 -1
  81. package/dist/function.js.map +0 -1
  82. package/dist/number.d.ts +0 -8
  83. package/dist/number.d.ts.map +0 -1
  84. package/dist/number.esm.js +0 -15
  85. package/dist/number.js +0 -15
  86. package/dist/number.js.map +0 -1
  87. /package/dist/date/{fixTimezoneOffset.esm.js → fix-timezone-offset.esm.js} +0 -0
  88. /package/dist/date/{fixTimezoneOffset.js → fix-timezone-offset.js} +0 -0
  89. /package/dist/date/{formatDate.esm.js → format-date.esm.js} +0 -0
  90. /package/dist/date/{formatDate.js → format-date.js} +0 -0
  91. /package/dist/date/{getCurrentDateInUTC.esm.js → get-current-date-in-utc.esm.js} +0 -0
  92. /package/dist/date/{getCurrentDateInUTC.js → get-current-date-in-utc.js} +0 -0
  93. /package/dist/date/{getDateInUTC.esm.js → get-date-in-utc.esm.js} +0 -0
  94. /package/dist/date/{getDateInUTC.js → get-date-in-utc.js} +0 -0
package/README.md CHANGED
@@ -51,133 +51,162 @@ const debouncedFn = debounce(() => console.log('Called!'), 300);
51
51
 
52
52
  ## API Reference
53
53
 
54
+ ### Array Utilities
55
+
56
+ #### `shuffle<T>(array: T[]): T[]`
57
+ Returns a new array with the elements shuffled in random order.
58
+
59
+ ```typescript
60
+ shuffle([1, 2, 3, 4]); // e.g., [3, 1, 4, 2]
61
+ ```
62
+
63
+ #### `unique<T>(array: T[]): T[]`
64
+ Removes duplicate values from an array, preserving the first occurrence.
65
+
66
+ ```typescript
67
+ unique([1, 2, 2, 3, 1]); // [1, 2, 3]
68
+ ```
69
+
54
70
  ### Date Utilities
55
71
 
56
- #### `formatDate(date: Date, format: string): string`
72
+ #### `formatDate(date: Date | string | number, locale?: string, opts?: Intl.DateTimeFormatOptions): string`
73
+ Formats a date using the specified locale and options.
74
+
75
+ ```typescript
76
+ formatDate(new Date('2023-12-25'), 'en-US'); // "December 25, 2023"
77
+ ```
78
+
79
+ #### `fixTimezoneOffset(utcDate: Date | string): Dayjs`
80
+ Adjusts a UTC date string or Date object for the local timezone offset.
57
81
 
58
- Formats a date according to the specified format.
82
+ ```typescript
83
+ fixTimezoneOffset('2025-09-08T12:00:00Z');
84
+ ```
59
85
 
60
- **Supported format tokens:**
61
- - `YYYY` - 4-digit year
62
- - `YY` - 2-digit year
63
- - `MM` - 2-digit month (01-12)
64
- - `DD` - 2-digit day (01-31)
65
- - `HH` - 2-digit hours (00-23)
66
- - `mm` - 2-digit minutes (00-59)
67
- - `ss` - 2-digit seconds (00-59)
86
+ #### `getCurrentDateInUTC(): Dayjs`
87
+ Returns the current date/time as a Dayjs object in UTC.
68
88
 
69
89
  ```typescript
70
- formatDate(new Date('2023-12-25'), 'YYYY-MM-DD'); // "2023-12-25"
71
- formatDate(new Date('2023-12-25'), 'DD/MM/YYYY'); // "25/12/2023"
72
- formatDate(new Date('2023-12-25T10:30:45'), 'DD/MM/YYYY HH:mm:ss'); // "25/12/2023 10:30:45"
90
+ getCurrentDateInUTC();
73
91
  ```
74
92
 
75
- #### `addDays(date: Date, amount: number): Date`
93
+ #### `getDateInUTC(date: Date): Dayjs`
94
+ Converts a Date to a Dayjs object in UTC.
76
95
 
77
- Adds a specified number of days to a date. Returns a new Date object.
96
+ ```typescript
97
+ getDateInUTC(new Date());
98
+ ```
99
+
100
+ #### `parseTimeSpent(initialDate: string | Date, finalDate: string | Date, locale?: string): string`
101
+ Returns a human-readable string describing the time difference between two dates, localized.
78
102
 
79
103
  ```typescript
80
- const date = new Date('2023-12-25');
81
- addDays(date, 5); // 2023-12-30
82
- addDays(date, -5); // 2023-12-20
104
+ parseTimeSpent('2020-01-01', '2022-04-16', 'en-US'); // "2 years, 3 months, and 15 days"
83
105
  ```
84
106
 
85
- #### `diffInDays(date1: Date, date2: Date): number`
107
+ ### Files Utilities
86
108
 
87
- Calculates the difference in days between two dates.
109
+ #### `compressImage({ file, maxWidth, maxHeight, quality, allowedFileTypes }): Promise<File>`
110
+ Compresses an image file to WebP format, optionally resizing and restricting file types.
88
111
 
89
112
  ```typescript
90
- const date1 = new Date('2023-12-30');
91
- const date2 = new Date('2023-12-25');
92
- diffInDays(date1, date2); // 5
93
- diffInDays(date2, date1); // -5
113
+ await compressImage({ file, maxWidth: 800, maxHeight: 600, quality: 0.8 });
94
114
  ```
95
115
 
96
- #### `isBefore(date1: Date, date2: Date): boolean`
116
+ #### `downloadUrl(url: string): Promise<boolean>`
117
+ Downloads a file from a URL in the browser, returning true if successful.
97
118
 
98
- Checks if the first date is before the second date.
119
+ ```typescript
120
+ await downloadUrl('https://example.com/file.pdf');
121
+ ```
122
+
123
+ #### `formatBytes(bytes: number): string`
124
+ Formats a byte count as a human-readable string (e.g., "1.23 MB").
99
125
 
100
126
  ```typescript
101
- const date1 = new Date('2023-12-20');
102
- const date2 = new Date('2023-12-25');
103
- isBefore(date1, date2); // true
104
- isBefore(date2, date1); // false
127
+ formatBytes(1234567); // "1.18 MB"
105
128
  ```
106
129
 
107
- #### `isAfter(date1: Date, date2: Date): boolean`
130
+ ### Function Utilities
108
131
 
109
- Checks if the first date is after the second date.
132
+ #### `debounce<T>(fn: T, delay: number): (...args: Parameters<T>) => void`
133
+ Creates a debounced function that delays invoking `fn` until after `delay` ms have elapsed since the last call.
110
134
 
111
135
  ```typescript
112
- const date1 = new Date('2023-12-30');
113
- const date2 = new Date('2023-12-25');
114
- isAfter(date1, date2); // true
115
- isAfter(date2, date1); // false
136
+ const debounced = debounce(() => { /* ... */ }, 300);
116
137
  ```
117
138
 
118
- ### String Utilities
139
+ #### `throttle<T>(fn: T, delay: number): (...args: Parameters<T>) => void`
140
+ Creates a throttled function that only invokes `fn` at most once per `delay` ms.
119
141
 
120
- #### `capitalize(str: string): string`
142
+ ```typescript
143
+ const throttled = throttle(() => { /* ... */ }, 100);
144
+ ```
121
145
 
122
- Capitalizes the first letter of a string and converts the rest to lowercase.
146
+ #### `tryCatch<T, E = Error, D = null>(fn: Promise<T> | (() => Promise<T> | T), defaultData?: D): Promise<{ data: T | D; error: E | null }>`
147
+ Executes a function or promise and returns an object with `data` or `error`.
123
148
 
124
149
  ```typescript
125
- capitalize('hello world'); // "Hello world"
126
- capitalize('HELLO WORLD'); // "Hello world"
127
- capitalize('hELLo WoRLd'); // "Hello world"
150
+ const result = await tryCatch(() => fetchData());
151
+ if (result.error) { /* handle error */ }
128
152
  ```
129
153
 
130
- #### `camelCase(str: string): string`
154
+ ### String Utilities
131
155
 
132
- Converts a string to camelCase by removing special characters and capitalizing words.
156
+ #### `camelCase(str: string): string`
157
+ Converts a string to camelCase.
133
158
 
134
159
  ```typescript
135
160
  camelCase('hello world'); // "helloWorld"
136
- camelCase('hello-world'); // "helloWorld"
137
- camelCase('hello_world_test'); // "helloWorldTest"
138
- camelCase('The Quick Brown Fox'); // "theQuickBrownFox"
139
161
  ```
140
162
 
141
- ### Number Utilities
163
+ #### `capitalize(str: string): string`
164
+ Capitalizes the first letter and lowercases the rest.
142
165
 
143
- #### `randomInt(min: number, max: number): number`
166
+ ```typescript
167
+ capitalize('hELLO'); // "Hello"
168
+ ```
144
169
 
145
- Generates a random integer between min and max (inclusive).
170
+ #### `kebabCase(str: string): string`
171
+ Converts a string to kebab-case.
146
172
 
147
173
  ```typescript
148
- randomInt(1, 10); // Random integer between 1 and 10
149
- randomInt(0, 100); // Random integer between 0 and 100
150
- randomInt(-5, 5); // Random integer between -5 and 5
174
+ kebabCase('Hello World'); // "hello-world"
151
175
  ```
152
176
 
153
- ### Function Utilities
177
+ #### `removeHtmlTags(input: string): string`
178
+ Removes all HTML tags from a string.
154
179
 
155
- #### `debounce<T>(fn: T, delay: number): T`
180
+ ```typescript
181
+ removeHtmlTags('<p>Hello</p>'); // "Hello"
182
+ ```
156
183
 
157
- Creates a debounced function that delays invoking `fn` until after `delay` milliseconds have elapsed since the last time it was invoked.
184
+ #### `slugify(text: string): string`
185
+ Converts a string to a URL-friendly slug.
158
186
 
159
187
  ```typescript
160
- const debouncedSearch = debounce((query: string) => {
161
- console.log('Searching for:', query);
162
- }, 300);
163
-
164
- // Will only execute once after 300ms of no new calls
165
- debouncedSearch('a');
166
- debouncedSearch('ab');
167
- debouncedSearch('abc'); // Only this will execute
188
+ slugify('Hello World!'); // "hello-world"
168
189
  ```
169
190
 
170
- #### `throttle<T>(fn: T, delay: number): T`
191
+ #### `snakeCase(str: string): string`
192
+ Converts a string to snake_case.
193
+
194
+ ```typescript
195
+ snakeCase('Hello World'); // "hello_world"
196
+ ```
171
197
 
172
- Creates a throttled function that only invokes `fn` at most once per every `delay` milliseconds.
198
+ #### `toSentenceCase(str: string): string`
199
+ Converts a string to sentence case.
173
200
 
174
201
  ```typescript
175
- const throttledScroll = throttle(() => {
176
- console.log('Scroll event handled');
177
- }, 100);
202
+ toSentenceCase('helloWorld'); // "Hello world"
203
+ ```
204
+
205
+ #### `truncate(str: string, length: number, suffix = "..."): string`
206
+ Truncates a string to a specified length, appending a suffix if truncated.
178
207
 
179
- // Will execute immediately, then at most once every 100ms
180
- window.addEventListener('scroll', throttledScroll);
208
+ ```typescript
209
+ truncate('Hello world', 5); // "He..."
181
210
  ```
182
211
 
183
212
  ## Browser Support
@@ -212,13 +241,4 @@ MIT © [HerowCode](https://github.com/herowcode)
212
241
 
213
242
  ## Contributing
214
243
 
215
- Contributions are welcome! Please feel free to submit a Pull Request.
216
-
217
- ## Changelog
218
-
219
- ### 1.0.0
220
- - Initial release
221
- - Date utilities: `formatDate`, `addDays`, `diffInDays`, `isBefore`, `isAfter`
222
- - String utilities: `capitalize`, `camelCase`
223
- - Number utilities: `randomInt`
224
- - Function utilities: `debounce`, `throttle`
244
+ Contributions are welcome! Please feel free to submit a Pull Request.
@@ -1,3 +1,3 @@
1
1
  import type { Dayjs } from "dayjs";
2
2
  export declare function fixTimezoneOffset(utcDate: Date | string): Dayjs;
3
- //# sourceMappingURL=fixTimezoneOffset.d.ts.map
3
+ //# sourceMappingURL=fix-timezone-offset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-timezone-offset.d.ts","sourceRoot":"","sources":["../../src/date/fix-timezone-offset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAIlC,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,IAAI,GAAG,MAAM,GAAG,KAAK,CAG/D"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-timezone-offset.js","sourceRoot":"","sources":["../../src/date/fix-timezone-offset.ts"],"names":[],"mappings":";;AAIA,8CAGC;AALD,mCAA+B;AAE/B,SAAgB,iBAAiB,CAAC,OAAsB;IACtD,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,iBAAiB,EAAE,CAAA;IACpD,OAAO,IAAA,aAAK,EAAC,OAAO,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;AAC7C,CAAC"}
@@ -1,2 +1,2 @@
1
1
  export declare function formatDate(date: Date | string | number, locale?: Intl.LocalesArgument, opts?: Intl.DateTimeFormatOptions): string;
2
- //# sourceMappingURL=formatDate.d.ts.map
2
+ //# sourceMappingURL=format-date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-date.d.ts","sourceRoot":"","sources":["../../src/date/format-date.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CACxB,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC5B,MAAM,GAAE,IAAI,CAAC,eAAyB,EACtC,IAAI,GAAE,IAAI,CAAC,qBAA0B,UAQtC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-date.js","sourceRoot":"","sources":["../../src/date/format-date.ts"],"names":[],"mappings":";;AAAA,gCAWC;AAXD,SAAgB,UAAU,CACxB,IAA4B,EAC5B,SAA+B,OAAO,EACtC,OAAmC,EAAE;;IAErC,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE;QACrC,KAAK,EAAE,MAAA,IAAI,CAAC,KAAK,mCAAI,MAAM;QAC3B,GAAG,EAAE,MAAA,IAAI,CAAC,GAAG,mCAAI,SAAS;QAC1B,IAAI,EAAE,MAAA,IAAI,CAAC,IAAI,mCAAI,SAAS;QAC5B,GAAG,IAAI;KACR,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;AAC3B,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import type { Dayjs } from "dayjs";
2
2
  export declare function getCurrentDateInUTC(): Dayjs;
3
- //# sourceMappingURL=getCurrentDateInUTC.d.ts.map
3
+ //# sourceMappingURL=get-current-date-in-utc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-current-date-in-utc.d.ts","sourceRoot":"","sources":["../../src/date/get-current-date-in-utc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAIlC,wBAAgB,mBAAmB,IAAI,KAAK,CAE3C"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-current-date-in-utc.js","sourceRoot":"","sources":["../../src/date/get-current-date-in-utc.ts"],"names":[],"mappings":";;AAIA,kDAEC;AAJD,mCAA+B;AAE/B,SAAgB,mBAAmB;IACjC,OAAO,IAAA,aAAK,GAAE,CAAC,GAAG,EAAE,CAAA;AACtB,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import type { Dayjs } from "dayjs";
2
2
  export declare function getDateInUTC(date: Date): Dayjs;
3
- //# sourceMappingURL=getDateInUTC.d.ts.map
3
+ //# sourceMappingURL=get-date-in-utc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-date-in-utc.d.ts","sourceRoot":"","sources":["../../src/date/get-date-in-utc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAIlC,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,KAAK,CAE9C"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-date-in-utc.js","sourceRoot":"","sources":["../../src/date/get-date-in-utc.ts"],"names":[],"mappings":";;AAIA,oCAEC;AAJD,mCAA+B;AAE/B,SAAgB,YAAY,CAAC,IAAU;IACrC,OAAO,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAA;AAC1B,CAAC"}
@@ -1,7 +1,7 @@
1
1
  export * from "./dayjs";
2
- export * from "./fixTimezoneOffset";
3
- export * from "./formatDate";
4
- export * from "./getCurrentDateInUTC";
5
- export * from "./getDateInUTC";
6
- export * from "./parseTimeSpent";
2
+ export * from "./fix-timezone-offset";
3
+ export * from "./format-date";
4
+ export * from "./get-current-date-in-utc";
5
+ export * from "./get-date-in-utc";
6
+ export * from "./parse-time-spent";
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA"}
@@ -1,6 +1,6 @@
1
1
  export * from "./dayjs";
2
- export * from "./fixTimezoneOffset";
3
- export * from "./formatDate";
4
- export * from "./getCurrentDateInUTC";
5
- export * from "./getDateInUTC";
6
- export * from "./parseTimeSpent";
2
+ export * from "./fix-timezone-offset";
3
+ export * from "./format-date";
4
+ export * from "./get-current-date-in-utc";
5
+ export * from "./get-date-in-utc";
6
+ export * from "./parse-time-spent";
@@ -1,6 +1,6 @@
1
1
  export * from "./dayjs";
2
- export * from "./fixTimezoneOffset";
3
- export * from "./formatDate";
4
- export * from "./getCurrentDateInUTC";
5
- export * from "./getDateInUTC";
6
- export * from "./parseTimeSpent";
2
+ export * from "./fix-timezone-offset";
3
+ export * from "./format-date";
4
+ export * from "./get-current-date-in-utc";
5
+ export * from "./get-date-in-utc";
6
+ export * from "./parse-time-spent";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,sDAAmC;AACnC,+CAA4B;AAC5B,wDAAqC;AACrC,iDAA8B;AAC9B,mDAAgC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,wDAAqC;AACrC,gDAA6B;AAC7B,4DAAyC;AACzC,oDAAiC;AACjC,qDAAkC"}
@@ -1,2 +1,2 @@
1
1
  export declare function parseTimeSpent(initialDate: string | Date, finalDate: string | Date, locale?: string): string;
2
- //# sourceMappingURL=parseTimeSpent.d.ts.map
2
+ //# sourceMappingURL=parse-time-spent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-time-spent.d.ts","sourceRoot":"","sources":["../../src/date/parse-time-spent.ts"],"names":[],"mappings":"AA4DA,wBAAgB,cAAc,CAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,MAAM,SAAU,UAsCjB"}
@@ -1,4 +1,4 @@
1
- import { fixTimezoneOffset } from "./fixTimezoneOffset";
1
+ import { fixTimezoneOffset } from "./fix-timezone-offset";
2
2
  // Supported locales and their translations
3
3
  const locales = {
4
4
  "pt-BR": {
@@ -1,4 +1,4 @@
1
- import { fixTimezoneOffset } from "./fixTimezoneOffset";
1
+ import { fixTimezoneOffset } from "./fix-timezone-offset";
2
2
  // Supported locales and their translations
3
3
  const locales = {
4
4
  "pt-BR": {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-time-spent.js","sourceRoot":"","sources":["../../src/date/parse-time-spent.ts"],"names":[],"mappings":";;AA4DA,wCAyCC;AArGD,+DAAyD;AASzD,2CAA2C;AAC3C,MAAM,OAAO,GAAwC;IACnD,OAAO,EAAE;QACP,IAAI,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;QACzC,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE;QAC3C,GAAG,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;QACxC,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE;YACpB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,EAAE,CAAA;YACjC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAA;YACvC,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;YACxC,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;YACrC,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,QAAQ,EAAE,CAAA;QACjD,CAAC;KACF;IACD,OAAO,EAAE;QACP,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;QAC3C,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;QAC9C,GAAG,EAAE,EAAE,QAAQ,EAAE,KAAK,EA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O,CAAC,EAC/C,KAAK,CACN,CAAA;IAED,0DAA0D;IAC1D,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IAExD,wBAAwB;IACxB,MAAM,KAAK,GAAa,EAAE,CAAA;IAE1B,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,MAAM,IAAI,GACR,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAA;QACrE,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC,CAAA;IAChC,CAAC;IAED,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,GACR,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,CAAA;QACxE,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC,CAAA;IACjC,CAAC;IAED,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,MAAM,IAAI,GACR,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAA;QAClE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAA;IAC/B,CAAC;IAED,qDAAqD;IACrD,OAAO,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;AACvC,CAAC"}
@@ -0,0 +1,10 @@
1
+ interface ICompressImageParams {
2
+ file: File;
3
+ maxWidth?: number;
4
+ maxHeight?: number;
5
+ quality?: number;
6
+ allowedFileTypes?: string[];
7
+ }
8
+ export declare function compressImage({ file, maxWidth, maxHeight, quality, allowedFileTypes, }: ICompressImageParams): Promise<File>;
9
+ export {};
10
+ //# sourceMappingURL=compress-image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compress-image.d.ts","sourceRoot":"","sources":["../../src/files/compress-image.ts"],"names":[],"mappings":"AAAA,UAAU,oBAAoB;IAC5B,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC5B;AAYD,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,QAAmC,EACnC,SAAoC,EACpC,OAAW,EACX,gBAAyE,GAC1E,EAAE,oBAAoB,iBAiEtB"}
@@ -0,0 +1,57 @@
1
+ function convertToWebp(filename) {
2
+ const lastDotIndex = filename.lastIndexOf(".");
3
+ if (lastDotIndex === -1) {
4
+ return `${filename}.webp`;
5
+ }
6
+ return `${filename.substring(0, lastDotIndex)}.webp`;
7
+ }
8
+ export function compressImage({ file, maxWidth = Number.POSITIVE_INFINITY, maxHeight = Number.POSITIVE_INFINITY, quality = 1, allowedFileTypes = ["image/jpg", "image/jpeg", "image/png", "image/webp"], }) {
9
+ if (!allowedFileTypes.includes(file.type)) {
10
+ throw new Error("Image format not supported");
11
+ }
12
+ return new Promise((resolve, reject) => {
13
+ const reader = new FileReader();
14
+ reader.onload = (event) => {
15
+ var _a;
16
+ const compressed = new Image();
17
+ compressed.onload = () => {
18
+ const canvas = document.createElement("canvas");
19
+ let width = compressed.width;
20
+ let height = compressed.height;
21
+ if (width > height) {
22
+ if (width > maxWidth) {
23
+ height *= maxWidth / width;
24
+ width = maxWidth;
25
+ }
26
+ }
27
+ else {
28
+ if (height > maxHeight) {
29
+ width *= maxHeight / height;
30
+ height = maxHeight;
31
+ }
32
+ }
33
+ canvas.width = width;
34
+ canvas.height = height;
35
+ const context = canvas.getContext("2d");
36
+ if (!context) {
37
+ reject(new Error("Failed to get canvas context"));
38
+ return;
39
+ }
40
+ context.drawImage(compressed, 0, 0, width, height);
41
+ canvas.toBlob((blob) => {
42
+ if (!blob) {
43
+ reject(new Error("Failed to compress image."));
44
+ return;
45
+ }
46
+ const compressedFile = new File([blob], convertToWebp(file.name), {
47
+ type: "image/webp",
48
+ lastModified: Date.now(),
49
+ });
50
+ resolve(compressedFile);
51
+ }, "image/webp", quality);
52
+ };
53
+ compressed.src = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
54
+ };
55
+ reader.readAsDataURL(file);
56
+ });
57
+ }
@@ -0,0 +1,57 @@
1
+ function convertToWebp(filename) {
2
+ const lastDotIndex = filename.lastIndexOf(".");
3
+ if (lastDotIndex === -1) {
4
+ return `${filename}.webp`;
5
+ }
6
+ return `${filename.substring(0, lastDotIndex)}.webp`;
7
+ }
8
+ export function compressImage({ file, maxWidth = Number.POSITIVE_INFINITY, maxHeight = Number.POSITIVE_INFINITY, quality = 1, allowedFileTypes = ["image/jpg", "image/jpeg", "image/png", "image/webp"], }) {
9
+ if (!allowedFileTypes.includes(file.type)) {
10
+ throw new Error("Image format not supported");
11
+ }
12
+ return new Promise((resolve, reject) => {
13
+ const reader = new FileReader();
14
+ reader.onload = (event) => {
15
+ var _a;
16
+ const compressed = new Image();
17
+ compressed.onload = () => {
18
+ const canvas = document.createElement("canvas");
19
+ let width = compressed.width;
20
+ let height = compressed.height;
21
+ if (width > height) {
22
+ if (width > maxWidth) {
23
+ height *= maxWidth / width;
24
+ width = maxWidth;
25
+ }
26
+ }
27
+ else {
28
+ if (height > maxHeight) {
29
+ width *= maxHeight / height;
30
+ height = maxHeight;
31
+ }
32
+ }
33
+ canvas.width = width;
34
+ canvas.height = height;
35
+ const context = canvas.getContext("2d");
36
+ if (!context) {
37
+ reject(new Error("Failed to get canvas context"));
38
+ return;
39
+ }
40
+ context.drawImage(compressed, 0, 0, width, height);
41
+ canvas.toBlob((blob) => {
42
+ if (!blob) {
43
+ reject(new Error("Failed to compress image."));
44
+ return;
45
+ }
46
+ const compressedFile = new File([blob], convertToWebp(file.name), {
47
+ type: "image/webp",
48
+ lastModified: Date.now(),
49
+ });
50
+ resolve(compressedFile);
51
+ }, "image/webp", quality);
52
+ };
53
+ compressed.src = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
54
+ };
55
+ reader.readAsDataURL(file);
56
+ });
57
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compress-image.js","sourceRoot":"","sources":["../../src/files/compress-image.ts"],"names":[],"mappings":";;AAkBA,sCAuEC;AAjFD,SAAS,aAAa,CAAC,QAAgB;IACrC,MAAM,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAE9C,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE,CAAC;QACxB,OAAO,GAAG,QAAQ,OAAO,CAAA;IAC3B,CAAC;IAED,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,YAAY,CAAC,OAAO,CAAA;AACtD,CAAC;AAED,SAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,QAAQ,GAAG,MAAM,CAAC,iBAAiB,EACnC,SAAS,GAAG,MAAM,CAAC,iBAAiB,EACpC,OAAO,GAAG,CAAC,EACX,gBAAgB,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,CAAC,GACpD;IACrB,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;IAC/C,CAAC;IAED,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAA;QAE/B,MAAM,CAAC,MAAM,GAAG,CAAC,KAAK,EAAE,EAAE;;YACxB,MAAM,UAAU,GAAG,IAAI,KA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AAC,EAAE;wBAChE,IAAI,EAAE,YAAY;wBAClB,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE;qBACzB,CAAC,CAAA;oBAEF,OAAO,CAAC,cAAc,CAAC,CAAA;gBACzB,CAAC,EACD,YAAY,EACZ,OAAO,CACR,CAAA;YACH,CAAC,CAAA;YAED,UAAU,CAAC,GAAG,GAAG,MAAA,KAAK,CAAC,MAAM,0CAAE,MAAgB,CAAA;QACjD,CAAC,CAAA;QAED,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const downloadUrl: (url: string) => Promise<boolean>;
2
+ //# sourceMappingURL=download-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download-url.d.ts","sourceRoot":"","sources":["../../src/files/download-url.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,OAAO,CAyB9D,CAAA"}
@@ -0,0 +1,24 @@
1
+ export const downloadUrl = async (url) => {
2
+ try {
3
+ const urlObj = new URL(url);
4
+ const pathname = urlObj.pathname;
5
+ const segments = pathname.split("/").filter((segment) => segment.length > 0);
6
+ const filename = segments.length > 0 ? segments[segments.length - 1] : null;
7
+ if (!filename || !filename.includes(".")) {
8
+ throw new Error("URL does not contain a valid filename");
9
+ }
10
+ const response = await fetch(url, { mode: "cors" });
11
+ const blob = await response.blob();
12
+ const link = document.createElement("a");
13
+ link.href = window.URL.createObjectURL(blob);
14
+ link.download = filename;
15
+ document.body.appendChild(link);
16
+ link.click();
17
+ document.body.removeChild(link);
18
+ return true;
19
+ }
20
+ catch (error) {
21
+ console.error("Error downloading the file", error);
22
+ return false;
23
+ }
24
+ };
@@ -0,0 +1,24 @@
1
+ export const downloadUrl = async (url) => {
2
+ try {
3
+ const urlObj = new URL(url);
4
+ const pathname = urlObj.pathname;
5
+ const segments = pathname.split("/").filter((segment) => segment.length > 0);
6
+ const filename = segments.length > 0 ? segments[segments.length - 1] : null;
7
+ if (!filename || !filename.includes(".")) {
8
+ throw new Error("URL does not contain a valid filename");
9
+ }
10
+ const response = await fetch(url, { mode: "cors" });
11
+ const blob = await response.blob();
12
+ const link = document.createElement("a");
13
+ link.href = window.URL.createObjectURL(blob);
14
+ link.download = filename;
15
+ document.body.appendChild(link);
16
+ link.click();
17
+ document.body.removeChild(link);
18
+ return true;
19
+ }
20
+ catch (error) {
21
+ console.error("Error downloading the file", error);
22
+ return false;
23
+ }
24
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download-url.js","sourceRoot":"","sources":["../../src/files/download-url.ts"],"names":[],"mappings":";;;AAAO,MAAM,WAAW,GAAG,KAAK,EAAE,GAAW,EAAoB,EAAE;IACjE,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;QAChC,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAC5E,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;QAE3E,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;QAC1D,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;QACnD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAElC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;QACxC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;QAC5C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QAC/B,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QAC/B,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAA;QAClD,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AAzBY,QAAA,WAAW,eAyBvB"}
@@ -0,0 +1,2 @@
1
+ export declare function formatBytes(bytes: number): string;
2
+ //# sourceMappingURL=format-bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-bytes.d.ts","sourceRoot":"","sources":["../../src/files/format-bytes.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAejD"}
@@ -0,0 +1,13 @@
1
+ export function formatBytes(bytes) {
2
+ if (bytes < 0) {
3
+ throw new Error("Size in bytes cannot be negative");
4
+ }
5
+ const units = ["B", "KB", "MB", "GB", "TB", "PB"];
6
+ let size = bytes;
7
+ let index = 0;
8
+ while (size >= 1024 && index < units.length - 1) {
9
+ size /= 1024;
10
+ index++;
11
+ }
12
+ return `${size.toFixed(2)} ${units[index]}`;
13
+ }
@@ -0,0 +1,13 @@
1
+ export function formatBytes(bytes) {
2
+ if (bytes < 0) {
3
+ throw new Error("Size in bytes cannot be negative");
4
+ }
5
+ const units = ["B", "KB", "MB", "GB", "TB", "PB"];
6
+ let size = bytes;
7
+ let index = 0;
8
+ while (size >= 1024 && index < units.length - 1) {
9
+ size /= 1024;
10
+ index++;
11
+ }
12
+ return `${size.toFixed(2)} ${units[index]}`;
13
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-bytes.js","sourceRoot":"","sources":["../../src/files/format-bytes.ts"],"names":[],"mappings":";;AAAA,kCAeC;AAfD,SAAgB,WAAW,CAAC,KAAa;IACvC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;IACrD,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IACjD,IAAI,IAAI,GAAG,KAAK,CAAA;IAChB,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,OAAO,IAAI,IAAI,IAAI,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,IAAI,IAAI,IAAI,CAAA;QACZ,KAAK,EAAE,CAAA;IACT,CAAC;IAED,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAA;AAC7C,CAAC"}