@catbee/utils 0.0.8-rc.1 → 0.0.8-rc.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.
Files changed (280) hide show
  1. package/build/esm/config.d.ts +0 -1
  2. package/build/esm/config.js +6 -7
  3. package/build/esm/index.d.ts +0 -1
  4. package/build/esm/index.js +0 -1
  5. package/build/esm/servers/server.builder.d.ts +0 -1
  6. package/build/esm/servers/server.builder.js +99 -147
  7. package/build/esm/servers/server.d.ts +0 -1
  8. package/build/esm/servers/server.js +591 -876
  9. package/build/esm/types/api-response.d.ts +0 -1
  10. package/build/esm/types/api-response.js +0 -1
  11. package/build/esm/types/index.d.ts +0 -1
  12. package/build/esm/types/index.js +0 -1
  13. package/build/esm/types/server.d.ts +0 -1
  14. package/build/esm/types/server.js +0 -1
  15. package/build/esm/utils/array.utils.d.ts +0 -1
  16. package/build/esm/utils/array.utils.js +48 -86
  17. package/build/esm/utils/async.utils.d.ts +0 -1
  18. package/build/esm/utils/async.utils.js +247 -524
  19. package/build/esm/utils/cache.utils.d.ts +0 -1
  20. package/build/esm/utils/cache.utils.js +96 -301
  21. package/build/esm/utils/context-store.utils.d.ts +0 -1
  22. package/build/esm/utils/context-store.utils.js +62 -79
  23. package/build/esm/utils/crypto.utils.d.ts +0 -1
  24. package/build/esm/utils/crypto.utils.js +78 -175
  25. package/build/esm/utils/date.utils.d.ts +0 -1
  26. package/build/esm/utils/date.utils.js +47 -53
  27. package/build/esm/utils/decorators.utils.d.ts +30 -27
  28. package/build/esm/utils/decorators.utils.js +417 -461
  29. package/build/esm/utils/dir.utils.d.ts +0 -1
  30. package/build/esm/utils/dir.utils.js +264 -786
  31. package/build/esm/utils/env.utils.d.ts +0 -1
  32. package/build/esm/utils/env.utils.js +180 -271
  33. package/build/esm/utils/exception.utils.d.ts +0 -1
  34. package/build/esm/utils/exception.utils.js +112 -289
  35. package/build/esm/utils/fs.utils.d.ts +0 -1
  36. package/build/esm/utils/fs.utils.js +169 -401
  37. package/build/esm/utils/http-status-codes.d.ts +0 -1
  38. package/build/esm/utils/http-status-codes.js +0 -1
  39. package/build/esm/utils/id.utils.d.ts +0 -1
  40. package/build/esm/utils/id.utils.js +5 -9
  41. package/build/esm/utils/logger.utils.d.ts +0 -1
  42. package/build/esm/utils/logger.utils.js +34 -71
  43. package/build/esm/utils/middleware.utils.d.ts +0 -1
  44. package/build/esm/utils/middleware.utils.js +65 -155
  45. package/build/esm/utils/obj.utils.d.ts +0 -1
  46. package/build/esm/utils/obj.utils.js +69 -176
  47. package/build/esm/utils/performance.utils.d.ts +0 -1
  48. package/build/esm/utils/performance.utils.js +92 -195
  49. package/build/esm/utils/request.utils.d.ts +0 -1
  50. package/build/esm/utils/request.utils.js +41 -74
  51. package/build/esm/utils/response.utils.d.ts +0 -1
  52. package/build/esm/utils/response.utils.js +84 -107
  53. package/build/esm/utils/stream.utils.d.ts +0 -1
  54. package/build/esm/utils/stream.utils.js +38 -113
  55. package/build/esm/utils/string.utils.d.ts +0 -1
  56. package/build/esm/utils/string.utils.js +6 -11
  57. package/build/esm/utils/type.utils.d.ts +0 -1
  58. package/build/esm/utils/type.utils.js +8 -12
  59. package/build/esm/utils/url.utils.d.ts +0 -1
  60. package/build/esm/utils/url.utils.js +49 -127
  61. package/build/esm/utils/validate.utils.d.ts +0 -1
  62. package/build/esm/utils/validate.utils.js +23 -40
  63. package/package.json +3 -33
  64. package/build/esm/config.js.map +0 -1
  65. package/build/esm/index.js.map +0 -1
  66. package/build/esm/servers/server.builder.js.map +0 -1
  67. package/build/esm/servers/server.js.map +0 -1
  68. package/build/esm/types/api-response.js.map +0 -1
  69. package/build/esm/types/index.js.map +0 -1
  70. package/build/esm/types/server.js.map +0 -1
  71. package/build/esm/utils/array.utils.js.map +0 -1
  72. package/build/esm/utils/async.utils.js.map +0 -1
  73. package/build/esm/utils/cache.utils.js.map +0 -1
  74. package/build/esm/utils/context-store.utils.js.map +0 -1
  75. package/build/esm/utils/crypto.utils.js.map +0 -1
  76. package/build/esm/utils/date.utils.js.map +0 -1
  77. package/build/esm/utils/decorators.utils.js.map +0 -1
  78. package/build/esm/utils/dir.utils.js.map +0 -1
  79. package/build/esm/utils/env.utils.js.map +0 -1
  80. package/build/esm/utils/exception.utils.js.map +0 -1
  81. package/build/esm/utils/fs.utils.js.map +0 -1
  82. package/build/esm/utils/http-status-codes.js.map +0 -1
  83. package/build/esm/utils/id.utils.js.map +0 -1
  84. package/build/esm/utils/logger.utils.js.map +0 -1
  85. package/build/esm/utils/middleware.utils.js.map +0 -1
  86. package/build/esm/utils/obj.utils.js.map +0 -1
  87. package/build/esm/utils/performance.utils.js.map +0 -1
  88. package/build/esm/utils/request.utils.js.map +0 -1
  89. package/build/esm/utils/response.utils.js.map +0 -1
  90. package/build/esm/utils/stream.utils.js.map +0 -1
  91. package/build/esm/utils/string.utils.js.map +0 -1
  92. package/build/esm/utils/type.utils.js.map +0 -1
  93. package/build/esm/utils/url.utils.js.map +0 -1
  94. package/build/esm/utils/validate.utils.js.map +0 -1
  95. package/build/esnext/config.d.ts +0 -122
  96. package/build/esnext/config.js +0 -133
  97. package/build/esnext/config.js.map +0 -1
  98. package/build/esnext/index.d.ts +0 -27
  99. package/build/esnext/index.js +0 -50
  100. package/build/esnext/index.js.map +0 -1
  101. package/build/esnext/servers/server.builder.d.ts +0 -508
  102. package/build/esnext/servers/server.builder.js +0 -657
  103. package/build/esnext/servers/server.builder.js.map +0 -1
  104. package/build/esnext/servers/server.d.ts +0 -256
  105. package/build/esnext/servers/server.js +0 -955
  106. package/build/esnext/servers/server.js.map +0 -1
  107. package/build/esnext/types/api-response.d.ts +0 -152
  108. package/build/esnext/types/api-response.js +0 -34
  109. package/build/esnext/types/api-response.js.map +0 -1
  110. package/build/esnext/types/index.d.ts +0 -125
  111. package/build/esnext/types/index.js +0 -25
  112. package/build/esnext/types/index.js.map +0 -1
  113. package/build/esnext/types/server.d.ts +0 -268
  114. package/build/esnext/types/server.js +0 -25
  115. package/build/esnext/types/server.js.map +0 -1
  116. package/build/esnext/utils/array.utils.d.ts +0 -168
  117. package/build/esnext/utils/array.utils.js +0 -345
  118. package/build/esnext/utils/array.utils.js.map +0 -1
  119. package/build/esnext/utils/async.utils.d.ts +0 -265
  120. package/build/esnext/utils/async.utils.js +0 -620
  121. package/build/esnext/utils/async.utils.js.map +0 -1
  122. package/build/esnext/utils/cache.utils.d.ts +0 -153
  123. package/build/esnext/utils/cache.utils.js +0 -293
  124. package/build/esnext/utils/cache.utils.js.map +0 -1
  125. package/build/esnext/utils/context-store.utils.d.ts +0 -189
  126. package/build/esnext/utils/context-store.utils.js +0 -289
  127. package/build/esnext/utils/context-store.utils.js.map +0 -1
  128. package/build/esnext/utils/crypto.utils.d.ts +0 -160
  129. package/build/esnext/utils/crypto.utils.js +0 -276
  130. package/build/esnext/utils/crypto.utils.js.map +0 -1
  131. package/build/esnext/utils/date.utils.d.ts +0 -159
  132. package/build/esnext/utils/date.utils.js +0 -384
  133. package/build/esnext/utils/date.utils.js.map +0 -1
  134. package/build/esnext/utils/decorators.utils.d.ts +0 -508
  135. package/build/esnext/utils/decorators.utils.js +0 -877
  136. package/build/esnext/utils/decorators.utils.js.map +0 -1
  137. package/build/esnext/utils/dir.utils.d.ts +0 -196
  138. package/build/esnext/utils/dir.utils.js +0 -477
  139. package/build/esnext/utils/dir.utils.js.map +0 -1
  140. package/build/esnext/utils/env.utils.d.ts +0 -377
  141. package/build/esnext/utils/env.utils.js +0 -785
  142. package/build/esnext/utils/env.utils.js.map +0 -1
  143. package/build/esnext/utils/exception.utils.d.ts +0 -230
  144. package/build/esnext/utils/exception.utils.js +0 -381
  145. package/build/esnext/utils/exception.utils.js.map +0 -1
  146. package/build/esnext/utils/fs.utils.d.ts +0 -164
  147. package/build/esnext/utils/fs.utils.js +0 -349
  148. package/build/esnext/utils/fs.utils.js.map +0 -1
  149. package/build/esnext/utils/http-status-codes.d.ts +0 -266
  150. package/build/esnext/utils/http-status-codes.js +0 -295
  151. package/build/esnext/utils/http-status-codes.js.map +0 -1
  152. package/build/esnext/utils/id.utils.d.ts +0 -36
  153. package/build/esnext/utils/id.utils.js +0 -84
  154. package/build/esnext/utils/id.utils.js.map +0 -1
  155. package/build/esnext/utils/logger.utils.d.ts +0 -160
  156. package/build/esnext/utils/logger.utils.js +0 -300
  157. package/build/esnext/utils/logger.utils.js.map +0 -1
  158. package/build/esnext/utils/middleware.utils.d.ts +0 -100
  159. package/build/esnext/utils/middleware.utils.js +0 -236
  160. package/build/esnext/utils/middleware.utils.js.map +0 -1
  161. package/build/esnext/utils/obj.utils.d.ts +0 -124
  162. package/build/esnext/utils/obj.utils.js +0 -413
  163. package/build/esnext/utils/obj.utils.js.map +0 -1
  164. package/build/esnext/utils/performance.utils.d.ts +0 -136
  165. package/build/esnext/utils/performance.utils.js +0 -271
  166. package/build/esnext/utils/performance.utils.js.map +0 -1
  167. package/build/esnext/utils/request.utils.d.ts +0 -86
  168. package/build/esnext/utils/request.utils.js +0 -186
  169. package/build/esnext/utils/request.utils.js.map +0 -1
  170. package/build/esnext/utils/response.utils.d.ts +0 -163
  171. package/build/esnext/utils/response.utils.js +0 -247
  172. package/build/esnext/utils/response.utils.js.map +0 -1
  173. package/build/esnext/utils/stream.utils.d.ts +0 -88
  174. package/build/esnext/utils/stream.utils.js +0 -210
  175. package/build/esnext/utils/stream.utils.js.map +0 -1
  176. package/build/esnext/utils/string.utils.d.ts +0 -93
  177. package/build/esnext/utils/string.utils.js +0 -165
  178. package/build/esnext/utils/string.utils.js.map +0 -1
  179. package/build/esnext/utils/type.utils.d.ts +0 -90
  180. package/build/esnext/utils/type.utils.js +0 -187
  181. package/build/esnext/utils/type.utils.js.map +0 -1
  182. package/build/esnext/utils/url.utils.d.ts +0 -141
  183. package/build/esnext/utils/url.utils.js +0 -304
  184. package/build/esnext/utils/url.utils.js.map +0 -1
  185. package/build/esnext/utils/validate.utils.d.ts +0 -177
  186. package/build/esnext/utils/validate.utils.js +0 -320
  187. package/build/esnext/utils/validate.utils.js.map +0 -1
  188. package/build/src/config.d.ts +0 -122
  189. package/build/src/config.js +0 -138
  190. package/build/src/config.js.map +0 -1
  191. package/build/src/index.d.ts +0 -27
  192. package/build/src/index.js +0 -69
  193. package/build/src/index.js.map +0 -1
  194. package/build/src/servers/server.builder.d.ts +0 -508
  195. package/build/src/servers/server.builder.js +0 -661
  196. package/build/src/servers/server.builder.js.map +0 -1
  197. package/build/src/servers/server.d.ts +0 -256
  198. package/build/src/servers/server.js +0 -962
  199. package/build/src/servers/server.js.map +0 -1
  200. package/build/src/types/api-response.d.ts +0 -152
  201. package/build/src/types/api-response.js +0 -37
  202. package/build/src/types/api-response.js.map +0 -1
  203. package/build/src/types/index.d.ts +0 -125
  204. package/build/src/types/index.js +0 -26
  205. package/build/src/types/index.js.map +0 -1
  206. package/build/src/types/server.d.ts +0 -268
  207. package/build/src/types/server.js +0 -26
  208. package/build/src/types/server.js.map +0 -1
  209. package/build/src/utils/array.utils.d.ts +0 -168
  210. package/build/src/utils/array.utils.js +0 -364
  211. package/build/src/utils/array.utils.js.map +0 -1
  212. package/build/src/utils/async.utils.d.ts +0 -265
  213. package/build/src/utils/async.utils.js +0 -641
  214. package/build/src/utils/async.utils.js.map +0 -1
  215. package/build/src/utils/cache.utils.d.ts +0 -153
  216. package/build/src/utils/cache.utils.js +0 -297
  217. package/build/src/utils/cache.utils.js.map +0 -1
  218. package/build/src/utils/context-store.utils.d.ts +0 -189
  219. package/build/src/utils/context-store.utils.js +0 -296
  220. package/build/src/utils/context-store.utils.js.map +0 -1
  221. package/build/src/utils/crypto.utils.d.ts +0 -160
  222. package/build/src/utils/crypto.utils.js +0 -293
  223. package/build/src/utils/crypto.utils.js.map +0 -1
  224. package/build/src/utils/date.utils.d.ts +0 -159
  225. package/build/src/utils/date.utils.js +0 -396
  226. package/build/src/utils/date.utils.js.map +0 -1
  227. package/build/src/utils/decorators.utils.d.ts +0 -508
  228. package/build/src/utils/decorators.utils.js +0 -896
  229. package/build/src/utils/decorators.utils.js.map +0 -1
  230. package/build/src/utils/dir.utils.d.ts +0 -196
  231. package/build/src/utils/dir.utils.js +0 -501
  232. package/build/src/utils/dir.utils.js.map +0 -1
  233. package/build/src/utils/env.utils.d.ts +0 -377
  234. package/build/src/utils/env.utils.js +0 -789
  235. package/build/src/utils/env.utils.js.map +0 -1
  236. package/build/src/utils/exception.utils.d.ts +0 -230
  237. package/build/src/utils/exception.utils.js +0 -407
  238. package/build/src/utils/exception.utils.js.map +0 -1
  239. package/build/src/utils/fs.utils.d.ts +0 -164
  240. package/build/src/utils/fs.utils.js +0 -372
  241. package/build/src/utils/fs.utils.js.map +0 -1
  242. package/build/src/utils/http-status-codes.d.ts +0 -266
  243. package/build/src/utils/http-status-codes.js +0 -298
  244. package/build/src/utils/http-status-codes.js.map +0 -1
  245. package/build/src/utils/id.utils.d.ts +0 -36
  246. package/build/src/utils/id.utils.js +0 -91
  247. package/build/src/utils/id.utils.js.map +0 -1
  248. package/build/src/utils/logger.utils.d.ts +0 -160
  249. package/build/src/utils/logger.utils.js +0 -346
  250. package/build/src/utils/logger.utils.js.map +0 -1
  251. package/build/src/utils/middleware.utils.d.ts +0 -100
  252. package/build/src/utils/middleware.utils.js +0 -244
  253. package/build/src/utils/middleware.utils.js.map +0 -1
  254. package/build/src/utils/obj.utils.d.ts +0 -124
  255. package/build/src/utils/obj.utils.js +0 -429
  256. package/build/src/utils/obj.utils.js.map +0 -1
  257. package/build/src/utils/performance.utils.d.ts +0 -136
  258. package/build/src/utils/performance.utils.js +0 -278
  259. package/build/src/utils/performance.utils.js.map +0 -1
  260. package/build/src/utils/request.utils.d.ts +0 -86
  261. package/build/src/utils/request.utils.js +0 -195
  262. package/build/src/utils/request.utils.js.map +0 -1
  263. package/build/src/utils/response.utils.d.ts +0 -163
  264. package/build/src/utils/response.utils.js +0 -260
  265. package/build/src/utils/response.utils.js.map +0 -1
  266. package/build/src/utils/stream.utils.d.ts +0 -88
  267. package/build/src/utils/stream.utils.js +0 -218
  268. package/build/src/utils/stream.utils.js.map +0 -1
  269. package/build/src/utils/string.utils.d.ts +0 -93
  270. package/build/src/utils/string.utils.js +0 -179
  271. package/build/src/utils/string.utils.js.map +0 -1
  272. package/build/src/utils/type.utils.d.ts +0 -90
  273. package/build/src/utils/type.utils.js +0 -196
  274. package/build/src/utils/type.utils.js.map +0 -1
  275. package/build/src/utils/url.utils.d.ts +0 -141
  276. package/build/src/utils/url.utils.js +0 -317
  277. package/build/src/utils/url.utils.js.map +0 -1
  278. package/build/src/utils/validate.utils.d.ts +0 -177
  279. package/build/src/utils/validate.utils.js +0 -345
  280. package/build/src/utils/validate.utils.js.map +0 -1
