@catbee/utils 0.0.1 → 0.0.3

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 (197) hide show
  1. package/README.md +303 -107
  2. package/build/esm/config.d.ts +13 -1
  3. package/build/esm/config.js +16 -4
  4. package/build/esm/config.js.map +1 -1
  5. package/build/esm/index.d.ts +20 -18
  6. package/build/esm/index.js +20 -18
  7. package/build/esm/index.js.map +1 -1
  8. package/build/esm/types/api-response.d.ts +83 -1
  9. package/build/esm/types/api-response.js.map +1 -1
  10. package/build/esm/utils/array.utils.d.ts +65 -2
  11. package/build/esm/utils/array.utils.js +147 -20
  12. package/build/esm/utils/array.utils.js.map +1 -1
  13. package/build/esm/utils/async.utils.d.ts +56 -1
  14. package/build/esm/utils/async.utils.js +166 -11
  15. package/build/esm/utils/async.utils.js.map +1 -1
  16. package/build/esm/utils/cache.utils.d.ts +67 -4
  17. package/build/esm/utils/cache.utils.js +210 -28
  18. package/build/esm/utils/cache.utils.js.map +1 -1
  19. package/build/esm/utils/context-store.utils.d.ts +102 -1
  20. package/build/esm/utils/context-store.utils.js +185 -3
  21. package/build/esm/utils/context-store.utils.js.map +1 -1
  22. package/build/esm/utils/crypto.utils.d.ts +110 -8
  23. package/build/esm/utils/crypto.utils.js +298 -23
  24. package/build/esm/utils/crypto.utils.js.map +1 -1
  25. package/build/esm/utils/decorators.utils.d.ts +40 -0
  26. package/build/esm/utils/decorators.utils.js +312 -0
  27. package/build/esm/utils/decorators.utils.js.map +1 -0
  28. package/build/esm/utils/dir.utils.d.ts +122 -1
  29. package/build/esm/utils/dir.utils.js +578 -3
  30. package/build/esm/utils/dir.utils.js.map +1 -1
  31. package/build/esm/utils/env.utils.d.ts +83 -0
  32. package/build/esm/utils/env.utils.js +235 -6
  33. package/build/esm/utils/env.utils.js.map +1 -1
  34. package/build/esm/utils/exception.utils.d.ts +117 -1
  35. package/build/esm/utils/exception.utils.js +331 -12
  36. package/build/esm/utils/exception.utils.js.map +1 -1
  37. package/build/esm/utils/fs.utils.d.ts +132 -0
  38. package/build/esm/utils/fs.utils.js +421 -4
  39. package/build/esm/utils/fs.utils.js.map +1 -1
  40. package/build/esm/utils/http-status-codes.d.ts +87 -178
  41. package/build/esm/utils/http-status-codes.js +92 -178
  42. package/build/esm/utils/http-status-codes.js.map +1 -1
  43. package/build/esm/utils/id.utils.d.ts +11 -10
  44. package/build/esm/utils/id.utils.js +30 -21
  45. package/build/esm/utils/id.utils.js.map +1 -1
  46. package/build/esm/utils/logger.utils.d.ts +35 -2
  47. package/build/esm/utils/logger.utils.js +68 -14
  48. package/build/esm/utils/logger.utils.js.map +1 -1
  49. package/build/esm/utils/middleware.utils.d.ts +73 -0
  50. package/build/esm/utils/middleware.utils.js +158 -0
  51. package/build/esm/utils/middleware.utils.js.map +1 -0
  52. package/build/esm/utils/obj.utils.d.ts +65 -3
  53. package/build/esm/utils/obj.utils.js +206 -18
  54. package/build/esm/utils/obj.utils.js.map +1 -1
  55. package/build/esm/utils/response.utils.d.ts +103 -2
  56. package/build/esm/utils/response.utils.js +156 -3
  57. package/build/esm/utils/response.utils.js.map +1 -1
  58. package/build/esm/utils/string.utils.d.ts +61 -5
  59. package/build/esm/utils/string.utils.js +109 -19
  60. package/build/esm/utils/string.utils.js.map +1 -1
  61. package/build/esm/utils/url.utils.d.ts +117 -0
  62. package/build/esm/utils/url.utils.js +287 -2
  63. package/build/esm/utils/url.utils.js.map +1 -1
  64. package/build/esm/utils/validate.utils.d.ts +110 -0
  65. package/build/esm/utils/validate.utils.js +190 -8
  66. package/build/esm/utils/validate.utils.js.map +1 -1
  67. package/build/esnext/config.d.ts +13 -1
  68. package/build/esnext/config.js +16 -4
  69. package/build/esnext/config.js.map +1 -1
  70. package/build/esnext/index.d.ts +20 -18
  71. package/build/esnext/index.js +20 -18
  72. package/build/esnext/index.js.map +1 -1
  73. package/build/esnext/types/api-response.d.ts +83 -1
  74. package/build/esnext/types/api-response.js.map +1 -1
  75. package/build/esnext/utils/array.utils.d.ts +65 -2
  76. package/build/esnext/utils/array.utils.js +140 -21
  77. package/build/esnext/utils/array.utils.js.map +1 -1
  78. package/build/esnext/utils/async.utils.d.ts +56 -1
  79. package/build/esnext/utils/async.utils.js +130 -14
  80. package/build/esnext/utils/async.utils.js.map +1 -1
  81. package/build/esnext/utils/cache.utils.d.ts +67 -4
  82. package/build/esnext/utils/cache.utils.js +137 -9
  83. package/build/esnext/utils/cache.utils.js.map +1 -1
  84. package/build/esnext/utils/context-store.utils.d.ts +102 -1
  85. package/build/esnext/utils/context-store.utils.js +171 -3
  86. package/build/esnext/utils/context-store.utils.js.map +1 -1
  87. package/build/esnext/utils/crypto.utils.d.ts +110 -8
  88. package/build/esnext/utils/crypto.utils.js +199 -19
  89. package/build/esnext/utils/crypto.utils.js.map +1 -1
  90. package/build/esnext/utils/decorators.utils.d.ts +40 -0
  91. package/build/esnext/utils/decorators.utils.js +155 -0
  92. package/build/esnext/utils/decorators.utils.js.map +1 -0
  93. package/build/esnext/utils/dir.utils.d.ts +122 -1
  94. package/build/esnext/utils/dir.utils.js +307 -3
  95. package/build/esnext/utils/dir.utils.js.map +1 -1
  96. package/build/esnext/utils/env.utils.d.ts +83 -0
  97. package/build/esnext/utils/env.utils.js +191 -8
  98. package/build/esnext/utils/env.utils.js.map +1 -1
  99. package/build/esnext/utils/exception.utils.d.ts +117 -1
  100. package/build/esnext/utils/exception.utils.js +222 -12
  101. package/build/esnext/utils/exception.utils.js.map +1 -1
  102. package/build/esnext/utils/fs.utils.d.ts +132 -0
  103. package/build/esnext/utils/fs.utils.js +268 -4
  104. package/build/esnext/utils/fs.utils.js.map +1 -1
  105. package/build/esnext/utils/http-status-codes.d.ts +87 -178
  106. package/build/esnext/utils/http-status-codes.js +92 -178
  107. package/build/esnext/utils/http-status-codes.js.map +1 -1
  108. package/build/esnext/utils/id.utils.d.ts +11 -10
  109. package/build/esnext/utils/id.utils.js +28 -20
  110. package/build/esnext/utils/id.utils.js.map +1 -1
  111. package/build/esnext/utils/logger.utils.d.ts +35 -2
  112. package/build/esnext/utils/logger.utils.js +56 -14
  113. package/build/esnext/utils/logger.utils.js.map +1 -1
  114. package/build/esnext/utils/middleware.utils.d.ts +73 -0
  115. package/build/esnext/utils/middleware.utils.js +157 -0
  116. package/build/esnext/utils/middleware.utils.js.map +1 -0
  117. package/build/esnext/utils/obj.utils.d.ts +65 -3
  118. package/build/esnext/utils/obj.utils.js +169 -14
  119. package/build/esnext/utils/obj.utils.js.map +1 -1
  120. package/build/esnext/utils/response.utils.d.ts +103 -2
  121. package/build/esnext/utils/response.utils.js +141 -3
  122. package/build/esnext/utils/response.utils.js.map +1 -1
  123. package/build/esnext/utils/string.utils.d.ts +61 -5
  124. package/build/esnext/utils/string.utils.js +110 -14
  125. package/build/esnext/utils/string.utils.js.map +1 -1
  126. package/build/esnext/utils/url.utils.d.ts +117 -0
  127. package/build/esnext/utils/url.utils.js +248 -2
  128. package/build/esnext/utils/url.utils.js.map +1 -1
  129. package/build/esnext/utils/validate.utils.d.ts +110 -0
  130. package/build/esnext/utils/validate.utils.js +190 -8
  131. package/build/esnext/utils/validate.utils.js.map +1 -1
  132. package/build/src/config.d.ts +13 -1
  133. package/build/src/config.js +15 -3
  134. package/build/src/config.js.map +1 -1
  135. package/build/src/index.d.ts +20 -18
  136. package/build/src/index.js +2 -0
  137. package/build/src/index.js.map +1 -1
  138. package/build/src/types/api-response.d.ts +83 -1
  139. package/build/src/types/api-response.js.map +1 -1
  140. package/build/src/utils/array.utils.d.ts +65 -2
  141. package/build/src/utils/array.utils.js +147 -22
  142. package/build/src/utils/array.utils.js.map +1 -1
  143. package/build/src/utils/async.utils.d.ts +56 -1
  144. package/build/src/utils/async.utils.js +137 -17
  145. package/build/src/utils/async.utils.js.map +1 -1
  146. package/build/src/utils/cache.utils.d.ts +67 -4
  147. package/build/src/utils/cache.utils.js +137 -9
  148. package/build/src/utils/cache.utils.js.map +1 -1
  149. package/build/src/utils/context-store.utils.d.ts +102 -1
  150. package/build/src/utils/context-store.utils.js +173 -3
  151. package/build/src/utils/context-store.utils.js.map +1 -1
  152. package/build/src/utils/crypto.utils.d.ts +110 -8
  153. package/build/src/utils/crypto.utils.js +214 -27
  154. package/build/src/utils/crypto.utils.js.map +1 -1
  155. package/build/src/utils/decorators.utils.d.ts +40 -0
  156. package/build/src/utils/decorators.utils.js +165 -0
  157. package/build/src/utils/decorators.utils.js.map +1 -0
  158. package/build/src/utils/dir.utils.d.ts +122 -1
  159. package/build/src/utils/dir.utils.js +314 -0
  160. package/build/src/utils/dir.utils.js.map +1 -1
  161. package/build/src/utils/env.utils.d.ts +83 -0
  162. package/build/src/utils/env.utils.js +192 -9
  163. package/build/src/utils/env.utils.js.map +1 -1
  164. package/build/src/utils/exception.utils.d.ts +117 -1
  165. package/build/src/utils/exception.utils.js +233 -11
  166. package/build/src/utils/exception.utils.js.map +1 -1
  167. package/build/src/utils/fs.utils.d.ts +132 -0
  168. package/build/src/utils/fs.utils.js +281 -3
  169. package/build/src/utils/fs.utils.js.map +1 -1
  170. package/build/src/utils/http-status-codes.d.ts +87 -178
  171. package/build/src/utils/http-status-codes.js +92 -178
  172. package/build/src/utils/http-status-codes.js.map +1 -1
  173. package/build/src/utils/id.utils.d.ts +11 -10
  174. package/build/src/utils/id.utils.js +28 -20
  175. package/build/src/utils/id.utils.js.map +1 -1
  176. package/build/src/utils/logger.utils.d.ts +35 -2
  177. package/build/src/utils/logger.utils.js +56 -11
  178. package/build/src/utils/logger.utils.js.map +1 -1
  179. package/build/src/utils/middleware.utils.d.ts +73 -0
  180. package/build/src/utils/middleware.utils.js +163 -0
  181. package/build/src/utils/middleware.utils.js.map +1 -0
  182. package/build/src/utils/obj.utils.d.ts +65 -3
  183. package/build/src/utils/obj.utils.js +179 -18
  184. package/build/src/utils/obj.utils.js.map +1 -1
  185. package/build/src/utils/response.utils.d.ts +103 -2
  186. package/build/src/utils/response.utils.js +147 -2
  187. package/build/src/utils/response.utils.js.map +1 -1
  188. package/build/src/utils/string.utils.d.ts +61 -5
  189. package/build/src/utils/string.utils.js +122 -20
  190. package/build/src/utils/string.utils.js.map +1 -1
  191. package/build/src/utils/url.utils.d.ts +117 -0
  192. package/build/src/utils/url.utils.js +256 -1
  193. package/build/src/utils/url.utils.js.map +1 -1
  194. package/build/src/utils/validate.utils.d.ts +110 -0
  195. package/build/src/utils/validate.utils.js +204 -8
  196. package/build/src/utils/validate.utils.js.map +1 -1
  197. package/package.json +20 -12
