@catbee/utils 0.0.7 → 0.0.8-next.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 (285) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +26 -1
  3. package/build/index.cjs +6888 -0
  4. package/build/index.d.ts +5242 -0
  5. package/build/index.mjs +6615 -0
  6. package/package.json +26 -99
  7. package/build/esm/config.d.ts +0 -122
  8. package/build/esm/config.js +0 -133
  9. package/build/esm/config.js.map +0 -1
  10. package/build/esm/index.d.ts +0 -27
  11. package/build/esm/index.js +0 -50
  12. package/build/esm/index.js.map +0 -1
  13. package/build/esm/servers/server.builder.d.ts +0 -508
  14. package/build/esm/servers/server.builder.js +0 -702
  15. package/build/esm/servers/server.builder.js.map +0 -1
  16. package/build/esm/servers/server.d.ts +0 -256
  17. package/build/esm/servers/server.js +0 -1201
  18. package/build/esm/servers/server.js.map +0 -1
  19. package/build/esm/types/api-response.d.ts +0 -152
  20. package/build/esm/types/api-response.js +0 -34
  21. package/build/esm/types/api-response.js.map +0 -1
  22. package/build/esm/types/index.d.ts +0 -125
  23. package/build/esm/types/index.js +0 -25
  24. package/build/esm/types/index.js.map +0 -1
  25. package/build/esm/types/server.d.ts +0 -268
  26. package/build/esm/types/server.js +0 -25
  27. package/build/esm/types/server.js.map +0 -1
  28. package/build/esm/utils/array.utils.d.ts +0 -168
  29. package/build/esm/utils/array.utils.js +0 -382
  30. package/build/esm/utils/array.utils.js.map +0 -1
  31. package/build/esm/utils/async.utils.d.ts +0 -265
  32. package/build/esm/utils/async.utils.js +0 -896
  33. package/build/esm/utils/async.utils.js.map +0 -1
  34. package/build/esm/utils/cache.utils.d.ts +0 -153
  35. package/build/esm/utils/cache.utils.js +0 -499
  36. package/build/esm/utils/cache.utils.js.map +0 -1
  37. package/build/esm/utils/context-store.utils.d.ts +0 -189
  38. package/build/esm/utils/context-store.utils.js +0 -307
  39. package/build/esm/utils/context-store.utils.js.map +0 -1
  40. package/build/esm/utils/crypto.utils.d.ts +0 -160
  41. package/build/esm/utils/crypto.utils.js +0 -375
  42. package/build/esm/utils/crypto.utils.js.map +0 -1
  43. package/build/esm/utils/date.utils.d.ts +0 -159
  44. package/build/esm/utils/date.utils.js +0 -389
  45. package/build/esm/utils/date.utils.js.map +0 -1
  46. package/build/esm/utils/decorators.utils.d.ts +0 -315
  47. package/build/esm/utils/decorators.utils.js +0 -666
  48. package/build/esm/utils/decorators.utils.js.map +0 -1
  49. package/build/esm/utils/dir.utils.d.ts +0 -196
  50. package/build/esm/utils/dir.utils.js +0 -998
  51. package/build/esm/utils/dir.utils.js.map +0 -1
  52. package/build/esm/utils/env.utils.d.ts +0 -377
  53. package/build/esm/utils/env.utils.js +0 -873
  54. package/build/esm/utils/env.utils.js.map +0 -1
  55. package/build/esm/utils/exception.utils.d.ts +0 -230
  56. package/build/esm/utils/exception.utils.js +0 -559
  57. package/build/esm/utils/exception.utils.js.map +0 -1
  58. package/build/esm/utils/fs.utils.d.ts +0 -164
  59. package/build/esm/utils/fs.utils.js +0 -580
  60. package/build/esm/utils/fs.utils.js.map +0 -1
  61. package/build/esm/utils/http-status-codes.d.ts +0 -266
  62. package/build/esm/utils/http-status-codes.js +0 -295
  63. package/build/esm/utils/http-status-codes.js.map +0 -1
  64. package/build/esm/utils/id.utils.d.ts +0 -36
  65. package/build/esm/utils/id.utils.js +0 -87
  66. package/build/esm/utils/id.utils.js.map +0 -1
  67. package/build/esm/utils/logger.utils.d.ts +0 -160
  68. package/build/esm/utils/logger.utils.js +0 -341
  69. package/build/esm/utils/logger.utils.js.map +0 -1
  70. package/build/esm/utils/middleware.utils.d.ts +0 -83
  71. package/build/esm/utils/middleware.utils.js +0 -206
  72. package/build/esm/utils/middleware.utils.js.map +0 -1
  73. package/build/esm/utils/obj.utils.d.ts +0 -124
  74. package/build/esm/utils/obj.utils.js +0 -519
  75. package/build/esm/utils/obj.utils.js.map +0 -1
  76. package/build/esm/utils/performance.utils.d.ts +0 -136
  77. package/build/esm/utils/performance.utils.js +0 -376
  78. package/build/esm/utils/performance.utils.js.map +0 -1
  79. package/build/esm/utils/request.utils.d.ts +0 -86
  80. package/build/esm/utils/request.utils.js +0 -223
  81. package/build/esm/utils/request.utils.js.map +0 -1
  82. package/build/esm/utils/response.utils.d.ts +0 -163
  83. package/build/esm/utils/response.utils.js +0 -284
  84. package/build/esm/utils/response.utils.js.map +0 -1
  85. package/build/esm/utils/stream.utils.d.ts +0 -88
  86. package/build/esm/utils/stream.utils.js +0 -284
  87. package/build/esm/utils/stream.utils.js.map +0 -1
  88. package/build/esm/utils/string.utils.d.ts +0 -93
  89. package/build/esm/utils/string.utils.js +0 -169
  90. package/build/esm/utils/string.utils.js.map +0 -1
  91. package/build/esm/utils/type.utils.d.ts +0 -90
  92. package/build/esm/utils/type.utils.js +0 -190
  93. package/build/esm/utils/type.utils.js.map +0 -1
  94. package/build/esm/utils/url.utils.d.ts +0 -141
  95. package/build/esm/utils/url.utils.js +0 -381
  96. package/build/esm/utils/url.utils.js.map +0 -1
  97. package/build/esm/utils/validate.utils.d.ts +0 -177
  98. package/build/esm/utils/validate.utils.js +0 -336
  99. package/build/esm/utils/validate.utils.js.map +0 -1
  100. package/build/esnext/config.d.ts +0 -122
  101. package/build/esnext/config.js +0 -133
  102. package/build/esnext/config.js.map +0 -1
  103. package/build/esnext/index.d.ts +0 -27
  104. package/build/esnext/index.js +0 -50
  105. package/build/esnext/index.js.map +0 -1
  106. package/build/esnext/servers/server.builder.d.ts +0 -508
  107. package/build/esnext/servers/server.builder.js +0 -657
  108. package/build/esnext/servers/server.builder.js.map +0 -1
  109. package/build/esnext/servers/server.d.ts +0 -256
  110. package/build/esnext/servers/server.js +0 -908
  111. package/build/esnext/servers/server.js.map +0 -1
  112. package/build/esnext/types/api-response.d.ts +0 -152
  113. package/build/esnext/types/api-response.js +0 -34
  114. package/build/esnext/types/api-response.js.map +0 -1
  115. package/build/esnext/types/index.d.ts +0 -125
  116. package/build/esnext/types/index.js +0 -25
  117. package/build/esnext/types/index.js.map +0 -1
  118. package/build/esnext/types/server.d.ts +0 -268
  119. package/build/esnext/types/server.js +0 -25
  120. package/build/esnext/types/server.js.map +0 -1
  121. package/build/esnext/utils/array.utils.d.ts +0 -168
  122. package/build/esnext/utils/array.utils.js +0 -345
  123. package/build/esnext/utils/array.utils.js.map +0 -1
  124. package/build/esnext/utils/async.utils.d.ts +0 -265
  125. package/build/esnext/utils/async.utils.js +0 -620
  126. package/build/esnext/utils/async.utils.js.map +0 -1
  127. package/build/esnext/utils/cache.utils.d.ts +0 -153
  128. package/build/esnext/utils/cache.utils.js +0 -293
  129. package/build/esnext/utils/cache.utils.js.map +0 -1
  130. package/build/esnext/utils/context-store.utils.d.ts +0 -189
  131. package/build/esnext/utils/context-store.utils.js +0 -289
  132. package/build/esnext/utils/context-store.utils.js.map +0 -1
  133. package/build/esnext/utils/crypto.utils.d.ts +0 -160
  134. package/build/esnext/utils/crypto.utils.js +0 -276
  135. package/build/esnext/utils/crypto.utils.js.map +0 -1
  136. package/build/esnext/utils/date.utils.d.ts +0 -159
  137. package/build/esnext/utils/date.utils.js +0 -384
  138. package/build/esnext/utils/date.utils.js.map +0 -1
  139. package/build/esnext/utils/decorators.utils.d.ts +0 -315
  140. package/build/esnext/utils/decorators.utils.js +0 -504
  141. package/build/esnext/utils/decorators.utils.js.map +0 -1
  142. package/build/esnext/utils/dir.utils.d.ts +0 -196
  143. package/build/esnext/utils/dir.utils.js +0 -477
  144. package/build/esnext/utils/dir.utils.js.map +0 -1
  145. package/build/esnext/utils/env.utils.d.ts +0 -377
  146. package/build/esnext/utils/env.utils.js +0 -785
  147. package/build/esnext/utils/env.utils.js.map +0 -1
  148. package/build/esnext/utils/exception.utils.d.ts +0 -230
  149. package/build/esnext/utils/exception.utils.js +0 -381
  150. package/build/esnext/utils/exception.utils.js.map +0 -1
  151. package/build/esnext/utils/fs.utils.d.ts +0 -164
  152. package/build/esnext/utils/fs.utils.js +0 -349
  153. package/build/esnext/utils/fs.utils.js.map +0 -1
  154. package/build/esnext/utils/http-status-codes.d.ts +0 -266
  155. package/build/esnext/utils/http-status-codes.js +0 -295
  156. package/build/esnext/utils/http-status-codes.js.map +0 -1
  157. package/build/esnext/utils/id.utils.d.ts +0 -36
  158. package/build/esnext/utils/id.utils.js +0 -84
  159. package/build/esnext/utils/id.utils.js.map +0 -1
  160. package/build/esnext/utils/logger.utils.d.ts +0 -160
  161. package/build/esnext/utils/logger.utils.js +0 -300
  162. package/build/esnext/utils/logger.utils.js.map +0 -1
  163. package/build/esnext/utils/middleware.utils.d.ts +0 -83
  164. package/build/esnext/utils/middleware.utils.js +0 -199
  165. package/build/esnext/utils/middleware.utils.js.map +0 -1
  166. package/build/esnext/utils/obj.utils.d.ts +0 -124
  167. package/build/esnext/utils/obj.utils.js +0 -413
  168. package/build/esnext/utils/obj.utils.js.map +0 -1
  169. package/build/esnext/utils/performance.utils.d.ts +0 -136
  170. package/build/esnext/utils/performance.utils.js +0 -271
  171. package/build/esnext/utils/performance.utils.js.map +0 -1
  172. package/build/esnext/utils/request.utils.d.ts +0 -86
  173. package/build/esnext/utils/request.utils.js +0 -186
  174. package/build/esnext/utils/request.utils.js.map +0 -1
  175. package/build/esnext/utils/response.utils.d.ts +0 -163
  176. package/build/esnext/utils/response.utils.js +0 -247
  177. package/build/esnext/utils/response.utils.js.map +0 -1
  178. package/build/esnext/utils/stream.utils.d.ts +0 -88
  179. package/build/esnext/utils/stream.utils.js +0 -210
  180. package/build/esnext/utils/stream.utils.js.map +0 -1
  181. package/build/esnext/utils/string.utils.d.ts +0 -93
  182. package/build/esnext/utils/string.utils.js +0 -165
  183. package/build/esnext/utils/string.utils.js.map +0 -1
  184. package/build/esnext/utils/type.utils.d.ts +0 -90
  185. package/build/esnext/utils/type.utils.js +0 -187
  186. package/build/esnext/utils/type.utils.js.map +0 -1
  187. package/build/esnext/utils/url.utils.d.ts +0 -141
  188. package/build/esnext/utils/url.utils.js +0 -304
  189. package/build/esnext/utils/url.utils.js.map +0 -1
  190. package/build/esnext/utils/validate.utils.d.ts +0 -177
  191. package/build/esnext/utils/validate.utils.js +0 -320
  192. package/build/esnext/utils/validate.utils.js.map +0 -1
  193. package/build/src/config.d.ts +0 -122
  194. package/build/src/config.js +0 -138
  195. package/build/src/config.js.map +0 -1
  196. package/build/src/index.d.ts +0 -27
  197. package/build/src/index.js +0 -69
  198. package/build/src/index.js.map +0 -1
  199. package/build/src/servers/server.builder.d.ts +0 -508
  200. package/build/src/servers/server.builder.js +0 -661
  201. package/build/src/servers/server.builder.js.map +0 -1
  202. package/build/src/servers/server.d.ts +0 -256
  203. package/build/src/servers/server.js +0 -948
  204. package/build/src/servers/server.js.map +0 -1
  205. package/build/src/types/api-response.d.ts +0 -152
  206. package/build/src/types/api-response.js +0 -37
  207. package/build/src/types/api-response.js.map +0 -1
  208. package/build/src/types/index.d.ts +0 -125
  209. package/build/src/types/index.js +0 -26
  210. package/build/src/types/index.js.map +0 -1
  211. package/build/src/types/server.d.ts +0 -268
  212. package/build/src/types/server.js +0 -26
  213. package/build/src/types/server.js.map +0 -1
  214. package/build/src/utils/array.utils.d.ts +0 -168
  215. package/build/src/utils/array.utils.js +0 -364
  216. package/build/src/utils/array.utils.js.map +0 -1
  217. package/build/src/utils/async.utils.d.ts +0 -265
  218. package/build/src/utils/async.utils.js +0 -641
  219. package/build/src/utils/async.utils.js.map +0 -1
  220. package/build/src/utils/cache.utils.d.ts +0 -153
  221. package/build/src/utils/cache.utils.js +0 -297
  222. package/build/src/utils/cache.utils.js.map +0 -1
  223. package/build/src/utils/context-store.utils.d.ts +0 -189
  224. package/build/src/utils/context-store.utils.js +0 -296
  225. package/build/src/utils/context-store.utils.js.map +0 -1
  226. package/build/src/utils/crypto.utils.d.ts +0 -160
  227. package/build/src/utils/crypto.utils.js +0 -293
  228. package/build/src/utils/crypto.utils.js.map +0 -1
  229. package/build/src/utils/date.utils.d.ts +0 -159
  230. package/build/src/utils/date.utils.js +0 -396
  231. package/build/src/utils/date.utils.js.map +0 -1
  232. package/build/src/utils/decorators.utils.d.ts +0 -315
  233. package/build/src/utils/decorators.utils.js +0 -516
  234. package/build/src/utils/decorators.utils.js.map +0 -1
  235. package/build/src/utils/dir.utils.d.ts +0 -196
  236. package/build/src/utils/dir.utils.js +0 -501
  237. package/build/src/utils/dir.utils.js.map +0 -1
  238. package/build/src/utils/env.utils.d.ts +0 -377
  239. package/build/src/utils/env.utils.js +0 -789
  240. package/build/src/utils/env.utils.js.map +0 -1
  241. package/build/src/utils/exception.utils.d.ts +0 -230
  242. package/build/src/utils/exception.utils.js +0 -407
  243. package/build/src/utils/exception.utils.js.map +0 -1
  244. package/build/src/utils/fs.utils.d.ts +0 -164
  245. package/build/src/utils/fs.utils.js +0 -372
  246. package/build/src/utils/fs.utils.js.map +0 -1
  247. package/build/src/utils/http-status-codes.d.ts +0 -266
  248. package/build/src/utils/http-status-codes.js +0 -298
  249. package/build/src/utils/http-status-codes.js.map +0 -1
  250. package/build/src/utils/id.utils.d.ts +0 -36
  251. package/build/src/utils/id.utils.js +0 -91
  252. package/build/src/utils/id.utils.js.map +0 -1
  253. package/build/src/utils/logger.utils.d.ts +0 -160
  254. package/build/src/utils/logger.utils.js +0 -346
  255. package/build/src/utils/logger.utils.js.map +0 -1
  256. package/build/src/utils/middleware.utils.d.ts +0 -83
  257. package/build/src/utils/middleware.utils.js +0 -206
  258. package/build/src/utils/middleware.utils.js.map +0 -1
  259. package/build/src/utils/obj.utils.d.ts +0 -124
  260. package/build/src/utils/obj.utils.js +0 -429
  261. package/build/src/utils/obj.utils.js.map +0 -1
  262. package/build/src/utils/performance.utils.d.ts +0 -136
  263. package/build/src/utils/performance.utils.js +0 -278
  264. package/build/src/utils/performance.utils.js.map +0 -1
  265. package/build/src/utils/request.utils.d.ts +0 -86
  266. package/build/src/utils/request.utils.js +0 -195
  267. package/build/src/utils/request.utils.js.map +0 -1
  268. package/build/src/utils/response.utils.d.ts +0 -163
  269. package/build/src/utils/response.utils.js +0 -260
  270. package/build/src/utils/response.utils.js.map +0 -1
  271. package/build/src/utils/stream.utils.d.ts +0 -88
  272. package/build/src/utils/stream.utils.js +0 -218
  273. package/build/src/utils/stream.utils.js.map +0 -1
  274. package/build/src/utils/string.utils.d.ts +0 -93
  275. package/build/src/utils/string.utils.js +0 -179
  276. package/build/src/utils/string.utils.js.map +0 -1
  277. package/build/src/utils/type.utils.d.ts +0 -90
  278. package/build/src/utils/type.utils.js +0 -196
  279. package/build/src/utils/type.utils.js.map +0 -1
  280. package/build/src/utils/url.utils.d.ts +0 -141
  281. package/build/src/utils/url.utils.js +0 -317
  282. package/build/src/utils/url.utils.js.map +0 -1
  283. package/build/src/utils/validate.utils.d.ts +0 -177
  284. package/build/src/utils/validate.utils.js +0 -345
  285. package/build/src/utils/validate.utils.js.map +0 -1