@@ -1,88 +0,0 @@
1
- import { Readable, Transform } from 'stream';
2
- import { BufferEncoding } from './crypto.utils';
3
- /**
4
- * Convert a buffer or string to a readable stream.
5
- *
6
- * @param data - Buffer or string to convert
7
- * @returns Readable stream containing the data
8
- *
9
- * @example
10
- * ```typescript
11
- * const stream = bufferToStream(Buffer.from('Hello world'));
12
- * // or
13
- * const stream = bufferToStream('Hello world');
14
- * ```
15
- */
16
- export declare function bufferToStream(data: Buffer | string): Readable;
17
- /**
18
- * Convert a readable stream to a buffer.
19
- *
20
- * @param stream - Readable stream to convert
21
- * @returns Promise resolving to a buffer containing all stream data
22
- *
23
- * @example
24
- * ```typescript
25
- * const buffer = await streamToBuffer(fs.createReadStream('file.txt'));
26
- * console.log(buffer.toString()); // Contents of file.txt
27
- * ```
28
- */
29
- export declare function streamToBuffer(stream: Readable): Promise<Buffer>;
30
- /**
31
- * Convert a readable stream to a string.
32
- *
33
- * @param stream - Readable stream to convert
34
- * @param encoding - Character encoding (default: 'utf8')
35
- * @returns Promise resolving to a string containing all stream data
36
- *
37
- * @example
38
- * ```typescript
39
- * const content = await streamToString(fs.createReadStream('file.txt'));
40
- * console.log(content); // Contents of file.txt as string
41
- * ```
42
- */
43
- export declare function streamToString(stream: Readable, encoding?: BufferEncoding): Promise<string>;
44
- /**
45
- * Create a transform stream that limits the rate of data flow.
46
- *
47
- * @param bytesPerSecond - Maximum bytes per second
48
- * @returns Transform stream that throttles data flow
49
- */
50
- export declare function createThrottleStream(bytesPerSecond: number): Transform;
51
- /**
52
- * Create a transform stream that batches data into chunks of specified size.
53
- *
54
- * @param size - Size of each batch (items for object mode, bytes for binary mode)
55
- * @param options - Stream options
56
- * @returns Transform stream that batches data
57
- *
58
- * @example
59
- * ```typescript
60
- * // Batch lines from a file into arrays of 100 lines each
61
- * createReadStream('large-file.txt')
62
- * .pipe(createLineStream())
63
- * .pipe(createBatchStream(100))
64
- * .on('data', batch => console.log(`Processing batch of ${batch.length} lines`));
65
- * ```
66
- */
67
- export declare function createBatchStream(size: number, options?: {
68
- objectMode?: boolean;
69
- }): Transform;
70
- /**
71
- * Create a transform stream that splits text data by newlines.
72
- *
73
- * @param options - Options for the line stream
74
- * @returns Transform stream that emits lines
75
- *
76
- * @example
77
- * ```typescript
78
- * // Process a file line by line
79
- * createReadStream('file.txt')
80
- * .pipe(createLineStream())
81
- * .on('data', line => console.log(`Line: ${line}`));
82
- * ```
83
- */
84
- export declare function createLineStream(options?: {
85
- encoding?: BufferEncoding;
86
- includeNewlines?: boolean;
87
- }): Transform;
88
- //# sourceMappingURL=stream.utils.d.ts.map
@@ -1,210 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- import { Readable, Transform } from 'stream';
25
- /**
26
- * Convert a buffer or string to a readable stream.
27
- *
28
- * @param data - Buffer or string to convert
29
- * @returns Readable stream containing the data
30
- *
31
- * @example
32
- * ```typescript
33
- * const stream = bufferToStream(Buffer.from('Hello world'));
34
- * // or
35
- * const stream = bufferToStream('Hello world');
36
- * ```
37
- */
38
- export function bufferToStream(data) {
39
- const readable = new Readable();
40
- readable.push(data);
41
- readable.push(null); // End of stream
42
- return readable;
43
- }
44
- /**
45
- * Convert a readable stream to a buffer.
46
- *
47
- * @param stream - Readable stream to convert
48
- * @returns Promise resolving to a buffer containing all stream data
49
- *
50
- * @example
51
- * ```typescript
52
- * const buffer = await streamToBuffer(fs.createReadStream('file.txt'));
53
- * console.log(buffer.toString()); // Contents of file.txt
54
- * ```
55
- */
56
- export async function streamToBuffer(stream) {
57
- return new Promise((resolve, reject) => {
58
- const chunks = [];
59
- stream.on('data', chunk => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
60
- stream.on('end', () => resolve(Buffer.concat(chunks)));
61
- stream.on('error', reject);
62
- });
63
- }
64
- /**
65
- * Convert a readable stream to a string.
66
- *
67
- * @param stream - Readable stream to convert
68
- * @param encoding - Character encoding (default: 'utf8')
69
- * @returns Promise resolving to a string containing all stream data
70
- *
71
- * @example
72
- * ```typescript
73
- * const content = await streamToString(fs.createReadStream('file.txt'));
74
- * console.log(content); // Contents of file.txt as string
75
- * ```
76
- */
77
- export async function streamToString(stream, encoding = 'utf8') {
78
- const buffer = await streamToBuffer(stream);
79
- return buffer.toString(encoding);
80
- }
81
- /**
82
- * Create a transform stream that limits the rate of data flow.
83
- *
84
- * @param bytesPerSecond - Maximum bytes per second
85
- * @returns Transform stream that throttles data flow
86
- */
87
- export function createThrottleStream(bytesPerSecond) {
88
- let bytesSent = 0;
89
- let startTime = Date.now();
90
- return new Transform({
91
- transform(chunk, _encoding, callback) {
92
- const elapsedSeconds = (Date.now() - startTime) / 1000;
93
- const targetBytes = bytesPerSecond * elapsedSeconds;
94
- const chunkSize = chunk.length;
95
- // If we've sent fewer bytes than our target, just send the chunk
96
- if (bytesSent + chunkSize <= targetBytes) {
97
- bytesSent += chunkSize;
98
- callback(null, chunk);
99
- return;
100
- }
101
- // Otherwise we need to throttle
102
- const delay = ((bytesSent + chunkSize) / bytesPerSecond - elapsedSeconds) * 1000;
103
- setTimeout(() => {
104
- bytesSent += chunkSize;
105
- callback(null, chunk);
106
- }, delay);
107
- }
108
- });
109
- }
110
- /**
111
- * Create a transform stream that batches data into chunks of specified size.
112
- *
113
- * @param size - Size of each batch (items for object mode, bytes for binary mode)
114
- * @param options - Stream options
115
- * @returns Transform stream that batches data
116
- *
117
- * @example
118
- * ```typescript
119
- * // Batch lines from a file into arrays of 100 lines each
120
- * createReadStream('large-file.txt')
121
- * .pipe(createLineStream())
122
- * .pipe(createBatchStream(100))
123
- * .on('data', batch => console.log(`Processing batch of ${batch.length} lines`));
124
- * ```
125
- */
126
- export function createBatchStream(size, options = {}) {
127
- const objectMode = options.objectMode !== false;
128
- let batch = [];
129
- let buffers = [];
130
- let bufferSize = 0;
131
- return new Transform({
132
- objectMode,
133
- transform(chunk, _encoding, callback) {
134
- if (objectMode) {
135
- batch.push(chunk);
136
- if (batch.length >= size) {
137
- this.push(batch);
138
- batch = [];
139
- }
140
- }
141
- else {
142
- const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
143
- buffers.push(buffer);
144
- bufferSize += buffer.length;
145
- // Emit batches of exact size
146
- let combined = Buffer.concat(buffers, bufferSize);
147
- while (combined.length >= size) {
148
- this.push(combined.slice(0, size));
149
- combined = combined.slice(size);
150
- }
151
- buffers = combined.length > 0 ? [combined] : [];
152
- bufferSize = combined.length;
153
- }
154
- callback();
155
- },
156
- flush(callback) {
157
- if (objectMode && batch.length > 0) {
158
- this.push(batch);
159
- }
160
- else if (!objectMode && buffers.length > 0 && bufferSize > 0) {
161
- let combined = Buffer.concat(buffers, bufferSize);
162
- while (combined.length >= size) {
163
- this.push(combined.slice(0, size));
164
- combined = combined.slice(size);
165
- }
166
- if (combined.length > 0) {
167
- this.push(combined);
168
- }
169
- }
170
- callback();
171
- }
172
- });
173
- }
174
- /**
175
- * Create a transform stream that splits text data by newlines.
176
- *
177
- * @param options - Options for the line stream
178
- * @returns Transform stream that emits lines
179
- *
180
- * @example
181
- * ```typescript
182
- * // Process a file line by line
183
- * createReadStream('file.txt')
184
- * .pipe(createLineStream())
185
- * .on('data', line => console.log(`Line: ${line}`));
186
- * ```
187
- */
188
- export function createLineStream(options = {}) {
189
- const { encoding = 'utf8', includeNewlines = false } = options;
190
- let buffer = '';
191
- return new Transform({
192
- objectMode: true,
193
- transform(chunk, _encoding, callback) {
194
- const str = buffer + (Buffer.isBuffer(chunk) ? chunk.toString(encoding) : chunk);
195
- const lines = str.split(/\r?\n/);
196
- buffer = lines.pop() || '';
197
- for (const line of lines) {
198
- this.push(includeNewlines ? line + '\n' : line);
199
- }
200
- callback();
201
- },
202
- flush(callback) {
203
- if (buffer) {
204
- this.push(buffer);
205
- }
206
- callback();
207
- }
208
- });
209
- }
210
- //# sourceMappingURL=stream.utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.utils.js","sourceRoot":"","sources":["../../../src/utils/stream.utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAqB,MAAM,QAAQ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b,CAAC;QAED,KAAK,CAAC,QAAQ;YACZ,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC;YACD,QAAQ,EAAE,CAAC;QACb,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Readable, Transform, TransformCallback } from 'stream';\nimport { BufferEncoding } from './crypto.utils';\n\n/**\n * Convert a buffer or string to a readable stream.\n *\n * @param data - Buffer or string to convert\n * @returns Readable stream containing the data\n *\n * @example\n * ```typescript\n * const stream = bufferToStream(Buffer.from('Hello world'));\n * // or\n * const stream = bufferToStream('Hello world');\n * ```\n */\nexport function bufferToStream(data: Buffer | string): Readable {\n const readable = new Readable();\n readable.push(data);\n readable.push(null); // End of stream\n return readable;\n}\n\n/**\n * Convert a readable stream to a buffer.\n *\n * @param stream - Readable stream to convert\n * @returns Promise resolving to a buffer containing all stream data\n *\n * @example\n * ```typescript\n * const buffer = await streamToBuffer(fs.createReadStream('file.txt'));\n * console.log(buffer.toString()); // Contents of file.txt\n * ```\n */\nexport async function streamToBuffer(stream: Readable): Promise<Buffer> {\n return new Promise<Buffer>((resolve, reject) => {\n const chunks: Buffer[] = [];\n stream.on('data', chunk => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));\n stream.on('end', () => resolve(Buffer.concat(chunks)));\n stream.on('error', reject);\n });\n}\n\n/**\n * Convert a readable stream to a string.\n *\n * @param stream - Readable stream to convert\n * @param encoding - Character encoding (default: 'utf8')\n * @returns Promise resolving to a string containing all stream data\n *\n * @example\n * ```typescript\n * const content = await streamToString(fs.createReadStream('file.txt'));\n * console.log(content); // Contents of file.txt as string\n * ```\n */\nexport async function streamToString(stream: Readable, encoding: BufferEncoding = 'utf8'): Promise<string> {\n const buffer = await streamToBuffer(stream);\n return buffer.toString(encoding);\n}\n\n/**\n * Create a transform stream that limits the rate of data flow.\n *\n * @param bytesPerSecond - Maximum bytes per second\n * @returns Transform stream that throttles data flow\n */\nexport function createThrottleStream(bytesPerSecond: number): Transform {\n let bytesSent = 0;\n let startTime = Date.now();\n\n return new Transform({\n transform(chunk: Buffer, _encoding: BufferEncoding, callback: TransformCallback) {\n const elapsedSeconds = (Date.now() - startTime) / 1000;\n const targetBytes = bytesPerSecond * elapsedSeconds;\n const chunkSize = chunk.length;\n\n // If we've sent fewer bytes than our target, just send the chunk\n if (bytesSent + chunkSize <= targetBytes) {\n bytesSent += chunkSize;\n callback(null, chunk);\n return;\n }\n\n // Otherwise we need to throttle\n const delay = ((bytesSent + chunkSize) / bytesPerSecond - elapsedSeconds) * 1000;\n\n setTimeout(() => {\n bytesSent += chunkSize;\n callback(null, chunk);\n }, delay);\n }\n });\n}\n\n/**\n * Create a transform stream that batches data into chunks of specified size.\n *\n * @param size - Size of each batch (items for object mode, bytes for binary mode)\n * @param options - Stream options\n * @returns Transform stream that batches data\n *\n * @example\n * ```typescript\n * // Batch lines from a file into arrays of 100 lines each\n * createReadStream('large-file.txt')\n * .pipe(createLineStream())\n * .pipe(createBatchStream(100))\n * .on('data', batch => console.log(`Processing batch of ${batch.length} lines`));\n * ```\n */\nexport function createBatchStream(size: number, options: { objectMode?: boolean } = {}): Transform {\n const objectMode = options.objectMode !== false;\n let batch: any[] = [];\n let buffers: Buffer[] = [];\n let bufferSize = 0;\n\n return new Transform({\n objectMode,\n transform(chunk, _encoding, callback) {\n if (objectMode) {\n batch.push(chunk);\n if (batch.length >= size) {\n this.push(batch);\n batch = [];\n }\n } else {\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n buffers.push(buffer);\n bufferSize += buffer.length;\n\n // Emit batches of exact size\n let combined = Buffer.concat(buffers, bufferSize);\n while (combined.length >= size) {\n this.push(combined.slice(0, size));\n combined = combined.slice(size);\n }\n buffers = combined.length > 0 ? [combined] : [];\n bufferSize = combined.length;\n }\n\n callback();\n },\n\n flush(callback) {\n if (objectMode && batch.length > 0) {\n this.push(batch);\n } else if (!objectMode && buffers.length > 0 && bufferSize > 0) {\n let combined = Buffer.concat(buffers, bufferSize);\n while (combined.length >= size) {\n this.push(combined.slice(0, size));\n combined = combined.slice(size);\n }\n if (combined.length > 0) {\n this.push(combined);\n }\n }\n callback();\n }\n });\n}\n\n/**\n * Create a transform stream that splits text data by newlines.\n *\n * @param options - Options for the line stream\n * @returns Transform stream that emits lines\n *\n * @example\n * ```typescript\n * // Process a file line by line\n * createReadStream('file.txt')\n * .pipe(createLineStream())\n * .on('data', line => console.log(`Line: ${line}`));\n * ```\n */\nexport function createLineStream(\n options: {\n encoding?: BufferEncoding;\n includeNewlines?: boolean;\n } = {}\n): Transform {\n const { encoding = 'utf8', includeNewlines = false } = options;\n let buffer = '';\n\n return new Transform({\n objectMode: true,\n transform(chunk, _encoding, callback) {\n const str = buffer + (Buffer.isBuffer(chunk) ? chunk.toString(encoding) : chunk);\n const lines = str.split(/\\r?\\n/);\n buffer = lines.pop() || '';\n\n for (const line of lines) {\n this.push(includeNewlines ? line + '\\n' : line);\n }\n\n callback();\n },\n\n flush(callback) {\n if (buffer) {\n this.push(buffer);\n }\n callback();\n }\n });\n}\n"]}
@@ -1,93 +0,0 @@
1
- /**
2
- * Capitalizes the first character of a string.
3
- *
4
- * @param {string} str - The input string.
5
- * @returns {string} The string with the first character in uppercase.
6
- */
7
- export declare function capitalize(str: string): string;
8
- /**
9
- * Converts a string to kebab-case (e.g., "FooBar test" → "foo-bar-test").
10
- *
11
- * @param {string} str - The input string.
12
- * @returns {string} The kebab-cased string.
13
- */
14
- export declare function toKebabCase(str: string): string;
15
- /**
16
- * Converts a kebab-case or snake_case string to camelCase.
17
- *
18
- * @param {string} str - The input string.
19
- * @returns {string} The camelCased string.
20
- */
21
- export declare function toCamelCase(str: string): string;
22
- /**
23
- * Converts a string to a URL-friendly slug (lowercase, dashes, alphanumeric).
24
- *
25
- * @param {string} str - The input string.
26
- * @returns {string} The slugified string.
27
- */
28
- export declare function slugify(str: string): string;
29
- /**
30
- * Truncates a string to a specific length, appending '...' if truncated.
31
- *
32
- * @param {string} str - The input string.
33
- * @param {number} len - The maximum length.
34
- * @returns {string} The truncated string.
35
- */
36
- export declare function truncate(str: string, len: number): string;
37
- /**
38
- * Converts a string to PascalCase (e.g., "foo-bar" → "FooBar").
39
- *
40
- * @param {string} str - The input string.
41
- * @returns {string} The PascalCased string.
42
- */
43
- export declare function toPascalCase(str: string): string;
44
- /**
45
- * Converts a string to snake_case (e.g., "FooBar test" → "foo_bar_test").
46
- *
47
- * @param {string} str - The input string.
48
- * @returns {string} The snake_cased string.
49
- */
50
- export declare function toSnakeCase(str: string): string;
51
- /**
52
- * Masks a string by replacing characters with a mask character.
53
- * Useful for hiding sensitive information like credit cards or passwords.
54
- *
55
- * @param {string} str - The string to mask.
56
- * @param {number} [visibleStart=0] - Number of characters to show at start.
57
- * @param {number} [visibleEnd=0] - Number of characters to show at end.
58
- * @param {string} [maskChar="*"] - Character to use for masking.
59
- * @returns {string} The masked string.
60
- */
61
- export declare function mask(str: string, visibleStart?: number, visibleEnd?: number, maskChar?: string): string;
62
- /**
63
- * Removes all HTML tags from a string.
64
- *
65
- * @param {string} str - The HTML string to process.
66
- * @returns {string} The string with HTML tags removed.
67
- */
68
- export declare function stripHtml(str: string): string;
69
- /**
70
- * Performs case-insensitive string comparison.
71
- *
72
- * @param {string} a - First string.
73
- * @param {string} b - Second string.
74
- * @returns {boolean} True if the strings are equal ignoring case.
75
- */
76
- export declare function equalsIgnoreCase(a: string, b: string): boolean;
77
- /**
78
- * Reverses a string.
79
- *
80
- * @param {string} str - The string to reverse.
81
- * @returns {string} The reversed string.
82
- */
83
- export declare function reverse(str: string): string;
84
- /**
85
- * Counts occurrences of a substring within a string.
86
- *
87
- * @param {string} str - The source string.
88
- * @param {string} substring - The substring to count.
89
- * @param {boolean} [caseSensitive=true] - Whether to perform case-sensitive counting.
90
- * @returns {number} Number of occurrences.
91
- */
92
- export declare function countOccurrences(str: string, substring: string, caseSensitive?: boolean): number;
93
- //# sourceMappingURL=string.utils.d.ts.map
@@ -1,165 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- /**
25
- * Capitalizes the first character of a string.
26
- *
27
- * @param {string} str - The input string.
28
- * @returns {string} The string with the first character in uppercase.
29
- */
30
- export function capitalize(str) {
31
- return str.length === 0 ? '' : str.charAt(0).toUpperCase() + str.slice(1);
32
- }
33
- /**
34
- * Converts a string to kebab-case (e.g., "FooBar test" → "foo-bar-test").
35
- *
36
- * @param {string} str - The input string.
37
- * @returns {string} The kebab-cased string.
38
- */
39
- export function toKebabCase(str) {
40
- return str
41
- .replace(/([a-z])([A-Z])/g, '$1-$2') // camelCase -> camel-Case
42
- .replace(/\s+/g, '-') // spaces to dash
43
- .replace(/_+/g, '-') // underscores to dash
44
- .toLowerCase();
45
- }
46
- /**
47
- * Converts a kebab-case or snake_case string to camelCase.
48
- *
49
- * @param {string} str - The input string.
50
- * @returns {string} The camelCased string.
51
- */
52
- export function toCamelCase(str) {
53
- return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase());
54
- }
55
- /**
56
- * Converts a string to a URL-friendly slug (lowercase, dashes, alphanumeric).
57
- *
58
- * @param {string} str - The input string.
59
- * @returns {string} The slugified string.
60
- */
61
- export function slugify(str) {
62
- return str
63
- .toLowerCase()
64
- .replace(/[^\w\s-]/g, '') // remove non-word
65
- .replace(/\s+/g, '-') // spaces to dash
66
- .replace(/-+/g, '-') // multiple dashes to one
67
- .replace(/^-+|-+$/g, ''); // trim leading/trailing dashes
68
- }
69
- /**
70
- * Truncates a string to a specific length, appending '...' if truncated.
71
- *
72
- * @param {string} str - The input string.
73
- * @param {number} len - The maximum length.
74
- * @returns {string} The truncated string.
75
- */
76
- export function truncate(str, len) {
77
- return str.length > len ? str.slice(0, len) + '...' : str;
78
- }
79
- /**
80
- * Converts a string to PascalCase (e.g., "foo-bar" → "FooBar").
81
- *
82
- * @param {string} str - The input string.
83
- * @returns {string} The PascalCased string.
84
- */
85
- export function toPascalCase(str) {
86
- return capitalize(toCamelCase(str));
87
- }
88
- /**
89
- * Converts a string to snake_case (e.g., "FooBar test" → "foo_bar_test").
90
- *
91
- * @param {string} str - The input string.
92
- * @returns {string} The snake_cased string.
93
- */
94
- export function toSnakeCase(str) {
95
- return str
96
- .trim()
97
- .replace(/([a-z])([A-Z])/g, '$1_$2') // camelCase -> camel_Case
98
- .replace(/\s+/g, '_') // spaces to underscore
99
- .replace(/-+/g, '_') // dashes to underscore
100
- .toLowerCase();
101
- }
102
- /**
103
- * Masks a string by replacing characters with a mask character.
104
- * Useful for hiding sensitive information like credit cards or passwords.
105
- *
106
- * @param {string} str - The string to mask.
107
- * @param {number} [visibleStart=0] - Number of characters to show at start.
108
- * @param {number} [visibleEnd=0] - Number of characters to show at end.
109
- * @param {string} [maskChar="*"] - Character to use for masking.
110
- * @returns {string} The masked string.
111
- */
112
- export function mask(str, visibleStart = 0, visibleEnd = 0, maskChar = '*') {
113
- if (!str || str.length === 0)
114
- return '';
115
- if (visibleStart >= str.length)
116
- return str;
117
- const start = str.slice(0, visibleStart);
118
- const end = visibleEnd > 0 ? str.slice(-visibleEnd) : '';
119
- const masked = maskChar.repeat(Math.max(0, str.length - visibleStart - visibleEnd));
120
- return start + masked + end;
121
- }
122
- /**
123
- * Removes all HTML tags from a string.
124
- *
125
- * @param {string} str - The HTML string to process.
126
- * @returns {string} The string with HTML tags removed.
127
- */
128
- export function stripHtml(str) {
129
- return str.replace(/<[^>]*>/g, '');
130
- }
131
- /**
132
- * Performs case-insensitive string comparison.
133
- *
134
- * @param {string} a - First string.
135
- * @param {string} b - Second string.
136
- * @returns {boolean} True if the strings are equal ignoring case.
137
- */
138
- export function equalsIgnoreCase(a, b) {
139
- return a.toLowerCase() === b.toLowerCase();
140
- }
141
- /**
142
- * Reverses a string.
143
- *
144
- * @param {string} str - The string to reverse.
145
- * @returns {string} The reversed string.
146
- */
147
- export function reverse(str) {
148
- return str.split('').reverse().join('');
149
- }
150
- /**
151
- * Counts occurrences of a substring within a string.
152
- *
153
- * @param {string} str - The source string.
154
- * @param {string} substring - The substring to count.
155
- * @param {boolean} [caseSensitive=true] - Whether to perform case-sensitive counting.
156
- * @returns {number} Number of occurrences.
157
- */
158
- export function countOccurrences(str, substring, caseSensitive = true) {
159
- if (!caseSensitive) {
160
- str = str.toLowerCase();
161
- substring = substring.toLowerCase();
162
- }
163
- return str.split(substring).length - 1;
164
- }
165
- //# sourceMappingURL=string.utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"string.utils.js","sourceRoot":"","sources":["../../../src/utils/string.utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,GAAG;SACP,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,0BAA0B;SAC9D,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,iBAAiB;SACtC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,sBAAsB;SAC1C,WAAW,EAAE,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,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AAK,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACzC,CAAC","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Capitalizes the first character of a string.\n *\n * @param {string} str - The input string.\n * @returns {string} The string with the first character in uppercase.\n */\nexport function capitalize(str: string): string {\n return str.length === 0 ? '' : str.charAt(0).toUpperCase() + str.slice(1);\n}\n\n/**\n * Converts a string to kebab-case (e.g., \"FooBar test\" → \"foo-bar-test\").\n *\n * @param {string} str - The input string.\n * @returns {string} The kebab-cased string.\n */\nexport function toKebabCase(str: string): string {\n return str\n .replace(/([a-z])([A-Z])/g, '$1-$2') // camelCase -> camel-Case\n .replace(/\\s+/g, '-') // spaces to dash\n .replace(/_+/g, '-') // underscores to dash\n .toLowerCase();\n}\n\n/**\n * Converts a kebab-case or snake_case string to camelCase.\n *\n * @param {string} str - The input string.\n * @returns {string} The camelCased string.\n */\nexport function toCamelCase(str: string): string {\n return str.replace(/[-_](.)/g, (_, c: string) => c.toUpperCase());\n}\n\n/**\n * Converts a string to a URL-friendly slug (lowercase, dashes, alphanumeric).\n *\n * @param {string} str - The input string.\n * @returns {string} The slugified string.\n */\nexport function slugify(str: string): string {\n return str\n .toLowerCase()\n .replace(/[^\\w\\s-]/g, '') // remove non-word\n .replace(/\\s+/g, '-') // spaces to dash\n .replace(/-+/g, '-') // multiple dashes to one\n .replace(/^-+|-+$/g, ''); // trim leading/trailing dashes\n}\n\n/**\n * Truncates a string to a specific length, appending '...' if truncated.\n *\n * @param {string} str - The input string.\n * @param {number} len - The maximum length.\n * @returns {string} The truncated string.\n */\nexport function truncate(str: string, len: number): string {\n return str.length > len ? str.slice(0, len) + '...' : str;\n}\n\n/**\n * Converts a string to PascalCase (e.g., \"foo-bar\" → \"FooBar\").\n *\n * @param {string} str - The input string.\n * @returns {string} The PascalCased string.\n */\nexport function toPascalCase(str: string): string {\n return capitalize(toCamelCase(str));\n}\n\n/**\n * Converts a string to snake_case (e.g., \"FooBar test\" → \"foo_bar_test\").\n *\n * @param {string} str - The input string.\n * @returns {string} The snake_cased string.\n */\nexport function toSnakeCase(str: string): string {\n return str\n .trim()\n .replace(/([a-z])([A-Z])/g, '$1_$2') // camelCase -> camel_Case\n .replace(/\\s+/g, '_') // spaces to underscore\n .replace(/-+/g, '_') // dashes to underscore\n .toLowerCase();\n}\n\n/**\n * Masks a string by replacing characters with a mask character.\n * Useful for hiding sensitive information like credit cards or passwords.\n *\n * @param {string} str - The string to mask.\n * @param {number} [visibleStart=0] - Number of characters to show at start.\n * @param {number} [visibleEnd=0] - Number of characters to show at end.\n * @param {string} [maskChar=\"*\"] - Character to use for masking.\n * @returns {string} The masked string.\n */\nexport function mask(str: string, visibleStart: number = 0, visibleEnd: number = 0, maskChar: string = '*'): string {\n if (!str || str.length === 0) return '';\n if (visibleStart >= str.length) return str;\n\n const start = str.slice(0, visibleStart);\n const end = visibleEnd > 0 ? str.slice(-visibleEnd) : '';\n const masked = maskChar.repeat(Math.max(0, str.length - visibleStart - visibleEnd));\n\n return start + masked + end;\n}\n\n/**\n * Removes all HTML tags from a string.\n *\n * @param {string} str - The HTML string to process.\n * @returns {string} The string with HTML tags removed.\n */\nexport function stripHtml(str: string): string {\n return str.replace(/<[^>]*>/g, '');\n}\n\n/**\n * Performs case-insensitive string comparison.\n *\n * @param {string} a - First string.\n * @param {string} b - Second string.\n * @returns {boolean} True if the strings are equal ignoring case.\n */\nexport function equalsIgnoreCase(a: string, b: string): boolean {\n return a.toLowerCase() === b.toLowerCase();\n}\n\n/**\n * Reverses a string.\n *\n * @param {string} str - The string to reverse.\n * @returns {string} The reversed string.\n */\nexport function reverse(str: string): string {\n return str.split('').reverse().join('');\n}\n\n/**\n * Counts occurrences of a substring within a string.\n *\n * @param {string} str - The source string.\n * @param {string} substring - The substring to count.\n * @param {boolean} [caseSensitive=true] - Whether to perform case-sensitive counting.\n * @returns {number} Number of occurrences.\n */\nexport function countOccurrences(str: string, substring: string, caseSensitive: boolean = true): number {\n if (!caseSensitive) {\n str = str.toLowerCase();\n substring = substring.toLowerCase();\n }\n\n return str.split(substring).length - 1;\n}\n"]}