@@ -1 +1 @@
1
- {"version":3,"file":"response.utils.js","sourceRoot":"","sources":["../../../src/utils/response.utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD;;;;;GAKG;AACH;IAgBE;;;;;OAKG;IACH,yBAAY,OAAe,EAAE,IAAQ;;QArBrC,sDAAsD;QACtD,YAAO,GAAW,SAAS,CAAC;QAE5B,2EAA2E;QAC3E,UAAK,GAAY,KAAK,CAAC;QAEvB,yCAAyC;QACzC,SAAI,GAAa,IAAI,CAAC;QAEtB,gEAAgE;QAChE,cAAS,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAE7C,uEAAuE;QACvE,cAAS,GAAW,MAAA,YAAY,EAAE,mCAAI,UAAU,EAAE,CAAC;QASjD,IAAI,OAAO;YAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,IAAI,CAAC;IAC3B,CAAC;IACH,sBAAC;AAAD,CAAC,AA1BD,IA0BC;;AAED;;;GAGG;AACH;IACU,iCAAK;IAeb;;;;;OAKG;IACH,uBAAY,OAAe,EAAE,MAAoB;QAApB,uBAAA,EAAA,YAAoB;;QAC/C,YAAA,MAAK,YAAC,OAAO,CAAC,SAAC;QAhBjB,oDAAoD;QACpD,WAAK,GAAY,IAAI,CAAC;QAEtB,wDAAwD;QACxD,eAAS,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAE7C,iDAAiD;QACjD,eAAS,GAAW,MAAA,YAAY,EAAE,mCAAI,UAAU,EAAE,CAAC;QAUjD,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,KAAI,CAAC,IAAI,GAAG,KAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,KAAK,CAAC,iBAAiB,CAAC,KAAI,EAAE,KAAI,CAAC,WAAW,CAAC,CAAC;;IAClD,CAAC;IACH,oBAAC;AAAD,CAAC,AA5BD,CACU,KAAK,GA2Bd","sourcesContent":["import { randomUUID } from \"crypto\";\nimport { ApiResponse } from \"../types/api-response\";\nimport { getRequestId } from \"./context-store.utils\";\n\n/**\n * Standard HTTP response wrapper for successful responses.\n * Implements the `ApiResponse<T>` interface and sets default values.\n *\n * @typeParam T - The shape of the data returned in the response.\n */\nexport class SuccessResponse<T> implements ApiResponse<T> {\n /** Message describing the result of the operation. */\n message: string = \"Success\";\n\n /** Whether the response is an error. Always false in success responses. */\n error: boolean = false;\n\n /** The payload returned from the API. */\n data: T | null = null;\n\n /** Timestamp when the response was generated, in ISO format. */\n timestamp: string = new Date().toISOString();\n\n /** Unique identifier for this response, useful for request tracing. */\n requestId: string = getRequestId() ?? randomUUID();\n\n /**\n * Constructs a new success response.\n *\n * @param {string} message - Optional message to override the default.\n * @param {T} [data] - Optional data payload.\n */\n constructor(message: string, data?: T) {\n if (message) this.message = message;\n this.data = data ?? null;\n }\n}\n\n/**\n * Wrapper for error responses that extends the native `Error` object.\n * Implements `ApiResponse` but omits the `data` field (which should not be present in errors).\n */\nexport class ErrorResponse\n extends Error\n implements Omit<ApiResponse<never>, \"data\">\n{\n /** HTTP status code associated with the error (e.g., 404, 500). */\n status: number;\n\n /** Indicates that this is an error. Always true. */\n error: boolean = true;\n\n /** Timestamp when the error occurred, in ISO format. */\n timestamp: string = new Date().toISOString();\n\n /** Unique identifier for this error instance. */\n requestId: string = getRequestId() ?? randomUUID();\n\n /**\n * Constructs a new error response.\n *\n * @param {string} message - The error message to display or log.\n * @param {number} [status=500] - Optional HTTP status code (defaults to 500).\n */\n constructor(message: string, status: number = 500) {\n super(message);\n this.status = status;\n this.name = this.constructor.name;\n Error.captureStackTrace(this, this.constructor);\n }\n}\n"]}
1
+ {"version":3,"file":"response.utils.js","sourceRoot":"","sources":["../../../src/utils/response.utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD;;;;;GAKG;AACH;IAgBE;;;;;OAKG;IACH,yBAAY,OAAe,EAAE,IAAQ;;QArBrC,sDAAsD;QACtD,YAAO,GAAW,SAAS,CAAC;QAE5B,2EAA2E;QAC3E,UAAK,GAAY,KAAK,CAAC;QAEvB,yCAAyC;QACzC,SAAI,GAAa,IAAI,CAAC;QAEtB,gEAAgE;QAChE,cAAS,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAE7C,uEAAuE;QACvE,cAAS,GAAW,MAAA,YAAY,EAAE,mCAAI,UAAU,EAAE,CAAC;QASjD,IAAI,OAAO;YAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,IAAI,CAAC;IAC3B,CAAC;IACH,sBAAC;AAAD,CAAC,AA1BD,IA0BC;;AAED;;;GAGG;AACH;IAAmC,iCAAK;IAatC;;;;;OAKG;IACH,uBAAY,OAAe,EAAE,MAAoB;QAApB,uBAAA,EAAA,YAAoB;;QAC/C,YAAA,MAAK,YAAC,OAAO,CAAC,SAAC;QAhBjB,oDAAoD;QACpD,WAAK,GAAY,IAAI,CAAC;QAEtB,wDAAwD;QACxD,eAAS,GAAW,IAAI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E,QAAQ,CAAC,CAAC;IAEvD,OAAO,IAAI,iBAAiB,CAC1B,SAAS,EACT;QACE,KAAK,EAAE,QAAQ,CAAC,MAAM;QACtB,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,aAAa;KACxB,EACD,OAAO,CACR,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAAQ,EAAE,WAAoE;IACzG,mBAAmB;IACnB,IAAI,aAAa,IAAI,WAAW,EAAE,CAAC;QACjC,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;QAC9D,OAAO;IACT,CAAC;IAED,gBAAgB;IAChB,IAAI,OAAO,IAAI,WAAW,IAAI,WAAW,CAAC,KAAK,EAAE,CAAC;QAChD,IAAM,aAAa,GAAG,WAA4B,CAAC;QACnD,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YACpC,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,aAAa,CAAC,OAAO;YAC9B,SAAS,EAAE,aAAa,CAAC,SAAS;YAClC,SAAS,EAAE,aAAa,CAAC,SAAS;SACnC,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,2BAA2B;IAC3B,IAAM,eAAe,GAAG,WAAmC,CAAC;IAE5D,2CAA2C;IAC3C,IAAI,eAAe,YAAY,iBAAiB,EAAE,CAAC;QACjD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACtB,OAAO;IACT,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { randomUUID } from 'crypto';\nimport { ApiResponse } from '../types/api-response';\nimport { getRequestId } from './context-store.utils';\n\n/**\n * Standard HTTP response wrapper for successful responses.\n * Implements the `ApiResponse<T>` interface and sets default values.\n *\n * @typeParam T - The shape of the data returned in the response.\n */\nexport class SuccessResponse<T> implements ApiResponse<T> {\n /** Message describing the result of the operation. */\n message: string = 'Success';\n\n /** Whether the response is an error. Always false in success responses. */\n error: boolean = false;\n\n /** The payload returned from the API. */\n data: T | null = null;\n\n /** Timestamp when the response was generated, in ISO format. */\n timestamp: string = new Date().toISOString();\n\n /** Unique identifier for this response, useful for request tracing. */\n requestId: string = getRequestId() ?? randomUUID();\n\n /**\n * Constructs a new success response.\n *\n * @param {string} message - Optional message to override the default.\n * @param {T} [data] - Optional data payload.\n */\n constructor(message: string, data?: T) {\n if (message) this.message = message;\n this.data = data ?? null;\n }\n}\n\n/**\n * Wrapper for error responses that extends the native `Error` object.\n * Implements `ApiResponse` but omits the `data` field (which should not be present in errors).\n */\nexport class ErrorResponse extends Error implements Omit<ApiResponse<never>, 'data'> {\n /** HTTP status code associated with the error (e.g., 404, 500). */\n status: number;\n\n /** Indicates that this is an error. Always true. */\n error: boolean = true;\n\n /** Timestamp when the error occurred, in ISO format. */\n timestamp: string = new Date().toISOString();\n\n /** Unique identifier for this error instance. */\n requestId: string = getRequestId() ?? randomUUID();\n\n /**\n * Constructs a new error response.\n *\n * @param {string} message - The error message to display or log.\n * @param {number} [status=500] - Optional HTTP status code (defaults to 500).\n */\n constructor(message: string, status: number = 500) {\n super(message);\n this.status = status;\n this.name = this.constructor.name;\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\n/**\n * Response with paginated data extending the standard success response.\n * Useful for APIs that return large collections of data.\n *\n * @typeParam T - The shape of each item in the paginated collection.\n */\nexport class PaginatedResponse<T> extends SuccessResponse<T[]> {\n /** Total number of items across all pages */\n total: number;\n\n /** Current page number (1-based) */\n page: number;\n\n /** Number of items per page */\n pageSize: number;\n\n /** Total number of pages */\n totalPages: number;\n\n /** Whether there's a next page available */\n hasNext: boolean;\n\n /** Whether there's a previous page available */\n hasPrevious: boolean;\n\n /**\n * Constructs a new paginated response.\n *\n * @param {T[]} items - The current page of items.\n * @param {Object} pagination - Pagination information.\n * @param {number} pagination.total - Total number of items across all pages.\n * @param {number} pagination.page - Current page number (1-based).\n * @param {number} pagination.pageSize - Number of items per page.\n * @param {string} [message=\"Success\"] - Optional custom message.\n */\n constructor(items: T[], pagination: { total: number; page: number; pageSize: number }, message: string = 'Success') {\n super(message, items);\n\n this.total = pagination.total;\n this.page = pagination.page;\n this.pageSize = pagination.pageSize;\n\n this.totalPages = Math.ceil(this.total / this.pageSize);\n this.hasNext = this.page < this.totalPages;\n this.hasPrevious = this.page > 1;\n }\n}\n\n/**\n * Specialized response for operations that don't return data (HTTP 204).\n */\nexport class NoContentResponse extends SuccessResponse<null> {\n /**\n * Constructs a new no-content response.\n *\n * @param {string} [message=\"Operation completed successfully\"] - Optional custom message.\n */\n constructor(message: string = 'Operation completed successfully') {\n super(message, null);\n }\n}\n\n/**\n * Specialized response for redirects.\n */\nexport class RedirectResponse {\n /** The URL to redirect to */\n redirectUrl: string;\n\n /** HTTP status code for the redirect (301, 302, 303, 307, 308) */\n statusCode: number;\n\n /** Whether the response is a redirect */\n isRedirect: boolean = true;\n\n /** Unique identifier for this response */\n requestId: string = getRequestId() ?? randomUUID();\n\n /**\n * Constructs a new redirect response.\n *\n * @param {string} url - The URL to redirect to.\n * @param {number} [statusCode=302] - HTTP status code for the redirect.\n */\n constructor(url: string, statusCode: number = 302) {\n this.redirectUrl = url;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * Creates a standard success response.\n *\n * @typeParam T - The shape of the data returned in the response.\n * @param {T} data - The data to include in the response.\n * @param {string} [message=\"Success\"] - Optional custom message.\n * @returns {SuccessResponse<T>} A properly formatted success response.\n */\nexport function createSuccessResponse<T>(data: T, message: string = 'Success'): SuccessResponse<T> {\n return new SuccessResponse<T>(message, data);\n}\n\n/**\n * Creates a standard error response.\n *\n * @param {string} message - The error message.\n * @param {number} [statusCode=500] - HTTP status code for the error.\n * @returns {ErrorResponse} A properly formatted error response.\n */\nexport function createErrorResponse(message: string, statusCode: number = 500): ErrorResponse {\n return new ErrorResponse(message, statusCode);\n}\n\n/**\n * Creates a paginated response from array data.\n *\n * @typeParam T - The shape of each item in the collection.\n * @param {T[]} allItems - The complete array of items to paginate.\n * @param {number} page - The requested page (1-based).\n * @param {number} pageSize - The number of items per page.\n * @param {string} [message=\"Success\"] - Optional custom message.\n * @returns {PaginatedResponse<T>} A properly formatted paginated response.\n */\nexport function createPaginatedResponse<T>(\n allItems: T[],\n page: number,\n pageSize: number,\n message: string = 'Success'\n): PaginatedResponse<T> {\n // Ensure valid pagination parameters\n const validPage = Math.max(1, page);\n const validPageSize = Math.max(1, pageSize);\n\n // Calculate slice indices\n const startIndex = (validPage - 1) * validPageSize;\n const endIndex = startIndex + validPageSize;\n\n // Get current page items\n const pageItems = allItems.slice(startIndex, endIndex);\n\n return new PaginatedResponse<T>(\n pageItems,\n {\n total: allItems.length,\n page: validPage,\n pageSize: validPageSize\n },\n message\n );\n}\n\n/**\n * Adapter to convert API responses to Express.js response format.\n *\n * @param {any} res - Express response object.\n * @param {SuccessResponse<any> | ErrorResponse | RedirectResponse} apiResponse - API response instance.\n */\nexport function sendResponse(res: any, apiResponse: SuccessResponse<any> | ErrorResponse | RedirectResponse): void {\n // Handle redirects\n if ('redirectUrl' in apiResponse) {\n res.redirect(apiResponse.statusCode, apiResponse.redirectUrl);\n return;\n }\n\n // Handle errors\n if ('error' in apiResponse && apiResponse.error) {\n const errorResponse = apiResponse as ErrorResponse;\n res.status(errorResponse.status).json({\n error: true,\n message: errorResponse.message,\n timestamp: errorResponse.timestamp,\n requestId: errorResponse.requestId\n });\n return;\n }\n\n // Handle success responses\n const successResponse = apiResponse as SuccessResponse<any>;\n\n // No content (204) shouldn't return a body\n if (successResponse instanceof NoContentResponse) {\n res.status(204).end();\n return;\n }\n\n res.status(200).json(successResponse);\n}\n"]}
@@ -4,28 +4,28 @@
4
4
  * @param {string} str - The input string.
5
5
  * @returns {string} The string with the first character in uppercase.
6
6
  */
7
- export declare const capitalize: (str: string) => string;
7
+ export declare function capitalize(str: string): string;
8
8
  /**
9
9
  * Converts a string to kebab-case (e.g., "FooBar test" → "foo-bar-test").
10
10
  *
11
11
  * @param {string} str - The input string.
12
12
  * @returns {string} The kebab-cased string.
13
13
  */
14
- export declare const toKebabCase: (str: string) => string;
14
+ export declare function toKebabCase(str: string): string;
15
15
  /**
16
16
  * Converts a kebab-case or snake_case string to camelCase.
17
17
  *
18
18
  * @param {string} str - The input string.
19
19
  * @returns {string} The camelCased string.
20
20
  */
21
- export declare const toCamelCase: (str: string) => string;
21
+ export declare function toCamelCase(str: string): string;
22
22
  /**
23
23
  * Converts a string to a URL-friendly slug (lowercase, dashes, alphanumeric).
24
24
  *
25
25
  * @param {string} str - The input string.
26
26
  * @returns {string} The slugified string.
27
27
  */
28
- export declare const slugify: (str: string) => string;
28
+ export declare function slugify(str: string): string;
29
29
  /**
30
30
  * Truncates a string to a specific length, appending '...' if truncated.
31
31
  *
@@ -33,5 +33,61 @@ export declare const slugify: (str: string) => string;
33
33
  * @param {number} len - The maximum length.
34
34
  * @returns {string} The truncated string.
35
35
  */
36
- export declare const truncate: (str: string, len: number) => string;
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;
37
93
  //# sourceMappingURL=string.utils.d.ts.map
@@ -4,45 +4,45 @@
4
4
  * @param {string} str - The input string.
5
5
  * @returns {string} The string with the first character in uppercase.
6
6
  */
7
- export var capitalize = function (str) {
8
- return str.length === 0 ? "" : str.charAt(0).toUpperCase() + str.slice(1);
9
- };
7
+ export function capitalize(str) {
8
+ return str.length === 0 ? '' : str.charAt(0).toUpperCase() + str.slice(1);
9
+ }
10
10
  /**
11
11
  * Converts a string to kebab-case (e.g., "FooBar test" → "foo-bar-test").
12
12
  *
13
13
  * @param {string} str - The input string.
14
14
  * @returns {string} The kebab-cased string.
15
15
  */
16
- export var toKebabCase = function (str) {
16
+ export function toKebabCase(str) {
17
17
  return str
18
- .replace(/([a-z])([A-Z])/g, "$1-$2") // camelCase -> camel-Case
19
- .replace(/\s+/g, "-") // spaces to dash
20
- .replace(/_+/g, "-") // underscores to dash
18
+ .replace(/([a-z])([A-Z])/g, '$1-$2') // camelCase -> camel-Case
19
+ .replace(/\s+/g, '-') // spaces to dash
20
+ .replace(/_+/g, '-') // underscores to dash
21
21
  .toLowerCase();
22
- };
22
+ }
23
23
  /**
24
24
  * Converts a kebab-case or snake_case string to camelCase.
25
25
  *
26
26
  * @param {string} str - The input string.
27
27
  * @returns {string} The camelCased string.
28
28
  */
29
- export var toCamelCase = function (str) {
29
+ export function toCamelCase(str) {
30
30
  return str.replace(/[-_](.)/g, function (_, c) { return c.toUpperCase(); });
31
- };
31
+ }
32
32
  /**
33
33
  * Converts a string to a URL-friendly slug (lowercase, dashes, alphanumeric).
34
34
  *
35
35
  * @param {string} str - The input string.
36
36
  * @returns {string} The slugified string.
37
37
  */
38
- export var slugify = function (str) {
38
+ export function slugify(str) {
39
39
  return str
40
40
  .toLowerCase()
41
- .replace(/[^\w\s-]/g, "") // remove non-word
42
- .replace(/\s+/g, "-") // spaces to dash
43
- .replace(/-+/g, "-") // multiple dashes to one
44
- .replace(/^-+|-+$/g, "");
45
- }; // trim leading/trailing dashes
41
+ .replace(/[^\w\s-]/g, '') // remove non-word
42
+ .replace(/\s+/g, '-') // spaces to dash
43
+ .replace(/-+/g, '-') // multiple dashes to one
44
+ .replace(/^-+|-+$/g, ''); // trim leading/trailing dashes
45
+ }
46
46
  /**
47
47
  * Truncates a string to a specific length, appending '...' if truncated.
48
48
  *
@@ -50,7 +50,97 @@ export var slugify = function (str) {
50
50
  * @param {number} len - The maximum length.
51
51
  * @returns {string} The truncated string.
52
52
  */
53
- export var truncate = function (str, len) {
54
- return str.length > len ? str.slice(0, len) + "..." : str;
55
- };
53
+ export function truncate(str, len) {
54
+ return str.length > len ? str.slice(0, len) + '...' : str;
55
+ }
56
+ /**
57
+ * Converts a string to PascalCase (e.g., "foo-bar" → "FooBar").
58
+ *
59
+ * @param {string} str - The input string.
60
+ * @returns {string} The PascalCased string.
61
+ */
62
+ export function toPascalCase(str) {
63
+ return capitalize(toCamelCase(str));
64
+ }
65
+ /**
66
+ * Converts a string to snake_case (e.g., "FooBar test" → "foo_bar_test").
67
+ *
68
+ * @param {string} str - The input string.
69
+ * @returns {string} The snake_cased string.
70
+ */
71
+ export function toSnakeCase(str) {
72
+ return str
73
+ .trim()
74
+ .replace(/([a-z])([A-Z])/g, '$1_$2') // camelCase -> camel_Case
75
+ .replace(/\s+/g, '_') // spaces to underscore
76
+ .replace(/-+/g, '_') // dashes to underscore
77
+ .toLowerCase();
78
+ }
79
+ /**
80
+ * Masks a string by replacing characters with a mask character.
81
+ * Useful for hiding sensitive information like credit cards or passwords.
82
+ *
83
+ * @param {string} str - The string to mask.
84
+ * @param {number} [visibleStart=0] - Number of characters to show at start.
85
+ * @param {number} [visibleEnd=0] - Number of characters to show at end.
86
+ * @param {string} [maskChar="*"] - Character to use for masking.
87
+ * @returns {string} The masked string.
88
+ */
89
+ export function mask(str, visibleStart, visibleEnd, maskChar) {
90
+ if (visibleStart === void 0) { visibleStart = 0; }
91
+ if (visibleEnd === void 0) { visibleEnd = 0; }
92
+ if (maskChar === void 0) { maskChar = '*'; }
93
+ if (!str || str.length === 0)
94
+ return '';
95
+ if (visibleStart >= str.length)
96
+ return str;
97
+ var start = str.slice(0, visibleStart);
98
+ var end = visibleEnd > 0 ? str.slice(-visibleEnd) : '';
99
+ var masked = maskChar.repeat(Math.max(0, str.length - visibleStart - visibleEnd));
100
+ return start + masked + end;
101
+ }
102
+ /**
103
+ * Removes all HTML tags from a string.
104
+ *
105
+ * @param {string} str - The HTML string to process.
106
+ * @returns {string} The string with HTML tags removed.
107
+ */
108
+ export function stripHtml(str) {
109
+ return str.replace(/<[^>]*>/g, '');
110
+ }
111
+ /**
112
+ * Performs case-insensitive string comparison.
113
+ *
114
+ * @param {string} a - First string.
115
+ * @param {string} b - Second string.
116
+ * @returns {boolean} True if the strings are equal ignoring case.
117
+ */
118
+ export function equalsIgnoreCase(a, b) {
119
+ return a.toLowerCase() === b.toLowerCase();
120
+ }
121
+ /**
122
+ * Reverses a string.
123
+ *
124
+ * @param {string} str - The string to reverse.
125
+ * @returns {string} The reversed string.
126
+ */
127
+ export function reverse(str) {
128
+ return str.split('').reverse().join('');
129
+ }
130
+ /**
131
+ * Counts occurrences of a substring within a string.
132
+ *
133
+ * @param {string} str - The source string.
134
+ * @param {string} substring - The substring to count.
135
+ * @param {boolean} [caseSensitive=true] - Whether to perform case-sensitive counting.
136
+ * @returns {number} Number of occurrences.
137
+ */
138
+ export function countOccurrences(str, substring, caseSensitive) {
139
+ if (caseSensitive === void 0) { caseSensitive = true; }
140
+ if (!caseSensitive) {
141
+ str = str.toLowerCase();
142
+ substring = substring.toLowerCase();
143
+ }
144
+ return str.split(substring).length - 1;
145
+ }
56
146
  //# sourceMappingURL=string.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"string.utils.js","sourceRoot":"","sources":["../../../src/utils/string.utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,IAAM,UAAU,GAAG,UAAC,GAAW;IACpC,OAAA,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;AAAlE,CAAkE,CAAC;AAErE;;;;;GAKG;AACH,MAAM,CAAC,IAAM,WAAW,GAAG,UAAC,GAAW;IACrC,OAAA,GAAG;SACA,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;AAJhB,CAIgB,CAAC;AAEnB;;;;;GAKG;AACH,MAAM,CAAC,IAAM,WAAW,GAAG,UAAC,GAAW;IACrC,OAAA,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,UAAC,CAAC,EAAE,CAAS,IAAK,OAAA,CAAC,CAAC,WAAW,EAAE,EAAf,CAAe,CAAC;AAA1D,CAA0D,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,CAAC,IAAM,OAAO,GAAG,UAAC,GAAW;IACjC,OAAA,GAAG;SACA,WAAW,EAAE;SACb,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,kBAAkB;SAC3C,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,iBAAiB;SACtC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,yBAAyB;SAC7C,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;AAL1B,CAK0B,CAAC,CAAC,+BAA+B;AAE7D;;;;;;GAMG;AACH,MAAM,CAAC,IAAM,QAAQ,GAAG,UAAC,GAAW,EAAE,GAAW;IAC/C,OAAA,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG;AAAlD,CAAkD,CAAC","sourcesContent":["/**\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 const capitalize = (str: string): string =>\n str.length === 0 ? \"\" : str.charAt(0).toUpperCase() + str.slice(1);\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 const toKebabCase = (str: string): string =>\n 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 * 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 const toCamelCase = (str: string): string =>\n str.replace(/[-_](.)/g, (_, c: string) => c.toUpperCase());\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 const slugify = (str: string): string =>\n 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 * 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 const truncate = (str: string, len: number): string =>\n str.length > len ? str.slice(0, len) + \"...\" : str;\n"]}
1
+ {"version":3,"file":"string.utils.js","sourceRoot":"","sources":["../../../src/utils/string.utils.ts"],"names":[],"mappings":"AAAA;;;;;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;;;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AAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACzC,CAAC","sourcesContent":["/**\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"]}
@@ -21,4 +21,121 @@ export declare function appendQueryParams(url: string, params: Record<string, st
21
21
  * // → { page: '1', limit: '10' }
22
22
  */
23
23
  export declare function parseQueryString(query: string): Record<string, string>;
24
+ /**
25
+ * Validates if a string is a valid URL.
26
+ *
27
+ * @param {string} url - The URL string to validate.
28
+ * @param {boolean} [requireHttps=false] - If true, requires the URL to use HTTPS.
29
+ * @returns {boolean} True if the URL is valid, false otherwise.
30
+ */
31
+ export declare function isValidUrl(url: string, requireHttps?: boolean): boolean;
32
+ /**
33
+ * Extracts the domain name from a URL.
34
+ *
35
+ * @param {string} url - The URL to extract the domain from.
36
+ * @param {boolean} [removeSubdomains=false] - If true, removes subdomains (returns root domain only).
37
+ * @returns {string} The domain name.
38
+ *
39
+ * @example
40
+ * getDomain('https://api.example.com/path');
41
+ * // → 'api.example.com'
42
+ *
43
+ * getDomain('https://api.example.com/path', true);
44
+ * // → 'example.com'
45
+ */
46
+ export declare function getDomain(url: string, removeSubdomains?: boolean): string;
47
+ /**
48
+ * Joins URL paths properly handling slashes.
49
+ *
50
+ * @param {...string[]} segments - URL path segments to join.
51
+ * @returns {string} Joined URL path.
52
+ *
53
+ * @example
54
+ * joinPaths('https://example.com/', '/api/', '/users');
55
+ * // → 'https://example.com/api/users'
56
+ */
57
+ export declare function joinPaths(...segments: string[]): string;
58
+ /**
59
+ * Normalizes a URL by resolving relative paths, handling protocol-relative URLs, etc.
60
+ *
61
+ * @param {string} url - The URL to normalize.
62
+ * @param {string} [base] - Optional base URL for resolving relative URLs.
63
+ * @returns {string} Normalized URL.
64
+ *
65
+ * @example
66
+ * normalizeUrl('HTTP://Example.COM/foo/../bar');
67
+ * // → 'http://example.com/bar'
68
+ */
69
+ export declare function normalizeUrl(url: string, base?: string): string;
70
+ /**
71
+ * Creates a URL builder for constructing URLs with a base URL.
72
+ *
73
+ * @param {string} baseUrl - The base URL to build upon.
74
+ * @returns {Object} URL builder methods.
75
+ *
76
+ * @example
77
+ * const api = createUrlBuilder('https://api.example.com');
78
+ * api.path('/users', { active: true });
79
+ * // → 'https://api.example.com/users?active=true'
80
+ */
81
+ export declare function createUrlBuilder(baseUrl: string): {
82
+ /**
83
+ * Creates a full URL with the given path and query parameters.
84
+ *
85
+ * @param {string} path - The path to append to the base URL.
86
+ * @param {Record<string, any>} [params] - Query parameters to add.
87
+ * @returns {string} The complete URL.
88
+ */
89
+ path(path: string, params?: Record<string, any>): string;
90
+ /**
91
+ * Creates a full URL with query parameters but no additional path.
92
+ *
93
+ * @param {Record<string, any>} params - Query parameters to add.
94
+ * @returns {string} The complete URL with query parameters.
95
+ */
96
+ query(params: Record<string, any>): string;
97
+ };
98
+ /**
99
+ * Extracts specific query parameters from a URL.
100
+ *
101
+ * @param {string} url - The URL to extract parameters from.
102
+ * @param {string[]} paramNames - Names of parameters to extract.
103
+ * @returns {Record<string, string>} Object containing the extracted parameters.
104
+ */
105
+ export declare function extractQueryParams(url: string, paramNames: string[]): Record<string, string>;
106
+ /**
107
+ * Removes specified query parameters from a URL.
108
+ *
109
+ * @param {string} url - The URL to modify.
110
+ * @param {string[]} paramsToRemove - Names of parameters to remove.
111
+ * @returns {string} URL with parameters removed.
112
+ */
113
+ export declare function removeQueryParams(url: string, paramsToRemove: string[]): string;
114
+ /**
115
+ * Gets the file extension from a URL path.
116
+ *
117
+ * @param {string} url - The URL to examine.
118
+ * @returns {string} The file extension (without dot) or empty string if none found.
119
+ *
120
+ * @example
121
+ * getExtension('https://example.com/document.pdf?v=1');
122
+ * // → 'pdf'
123
+ */
124
+ export declare function getExtension(url: string): string;
125
+ /**
126
+ * Parses URL query parameters into a strongly-typed object.
127
+ *
128
+ * @template T Expected type of the query parameters
129
+ * @param {string} url - The URL to parse.
130
+ * @param {Record<keyof T, (val: string) => any>} [converters] - Type converters for params.
131
+ * @returns {Partial<T>} Typed query parameters.
132
+ *
133
+ * @example
134
+ * parseTypedQueryParams<{page: number, q: string}>('https://example.com?page=2&q=test', {
135
+ * page: Number,
136
+ * q: String
137
+ * });
138
+ * // → { page: 2, q: 'test' }
139
+ */
140
+ export declare function parseTypedQueryParams<T extends Record<string, any>>(url: string, converters?: Record<keyof T, (val: string) => any>): Partial<T>;
24
141
  //# sourceMappingURL=url.utils.d.ts.map