@@ -1,284 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
32
- };
33
- var __generator = (this && this.__generator) || function (thisArg, body) {
34
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
35
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
36
- function verb(n) { return function (v) { return step([n, v]); }; }
37
- function step(op) {
38
- if (f) throw new TypeError("Generator is already executing.");
39
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
40
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
41
- if (y = 0, t) op = [op[0] & 2, t.value];
42
- switch (op[0]) {
43
- case 0: case 1: t = op; break;
44
- case 4: _.label++; return { value: op[1], done: false };
45
- case 5: _.label++; y = op[1]; op = [0]; continue;
46
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
47
- default:
48
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
49
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
50
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
51
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
52
- if (t[2]) _.ops.pop();
53
- _.trys.pop(); continue;
54
- }
55
- op = body.call(thisArg, _);
56
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
57
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
58
- }
59
- };
60
- var __values = (this && this.__values) || function(o) {
61
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
62
- if (m) return m.call(o);
63
- if (o && typeof o.length === "number") return {
64
- next: function () {
65
- if (o && i >= o.length) o = void 0;
66
- return { value: o && o[i++], done: !o };
67
- }
68
- };
69
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
70
- };
71
- import { Readable, Transform } from 'stream';
72
- /**
73
- * Convert a buffer or string to a readable stream.
74
- *
75
- * @param data - Buffer or string to convert
76
- * @returns Readable stream containing the data
77
- *
78
- * @example
79
- * ```typescript
80
- * const stream = bufferToStream(Buffer.from('Hello world'));
81
- * // or
82
- * const stream = bufferToStream('Hello world');
83
- * ```
84
- */
85
- export function bufferToStream(data) {
86
- var readable = new Readable();
87
- readable.push(data);
88
- readable.push(null); // End of stream
89
- return readable;
90
- }
91
- /**
92
- * Convert a readable stream to a buffer.
93
- *
94
- * @param stream - Readable stream to convert
95
- * @returns Promise resolving to a buffer containing all stream data
96
- *
97
- * @example
98
- * ```typescript
99
- * const buffer = await streamToBuffer(fs.createReadStream('file.txt'));
100
- * console.log(buffer.toString()); // Contents of file.txt
101
- * ```
102
- */
103
- export function streamToBuffer(stream) {
104
- return __awaiter(this, void 0, void 0, function () {
105
- return __generator(this, function (_a) {
106
- return [2 /*return*/, new Promise(function (resolve, reject) {
107
- var chunks = [];
108
- stream.on('data', function (chunk) { return chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)); });
109
- stream.on('end', function () { return resolve(Buffer.concat(chunks)); });
110
- stream.on('error', reject);
111
- })];
112
- });
113
- });
114
- }
115
- /**
116
- * Convert a readable stream to a string.
117
- *
118
- * @param stream - Readable stream to convert
119
- * @param encoding - Character encoding (default: 'utf8')
120
- * @returns Promise resolving to a string containing all stream data
121
- *
122
- * @example
123
- * ```typescript
124
- * const content = await streamToString(fs.createReadStream('file.txt'));
125
- * console.log(content); // Contents of file.txt as string
126
- * ```
127
- */
128
- export function streamToString(stream_1) {
129
- return __awaiter(this, arguments, void 0, function (stream, encoding) {
130
- var buffer;
131
- if (encoding === void 0) { encoding = 'utf8'; }
132
- return __generator(this, function (_a) {
133
- switch (_a.label) {
134
- case 0: return [4 /*yield*/, streamToBuffer(stream)];
135
- case 1:
136
- buffer = _a.sent();
137
- return [2 /*return*/, buffer.toString(encoding)];
138
- }
139
- });
140
- });
141
- }
142
- /**
143
- * Create a transform stream that limits the rate of data flow.
144
- *
145
- * @param bytesPerSecond - Maximum bytes per second
146
- * @returns Transform stream that throttles data flow
147
- */
148
- export function createThrottleStream(bytesPerSecond) {
149
- var bytesSent = 0;
150
- var startTime = Date.now();
151
- return new Transform({
152
- transform: function (chunk, _encoding, callback) {
153
- var elapsedSeconds = (Date.now() - startTime) / 1000;
154
- var targetBytes = bytesPerSecond * elapsedSeconds;
155
- var chunkSize = chunk.length;
156
- // If we've sent fewer bytes than our target, just send the chunk
157
- if (bytesSent + chunkSize <= targetBytes) {
158
- bytesSent += chunkSize;
159
- callback(null, chunk);
160
- return;
161
- }
162
- // Otherwise we need to throttle
163
- var delay = ((bytesSent + chunkSize) / bytesPerSecond - elapsedSeconds) * 1000;
164
- setTimeout(function () {
165
- bytesSent += chunkSize;
166
- callback(null, chunk);
167
- }, delay);
168
- }
169
- });
170
- }
171
- /**
172
- * Create a transform stream that batches data into chunks of specified size.
173
- *
174
- * @param size - Size of each batch (items for object mode, bytes for binary mode)
175
- * @param options - Stream options
176
- * @returns Transform stream that batches data
177
- *
178
- * @example
179
- * ```typescript
180
- * // Batch lines from a file into arrays of 100 lines each
181
- * createReadStream('large-file.txt')
182
- * .pipe(createLineStream())
183
- * .pipe(createBatchStream(100))
184
- * .on('data', batch => console.log(`Processing batch of ${batch.length} lines`));
185
- * ```
186
- */
187
- export function createBatchStream(size, options) {
188
- if (options === void 0) { options = {}; }
189
- var objectMode = options.objectMode !== false;
190
- var batch = [];
191
- var buffers = [];
192
- var bufferSize = 0;
193
- return new Transform({
194
- objectMode: objectMode,
195
- transform: function (chunk, _encoding, callback) {
196
- if (objectMode) {
197
- batch.push(chunk);
198
- if (batch.length >= size) {
199
- this.push(batch);
200
- batch = [];
201
- }
202
- }
203
- else {
204
- var buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
205
- buffers.push(buffer);
206
- bufferSize += buffer.length;
207
- // Emit batches of exact size
208
- var combined = Buffer.concat(buffers, bufferSize);
209
- while (combined.length >= size) {
210
- this.push(combined.slice(0, size));
211
- combined = combined.slice(size);
212
- }
213
- buffers = combined.length > 0 ? [combined] : [];
214
- bufferSize = combined.length;
215
- }
216
- callback();
217
- },
218
- flush: function (callback) {
219
- if (objectMode && batch.length > 0) {
220
- this.push(batch);
221
- }
222
- else if (!objectMode && buffers.length > 0 && bufferSize > 0) {
223
- var combined = Buffer.concat(buffers, bufferSize);
224
- while (combined.length >= size) {
225
- this.push(combined.slice(0, size));
226
- combined = combined.slice(size);
227
- }
228
- if (combined.length > 0) {
229
- this.push(combined);
230
- }
231
- }
232
- callback();
233
- }
234
- });
235
- }
236
- /**
237
- * Create a transform stream that splits text data by newlines.
238
- *
239
- * @param options - Options for the line stream
240
- * @returns Transform stream that emits lines
241
- *
242
- * @example
243
- * ```typescript
244
- * // Process a file line by line
245
- * createReadStream('file.txt')
246
- * .pipe(createLineStream())
247
- * .on('data', line => console.log(`Line: ${line}`));
248
- * ```
249
- */
250
- export function createLineStream(options) {
251
- if (options === void 0) { options = {}; }
252
- var _a = options.encoding, encoding = _a === void 0 ? 'utf8' : _a, _b = options.includeNewlines, includeNewlines = _b === void 0 ? false : _b;
253
- var buffer = '';
254
- return new Transform({
255
- objectMode: true,
256
- transform: function (chunk, _encoding, callback) {
257
- var e_1, _a;
258
- var str = buffer + (Buffer.isBuffer(chunk) ? chunk.toString(encoding) : chunk);
259
- var lines = str.split(/\r?\n/);
260
- buffer = lines.pop() || '';
261
- try {
262
- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
263
- var line = lines_1_1.value;
264
- this.push(includeNewlines ? line + '\n' : line);
265
- }
266
- }
267
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
268
- finally {
269
- try {
270
- if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
271
- }
272
- finally { if (e_1) throw e_1.error; }
273
- }
274
- callback();
275
- },
276
- flush: function (callback) {
277
- if (buffer) {
278
- this.push(buffer);
279
- }
280
- callback();
281
- }
282
- });
283
- }
284
- //# 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,CAAC;AAGhE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAAC,IAAqB;IAClD,IAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB;IACrC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAgB,cAAc,CAAC,MAAgB;;;YACnD,sBAAO,IAAI,OAAO,CAAS,UAAC,OAAO,EAAE,MAAM;oBACzC,IAAM,MAAM,GAAa,EAAE,CAAC;oBAC5B,MAAM,CAAC,EAAE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ACb,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAGM;IAHN,wBAAA,EAAA,YAGM;IAEE,IAAA,KAA+C,OAAO,SAArC,EAAjB,QAAQ,mBAAG,MAAM,KAAA,EAAE,KAA4B,OAAO,gBAAZ,EAAvB,eAAe,mBAAG,KAAK,KAAA,CAAa;IAC/D,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,OAAO,IAAI,SAAS,CAAC;QACnB,UAAU,EAAE,IAAI;QAChB,SAAS,YAAC,KAAK,EAAE,SAAS,EAAE,QAAQ;;YAClC,IAAM,GAAG,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACjF,IAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACjC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;;gBAE3B,KAAmB,IAAA,UAAA,SAAA,KAAK,CAAA,4BAAA,+CAAE,CAAC;oBAAtB,IAAM,IAAI,kBAAA;oBACb,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAClD,CAAC;;;;;;;;;YAED,QAAQ,EAAE,CAAC;QACb,CAAC;QAED,KAAK,YAAC,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\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,169 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies
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, function (_, c) { return 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, visibleEnd, maskChar) {
113
- if (visibleStart === void 0) { visibleStart = 0; }
114
- if (visibleEnd === void 0) { visibleEnd = 0; }
115
- if (maskChar === void 0) { maskChar = '*'; }
116
- if (!str || str.length === 0)
117
- return '';
118
- if (visibleStart >= str.length)
119
- return str;
120
- var start = str.slice(0, visibleStart);
121
- var end = visibleEnd > 0 ? str.slice(-visibleEnd) : '';
122
- var masked = maskChar.repeat(Math.max(0, str.length - visibleStart - visibleEnd));
123
- return start + masked + end;
124
- }
125
- /**
126
- * Removes all HTML tags from a string.
127
- *
128
- * @param {string} str - The HTML string to process.
129
- * @returns {string} The string with HTML tags removed.
130
- */
131
- export function stripHtml(str) {
132
- return str.replace(/<[^>]*>/g, '');
133
- }
134
- /**
135
- * Performs case-insensitive string comparison.
136
- *
137
- * @param {string} a - First string.
138
- * @param {string} b - Second string.
139
- * @returns {boolean} True if the strings are equal ignoring case.
140
- */
141
- export function equalsIgnoreCase(a, b) {
142
- return a.toLowerCase() === b.toLowerCase();
143
- }
144
- /**
145
- * Reverses a string.
146
- *
147
- * @param {string} str - The string to reverse.
148
- * @returns {string} The reversed string.
149
- */
150
- export function reverse(str) {
151
- return str.split('').reverse().join('');
152
- }
153
- /**
154
- * Counts occurrences of a substring within a string.
155
- *
156
- * @param {string} str - The source string.
157
- * @param {string} substring - The substring to count.
158
- * @param {boolean} [caseSensitive=true] - Whether to perform case-sensitive counting.
159
- * @returns {number} Number of occurrences.
160
- */
161
- export function countOccurrences(str, substring, caseSensitive) {
162
- if (caseSensitive === void 0) { caseSensitive = true; }
163
- if (!caseSensitive) {
164
- str = str.toLowerCase();
165
- substring = substring.toLowerCase();
166
- }
167
- return str.split(substring).length - 1;
168
- }
169
- //# 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,EAAE,UAAC,CAAC,EAAE,CAAS,IAAK,OAAA,CAAC,CAAC,WAAW,EAAE,EAAf,CAAe,CAAC,CAAC;AACpE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,GAAW;IACjC,OAAO,GAAG;SACP,WAAW,EAAE;SACb,OAAO,CAAC,WA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ies\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"]}