@catbee/utils 0.0.8-rc.1 → 0.0.8-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/build/esm/config.d.ts +0 -1
  2. package/build/esm/config.js +6 -7
  3. package/build/esm/index.d.ts +0 -1
  4. package/build/esm/index.js +0 -1
  5. package/build/esm/servers/server.builder.d.ts +0 -1
  6. package/build/esm/servers/server.builder.js +99 -147
  7. package/build/esm/servers/server.d.ts +0 -1
  8. package/build/esm/servers/server.js +591 -876
  9. package/build/esm/types/api-response.d.ts +0 -1
  10. package/build/esm/types/api-response.js +0 -1
  11. package/build/esm/types/index.d.ts +0 -1
  12. package/build/esm/types/index.js +0 -1
  13. package/build/esm/types/server.d.ts +0 -1
  14. package/build/esm/types/server.js +0 -1
  15. package/build/esm/utils/array.utils.d.ts +0 -1
  16. package/build/esm/utils/array.utils.js +48 -86
  17. package/build/esm/utils/async.utils.d.ts +0 -1
  18. package/build/esm/utils/async.utils.js +247 -524
  19. package/build/esm/utils/cache.utils.d.ts +0 -1
  20. package/build/esm/utils/cache.utils.js +96 -301
  21. package/build/esm/utils/context-store.utils.d.ts +0 -1
  22. package/build/esm/utils/context-store.utils.js +62 -79
  23. package/build/esm/utils/crypto.utils.d.ts +0 -1
  24. package/build/esm/utils/crypto.utils.js +78 -175
  25. package/build/esm/utils/date.utils.d.ts +0 -1
  26. package/build/esm/utils/date.utils.js +47 -53
  27. package/build/esm/utils/decorators.utils.d.ts +30 -27
  28. package/build/esm/utils/decorators.utils.js +417 -461
  29. package/build/esm/utils/dir.utils.d.ts +0 -1
  30. package/build/esm/utils/dir.utils.js +264 -786
  31. package/build/esm/utils/env.utils.d.ts +0 -1
  32. package/build/esm/utils/env.utils.js +180 -271
  33. package/build/esm/utils/exception.utils.d.ts +0 -1
  34. package/build/esm/utils/exception.utils.js +112 -289
  35. package/build/esm/utils/fs.utils.d.ts +0 -1
  36. package/build/esm/utils/fs.utils.js +169 -401
  37. package/build/esm/utils/http-status-codes.d.ts +0 -1
  38. package/build/esm/utils/http-status-codes.js +0 -1
  39. package/build/esm/utils/id.utils.d.ts +0 -1
  40. package/build/esm/utils/id.utils.js +5 -9
  41. package/build/esm/utils/logger.utils.d.ts +0 -1
  42. package/build/esm/utils/logger.utils.js +34 -71
  43. package/build/esm/utils/middleware.utils.d.ts +0 -1
  44. package/build/esm/utils/middleware.utils.js +65 -155
  45. package/build/esm/utils/obj.utils.d.ts +0 -1
  46. package/build/esm/utils/obj.utils.js +69 -176
  47. package/build/esm/utils/performance.utils.d.ts +0 -1
  48. package/build/esm/utils/performance.utils.js +92 -195
  49. package/build/esm/utils/request.utils.d.ts +0 -1
  50. package/build/esm/utils/request.utils.js +41 -74
  51. package/build/esm/utils/response.utils.d.ts +0 -1
  52. package/build/esm/utils/response.utils.js +84 -107
  53. package/build/esm/utils/stream.utils.d.ts +0 -1
  54. package/build/esm/utils/stream.utils.js +38 -113
  55. package/build/esm/utils/string.utils.d.ts +0 -1
  56. package/build/esm/utils/string.utils.js +6 -11
  57. package/build/esm/utils/type.utils.d.ts +0 -1
  58. package/build/esm/utils/type.utils.js +8 -12
  59. package/build/esm/utils/url.utils.d.ts +0 -1
  60. package/build/esm/utils/url.utils.js +49 -127
  61. package/build/esm/utils/validate.utils.d.ts +0 -1
  62. package/build/esm/utils/validate.utils.js +23 -40
  63. package/package.json +3 -33
  64. package/build/esm/config.js.map +0 -1
  65. package/build/esm/index.js.map +0 -1
  66. package/build/esm/servers/server.builder.js.map +0 -1
  67. package/build/esm/servers/server.js.map +0 -1
  68. package/build/esm/types/api-response.js.map +0 -1
  69. package/build/esm/types/index.js.map +0 -1
  70. package/build/esm/types/server.js.map +0 -1
  71. package/build/esm/utils/array.utils.js.map +0 -1
  72. package/build/esm/utils/async.utils.js.map +0 -1
  73. package/build/esm/utils/cache.utils.js.map +0 -1
  74. package/build/esm/utils/context-store.utils.js.map +0 -1
  75. package/build/esm/utils/crypto.utils.js.map +0 -1
  76. package/build/esm/utils/date.utils.js.map +0 -1
  77. package/build/esm/utils/decorators.utils.js.map +0 -1
  78. package/build/esm/utils/dir.utils.js.map +0 -1
  79. package/build/esm/utils/env.utils.js.map +0 -1
  80. package/build/esm/utils/exception.utils.js.map +0 -1
  81. package/build/esm/utils/fs.utils.js.map +0 -1
  82. package/build/esm/utils/http-status-codes.js.map +0 -1
  83. package/build/esm/utils/id.utils.js.map +0 -1
  84. package/build/esm/utils/logger.utils.js.map +0 -1
  85. package/build/esm/utils/middleware.utils.js.map +0 -1
  86. package/build/esm/utils/obj.utils.js.map +0 -1
  87. package/build/esm/utils/performance.utils.js.map +0 -1
  88. package/build/esm/utils/request.utils.js.map +0 -1
  89. package/build/esm/utils/response.utils.js.map +0 -1
  90. package/build/esm/utils/stream.utils.js.map +0 -1
  91. package/build/esm/utils/string.utils.js.map +0 -1
  92. package/build/esm/utils/type.utils.js.map +0 -1
  93. package/build/esm/utils/url.utils.js.map +0 -1
  94. package/build/esm/utils/validate.utils.js.map +0 -1
  95. package/build/esnext/config.d.ts +0 -122
  96. package/build/esnext/config.js +0 -133
  97. package/build/esnext/config.js.map +0 -1
  98. package/build/esnext/index.d.ts +0 -27
  99. package/build/esnext/index.js +0 -50
  100. package/build/esnext/index.js.map +0 -1
  101. package/build/esnext/servers/server.builder.d.ts +0 -508
  102. package/build/esnext/servers/server.builder.js +0 -657
  103. package/build/esnext/servers/server.builder.js.map +0 -1
  104. package/build/esnext/servers/server.d.ts +0 -256
  105. package/build/esnext/servers/server.js +0 -955
  106. package/build/esnext/servers/server.js.map +0 -1
  107. package/build/esnext/types/api-response.d.ts +0 -152
  108. package/build/esnext/types/api-response.js +0 -34
  109. package/build/esnext/types/api-response.js.map +0 -1
  110. package/build/esnext/types/index.d.ts +0 -125
  111. package/build/esnext/types/index.js +0 -25
  112. package/build/esnext/types/index.js.map +0 -1
  113. package/build/esnext/types/server.d.ts +0 -268
  114. package/build/esnext/types/server.js +0 -25
  115. package/build/esnext/types/server.js.map +0 -1
  116. package/build/esnext/utils/array.utils.d.ts +0 -168
  117. package/build/esnext/utils/array.utils.js +0 -345
  118. package/build/esnext/utils/array.utils.js.map +0 -1
  119. package/build/esnext/utils/async.utils.d.ts +0 -265
  120. package/build/esnext/utils/async.utils.js +0 -620
  121. package/build/esnext/utils/async.utils.js.map +0 -1
  122. package/build/esnext/utils/cache.utils.d.ts +0 -153
  123. package/build/esnext/utils/cache.utils.js +0 -293
  124. package/build/esnext/utils/cache.utils.js.map +0 -1
  125. package/build/esnext/utils/context-store.utils.d.ts +0 -189
  126. package/build/esnext/utils/context-store.utils.js +0 -289
  127. package/build/esnext/utils/context-store.utils.js.map +0 -1
  128. package/build/esnext/utils/crypto.utils.d.ts +0 -160
  129. package/build/esnext/utils/crypto.utils.js +0 -276
  130. package/build/esnext/utils/crypto.utils.js.map +0 -1
  131. package/build/esnext/utils/date.utils.d.ts +0 -159
  132. package/build/esnext/utils/date.utils.js +0 -384
  133. package/build/esnext/utils/date.utils.js.map +0 -1
  134. package/build/esnext/utils/decorators.utils.d.ts +0 -508
  135. package/build/esnext/utils/decorators.utils.js +0 -877
  136. package/build/esnext/utils/decorators.utils.js.map +0 -1
  137. package/build/esnext/utils/dir.utils.d.ts +0 -196
  138. package/build/esnext/utils/dir.utils.js +0 -477
  139. package/build/esnext/utils/dir.utils.js.map +0 -1
  140. package/build/esnext/utils/env.utils.d.ts +0 -377
  141. package/build/esnext/utils/env.utils.js +0 -785
  142. package/build/esnext/utils/env.utils.js.map +0 -1
  143. package/build/esnext/utils/exception.utils.d.ts +0 -230
  144. package/build/esnext/utils/exception.utils.js +0 -381
  145. package/build/esnext/utils/exception.utils.js.map +0 -1
  146. package/build/esnext/utils/fs.utils.d.ts +0 -164
  147. package/build/esnext/utils/fs.utils.js +0 -349
  148. package/build/esnext/utils/fs.utils.js.map +0 -1
  149. package/build/esnext/utils/http-status-codes.d.ts +0 -266
  150. package/build/esnext/utils/http-status-codes.js +0 -295
  151. package/build/esnext/utils/http-status-codes.js.map +0 -1
  152. package/build/esnext/utils/id.utils.d.ts +0 -36
  153. package/build/esnext/utils/id.utils.js +0 -84
  154. package/build/esnext/utils/id.utils.js.map +0 -1
  155. package/build/esnext/utils/logger.utils.d.ts +0 -160
  156. package/build/esnext/utils/logger.utils.js +0 -300
  157. package/build/esnext/utils/logger.utils.js.map +0 -1
  158. package/build/esnext/utils/middleware.utils.d.ts +0 -100
  159. package/build/esnext/utils/middleware.utils.js +0 -236
  160. package/build/esnext/utils/middleware.utils.js.map +0 -1
  161. package/build/esnext/utils/obj.utils.d.ts +0 -124
  162. package/build/esnext/utils/obj.utils.js +0 -413
  163. package/build/esnext/utils/obj.utils.js.map +0 -1
  164. package/build/esnext/utils/performance.utils.d.ts +0 -136
  165. package/build/esnext/utils/performance.utils.js +0 -271
  166. package/build/esnext/utils/performance.utils.js.map +0 -1
  167. package/build/esnext/utils/request.utils.d.ts +0 -86
  168. package/build/esnext/utils/request.utils.js +0 -186
  169. package/build/esnext/utils/request.utils.js.map +0 -1
  170. package/build/esnext/utils/response.utils.d.ts +0 -163
  171. package/build/esnext/utils/response.utils.js +0 -247
  172. package/build/esnext/utils/response.utils.js.map +0 -1
  173. package/build/esnext/utils/stream.utils.d.ts +0 -88
  174. package/build/esnext/utils/stream.utils.js +0 -210
  175. package/build/esnext/utils/stream.utils.js.map +0 -1
  176. package/build/esnext/utils/string.utils.d.ts +0 -93
  177. package/build/esnext/utils/string.utils.js +0 -165
  178. package/build/esnext/utils/string.utils.js.map +0 -1
  179. package/build/esnext/utils/type.utils.d.ts +0 -90
  180. package/build/esnext/utils/type.utils.js +0 -187
  181. package/build/esnext/utils/type.utils.js.map +0 -1
  182. package/build/esnext/utils/url.utils.d.ts +0 -141
  183. package/build/esnext/utils/url.utils.js +0 -304
  184. package/build/esnext/utils/url.utils.js.map +0 -1
  185. package/build/esnext/utils/validate.utils.d.ts +0 -177
  186. package/build/esnext/utils/validate.utils.js +0 -320
  187. package/build/esnext/utils/validate.utils.js.map +0 -1
  188. package/build/src/config.d.ts +0 -122
  189. package/build/src/config.js +0 -138
  190. package/build/src/config.js.map +0 -1
  191. package/build/src/index.d.ts +0 -27
  192. package/build/src/index.js +0 -69
  193. package/build/src/index.js.map +0 -1
  194. package/build/src/servers/server.builder.d.ts +0 -508
  195. package/build/src/servers/server.builder.js +0 -661
  196. package/build/src/servers/server.builder.js.map +0 -1
  197. package/build/src/servers/server.d.ts +0 -256
  198. package/build/src/servers/server.js +0 -962
  199. package/build/src/servers/server.js.map +0 -1
  200. package/build/src/types/api-response.d.ts +0 -152
  201. package/build/src/types/api-response.js +0 -37
  202. package/build/src/types/api-response.js.map +0 -1
  203. package/build/src/types/index.d.ts +0 -125
  204. package/build/src/types/index.js +0 -26
  205. package/build/src/types/index.js.map +0 -1
  206. package/build/src/types/server.d.ts +0 -268
  207. package/build/src/types/server.js +0 -26
  208. package/build/src/types/server.js.map +0 -1
  209. package/build/src/utils/array.utils.d.ts +0 -168
  210. package/build/src/utils/array.utils.js +0 -364
  211. package/build/src/utils/array.utils.js.map +0 -1
  212. package/build/src/utils/async.utils.d.ts +0 -265
  213. package/build/src/utils/async.utils.js +0 -641
  214. package/build/src/utils/async.utils.js.map +0 -1
  215. package/build/src/utils/cache.utils.d.ts +0 -153
  216. package/build/src/utils/cache.utils.js +0 -297
  217. package/build/src/utils/cache.utils.js.map +0 -1
  218. package/build/src/utils/context-store.utils.d.ts +0 -189
  219. package/build/src/utils/context-store.utils.js +0 -296
  220. package/build/src/utils/context-store.utils.js.map +0 -1
  221. package/build/src/utils/crypto.utils.d.ts +0 -160
  222. package/build/src/utils/crypto.utils.js +0 -293
  223. package/build/src/utils/crypto.utils.js.map +0 -1
  224. package/build/src/utils/date.utils.d.ts +0 -159
  225. package/build/src/utils/date.utils.js +0 -396
  226. package/build/src/utils/date.utils.js.map +0 -1
  227. package/build/src/utils/decorators.utils.d.ts +0 -508
  228. package/build/src/utils/decorators.utils.js +0 -896
  229. package/build/src/utils/decorators.utils.js.map +0 -1
  230. package/build/src/utils/dir.utils.d.ts +0 -196
  231. package/build/src/utils/dir.utils.js +0 -501
  232. package/build/src/utils/dir.utils.js.map +0 -1
  233. package/build/src/utils/env.utils.d.ts +0 -377
  234. package/build/src/utils/env.utils.js +0 -789
  235. package/build/src/utils/env.utils.js.map +0 -1
  236. package/build/src/utils/exception.utils.d.ts +0 -230
  237. package/build/src/utils/exception.utils.js +0 -407
  238. package/build/src/utils/exception.utils.js.map +0 -1
  239. package/build/src/utils/fs.utils.d.ts +0 -164
  240. package/build/src/utils/fs.utils.js +0 -372
  241. package/build/src/utils/fs.utils.js.map +0 -1
  242. package/build/src/utils/http-status-codes.d.ts +0 -266
  243. package/build/src/utils/http-status-codes.js +0 -298
  244. package/build/src/utils/http-status-codes.js.map +0 -1
  245. package/build/src/utils/id.utils.d.ts +0 -36
  246. package/build/src/utils/id.utils.js +0 -91
  247. package/build/src/utils/id.utils.js.map +0 -1
  248. package/build/src/utils/logger.utils.d.ts +0 -160
  249. package/build/src/utils/logger.utils.js +0 -346
  250. package/build/src/utils/logger.utils.js.map +0 -1
  251. package/build/src/utils/middleware.utils.d.ts +0 -100
  252. package/build/src/utils/middleware.utils.js +0 -244
  253. package/build/src/utils/middleware.utils.js.map +0 -1
  254. package/build/src/utils/obj.utils.d.ts +0 -124
  255. package/build/src/utils/obj.utils.js +0 -429
  256. package/build/src/utils/obj.utils.js.map +0 -1
  257. package/build/src/utils/performance.utils.d.ts +0 -136
  258. package/build/src/utils/performance.utils.js +0 -278
  259. package/build/src/utils/performance.utils.js.map +0 -1
  260. package/build/src/utils/request.utils.d.ts +0 -86
  261. package/build/src/utils/request.utils.js +0 -195
  262. package/build/src/utils/request.utils.js.map +0 -1
  263. package/build/src/utils/response.utils.d.ts +0 -163
  264. package/build/src/utils/response.utils.js +0 -260
  265. package/build/src/utils/response.utils.js.map +0 -1
  266. package/build/src/utils/stream.utils.d.ts +0 -88
  267. package/build/src/utils/stream.utils.js +0 -218
  268. package/build/src/utils/stream.utils.js.map +0 -1
  269. package/build/src/utils/string.utils.d.ts +0 -93
  270. package/build/src/utils/string.utils.js +0 -179
  271. package/build/src/utils/string.utils.js.map +0 -1
  272. package/build/src/utils/type.utils.d.ts +0 -90
  273. package/build/src/utils/type.utils.js +0 -196
  274. package/build/src/utils/type.utils.js.map +0 -1
  275. package/build/src/utils/url.utils.d.ts +0 -141
  276. package/build/src/utils/url.utils.js +0 -317
  277. package/build/src/utils/url.utils.js.map +0 -1
  278. package/build/src/utils/validate.utils.d.ts +0 -177
  279. package/build/src/utils/validate.utils.js +0 -345
  280. package/build/src/utils/validate.utils.js.map +0 -1
@@ -21,69 +21,6 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- var __assign = (this && this.__assign) || function () {
25
- __assign = Object.assign || function(t) {
26
- for (var s, i = 1, n = arguments.length; i < n; i++) {
27
- s = arguments[i];
28
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29
- t[p] = s[p];
30
- }
31
- return t;
32
- };
33
- return __assign.apply(this, arguments);
34
- };
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __generator = (this && this.__generator) || function (thisArg, body) {
45
- 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);
46
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
- function verb(n) { return function (v) { return step([n, v]); }; }
48
- function step(op) {
49
- if (f) throw new TypeError("Generator is already executing.");
50
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
51
- 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;
52
- if (y = 0, t) op = [op[0] & 2, t.value];
53
- switch (op[0]) {
54
- case 0: case 1: t = op; break;
55
- case 4: _.label++; return { value: op[1], done: false };
56
- case 5: _.label++; y = op[1]; op = [0]; continue;
57
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
- default:
59
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
- if (t[2]) _.ops.pop();
64
- _.trys.pop(); continue;
65
- }
66
- op = body.call(thisArg, _);
67
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
- }
70
- };
71
- var __read = (this && this.__read) || function (o, n) {
72
- var m = typeof Symbol === "function" && o[Symbol.iterator];
73
- if (!m) return o;
74
- var i = m.call(o), r, ar = [], e;
75
- try {
76
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
77
- }
78
- catch (error) { e = { error: error }; }
79
- finally {
80
- try {
81
- if (r && !r.done && (m = i["return"])) m.call(i);
82
- }
83
- finally { if (e) throw e.error; }
84
- }
85
- return ar;
86
- };
87
24
  import { createHmac, createHash, randomBytes, createCipheriv, createDecipheriv, scrypt, timingSafeEqual } from 'crypto';
88
25
  import { promisify } from 'util';
89
26
  import { uuid } from './id.utils';
@@ -96,8 +33,7 @@ import { uuid } from './id.utils';
96
33
  * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding ('hex', 'base64', etc).
97
34
  * @returns {string} HMAC digest as a string.
98
35
  */
99
- export function hmac(algorithm, input, secret, encoding) {
100
- if (encoding === void 0) { encoding = 'hex'; }
36
+ export function hmac(algorithm, input, secret, encoding = 'hex') {
101
37
  return createHmac(algorithm, secret).update(input).digest(encoding);
102
38
  }
103
39
  /**
@@ -108,8 +44,7 @@ export function hmac(algorithm, input, secret, encoding) {
108
44
  * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding ('hex', 'base64', etc).
109
45
  * @returns {string} Hash digest as a string.
110
46
  */
111
- export function hash(algorithm, input, encoding) {
112
- if (encoding === void 0) { encoding = 'hex'; }
47
+ export function hash(algorithm, input, encoding = 'hex') {
113
48
  return createHash(algorithm).update(input).digest(encoding);
114
49
  }
115
50
  /**
@@ -129,8 +64,7 @@ export function sha256Hmac(input, secret) {
129
64
  * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding.
130
65
  * @returns {string} SHA-1 hash as a string.
131
66
  */
132
- export function sha1(input, encoding) {
133
- if (encoding === void 0) { encoding = 'hex'; }
67
+ export function sha1(input, encoding = 'hex') {
134
68
  return hash('sha1', input, encoding);
135
69
  }
136
70
  /**
@@ -140,8 +74,7 @@ export function sha1(input, encoding) {
140
74
  * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding.
141
75
  * @returns {string} SHA-256 hash as a string.
142
76
  */
143
- export function sha256(input, encoding) {
144
- if (encoding === void 0) { encoding = 'hex'; }
77
+ export function sha256(input, encoding = 'hex') {
145
78
  return hash('sha256', input, encoding);
146
79
  }
147
80
  /**
@@ -167,8 +100,7 @@ export function randomString() {
167
100
  * @param {number} [byteLength=32] - Number of random bytes to generate.
168
101
  * @returns {Buffer} Buffer containing random bytes.
169
102
  */
170
- export function generateRandomBytes(byteLength) {
171
- if (byteLength === void 0) { byteLength = 32; }
103
+ export function generateRandomBytes(byteLength = 32) {
172
104
  return randomBytes(byteLength);
173
105
  }
174
106
  /**
@@ -178,9 +110,7 @@ export function generateRandomBytes(byteLength) {
178
110
  * @param {BinaryToTextEncoding} [encoding='hex'] - Output encoding.
179
111
  * @returns {string} Random string in specified encoding.
180
112
  */
181
- export function generateRandomBytesAsString(byteLength, encoding) {
182
- if (byteLength === void 0) { byteLength = 32; }
183
- if (encoding === void 0) { encoding = 'hex'; }
113
+ export function generateRandomBytesAsString(byteLength = 32, encoding = 'hex') {
184
114
  return randomBytes(byteLength).toString(encoding);
185
115
  }
186
116
  /**
@@ -190,14 +120,12 @@ export function generateRandomBytesAsString(byteLength, encoding) {
190
120
  * @param {number} [byteLength=24] - Number of random bytes to generate.
191
121
  * @returns {string} Formatted API key.
192
122
  */
193
- export function generateApiKey(prefix, byteLength) {
194
- if (prefix === void 0) { prefix = ''; }
195
- if (byteLength === void 0) { byteLength = 24; }
196
- var randomString = generateRandomBytesAsString(byteLength, 'base64');
197
- var key = randomString
123
+ export function generateApiKey(prefix = '', byteLength = 24) {
124
+ const randomString = generateRandomBytesAsString(byteLength, 'base64');
125
+ const key = randomString
198
126
  .replace(/[+/=]/g, '') // Remove non-URL-safe characters
199
127
  .substring(0, 32); // Limit length
200
- return prefix ? "".concat(prefix, "_").concat(key) : key;
128
+ return prefix ? `${prefix}_${key}` : key;
201
129
  }
202
130
  /**
203
131
  * Compares two strings, arrays, or buffers in constant time to prevent timing attacks.
@@ -209,8 +137,8 @@ export function generateApiKey(prefix, byteLength) {
209
137
  export function safeCompare(a, b) {
210
138
  if (typeof a === 'string' && typeof b === 'string') {
211
139
  // Convert strings to buffers
212
- var bufA = Buffer.from(a);
213
- var bufB = Buffer.from(b);
140
+ const bufA = Buffer.from(a);
141
+ const bufB = Buffer.from(b);
214
142
  // Compare lengths first (not constant time, but prevents timing attack on contents)
215
143
  if (bufA.length !== bufB.length)
216
144
  return false;
@@ -225,7 +153,7 @@ export function safeCompare(a, b) {
225
153
  throw new Error('Cannot compare: inputs must be strings, Buffers, or Uint8Arrays');
226
154
  }
227
155
  // Promisified version of scrypt for key derivation
228
- var scryptAsync = promisify(scrypt);
156
+ const scryptAsync = promisify(scrypt);
229
157
  /**
230
158
  * Encrypts data using a symmetric key with secure defaults (AES-256-GCM).
231
159
  *
@@ -234,46 +162,34 @@ var scryptAsync = promisify(scrypt);
234
162
  * @param {EncryptionOptions} [options] - Encryption options
235
163
  * @returns {Promise<EncryptionResult>} Encrypted data with metadata
236
164
  */
237
- export function encrypt(data_1, key_1) {
238
- return __awaiter(this, arguments, void 0, function (data, key, options) {
239
- var algorithm, inputEncoding, outputEncoding, iv, derivedKey, _a, cipher, ciphertext, encrypted, authTag;
240
- if (options === void 0) { options = {}; }
241
- return __generator(this, function (_b) {
242
- switch (_b.label) {
243
- case 0:
244
- algorithm = options.algorithm || 'aes-256-gcm';
245
- inputEncoding = options.inputEncoding || 'utf8';
246
- outputEncoding = options.outputEncoding || 'hex';
247
- iv = randomBytes(16);
248
- if (!(typeof key === 'string')) return [3 /*break*/, 2];
249
- return [4 /*yield*/, scryptAsync(key, iv.slice(0, 8), 32)];
250
- case 1:
251
- _a = _b.sent();
252
- return [3 /*break*/, 3];
253
- case 2:
254
- _a = key;
255
- _b.label = 3;
256
- case 3:
257
- derivedKey = _a;
258
- cipher = createCipheriv(algorithm, derivedKey, iv);
259
- if (typeof data === 'string') {
260
- ciphertext = cipher.update(data, inputEncoding, outputEncoding);
261
- ciphertext += cipher.final(outputEncoding);
262
- }
263
- else {
264
- encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
265
- ciphertext = outputEncoding ? encrypted.toString(outputEncoding) : encrypted;
266
- }
267
- authTag = algorithm.includes('gcm') ? cipher.getAuthTag() : undefined;
268
- return [2 /*return*/, {
269
- ciphertext: ciphertext,
270
- iv: iv,
271
- authTag: authTag,
272
- algorithm: algorithm
273
- }];
274
- }
275
- });
276
- });
165
+ export async function encrypt(data, key, options = {}) {
166
+ const algorithm = options.algorithm || 'aes-256-gcm';
167
+ const inputEncoding = options.inputEncoding || 'utf8';
168
+ const outputEncoding = options.outputEncoding || 'hex';
169
+ // Generate a random IV
170
+ const iv = randomBytes(16);
171
+ // Derive key using scrypt if key is a string (passphrase)
172
+ const derivedKey = typeof key === 'string' ? await scryptAsync(key, iv.slice(0, 8), 32) : key;
173
+ // Create cipher
174
+ const cipher = createCipheriv(algorithm, derivedKey, iv);
175
+ // Encrypt the data
176
+ let ciphertext;
177
+ if (typeof data === 'string') {
178
+ ciphertext = cipher.update(data, inputEncoding, outputEncoding);
179
+ ciphertext += cipher.final(outputEncoding);
180
+ }
181
+ else {
182
+ const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
183
+ ciphertext = outputEncoding ? encrypted.toString(outputEncoding) : encrypted;
184
+ }
185
+ // Get authentication tag if using GCM mode
186
+ const authTag = algorithm.includes('gcm') ? cipher.getAuthTag() : undefined;
187
+ return {
188
+ ciphertext,
189
+ iv,
190
+ authTag,
191
+ algorithm
192
+ };
277
193
  }
278
194
  /**
279
195
  * Decrypts data that was encrypted with the encrypt function.
@@ -283,43 +199,29 @@ export function encrypt(data_1, key_1) {
283
199
  * @param {DecryptionOptions} [options] - Decryption options
284
200
  * @returns {Promise<string | Buffer>} Decrypted data
285
201
  */
286
- export function decrypt(encryptedData_1, key_1) {
287
- return __awaiter(this, arguments, void 0, function (encryptedData, key, options) {
288
- var algorithm, inputEncoding, outputEncoding, derivedKey, _a, decipher, decrypted, result;
289
- if (options === void 0) { options = {}; }
290
- return __generator(this, function (_b) {
291
- switch (_b.label) {
292
- case 0:
293
- algorithm = options.algorithm || encryptedData.algorithm || 'aes-256-gcm';
294
- inputEncoding = options.inputEncoding || 'hex';
295
- outputEncoding = options.outputEncoding || 'utf8';
296
- if (!(typeof key === 'string')) return [3 /*break*/, 2];
297
- return [4 /*yield*/, scryptAsync(key, encryptedData.iv.slice(0, 8), 32)];
298
- case 1:
299
- _a = _b.sent();
300
- return [3 /*break*/, 3];
301
- case 2:
302
- _a = key;
303
- _b.label = 3;
304
- case 3:
305
- derivedKey = _a;
306
- decipher = createDecipheriv(algorithm, derivedKey, encryptedData.iv);
307
- // Set auth tag if using GCM mode
308
- if (encryptedData.authTag && algorithm.includes('gcm')) {
309
- decipher.setAuthTag(encryptedData.authTag);
310
- }
311
- if (typeof encryptedData.ciphertext === 'string') {
312
- decrypted = decipher.update(encryptedData.ciphertext, inputEncoding, outputEncoding);
313
- decrypted += decipher.final(outputEncoding);
314
- }
315
- else {
316
- result = Buffer.concat([decipher.update(encryptedData.ciphertext), decipher.final()]);
317
- decrypted = outputEncoding ? result.toString(outputEncoding) : result;
318
- }
319
- return [2 /*return*/, decrypted];
320
- }
321
- });
322
- });
202
+ export async function decrypt(encryptedData, key, options = {}) {
203
+ const algorithm = options.algorithm || encryptedData.algorithm || 'aes-256-gcm';
204
+ const inputEncoding = options.inputEncoding || 'hex';
205
+ const outputEncoding = options.outputEncoding || 'utf8';
206
+ // Derive key using scrypt if key is a string (passphrase)
207
+ const derivedKey = typeof key === 'string' ? await scryptAsync(key, encryptedData.iv.slice(0, 8), 32) : key;
208
+ // Create decipher
209
+ const decipher = createDecipheriv(algorithm, derivedKey, encryptedData.iv);
210
+ // Set auth tag if using GCM mode
211
+ if (encryptedData.authTag && algorithm.includes('gcm')) {
212
+ decipher.setAuthTag(encryptedData.authTag);
213
+ }
214
+ // Decrypt the data
215
+ let decrypted;
216
+ if (typeof encryptedData.ciphertext === 'string') {
217
+ decrypted = decipher.update(encryptedData.ciphertext, inputEncoding, outputEncoding);
218
+ decrypted += decipher.final(outputEncoding);
219
+ }
220
+ else {
221
+ const result = Buffer.concat([decipher.update(encryptedData.ciphertext), decipher.final()]);
222
+ decrypted = outputEncoding ? result.toString(outputEncoding) : result;
223
+ }
224
+ return decrypted;
323
225
  }
324
226
  /**
325
227
  * Creates a signed token with an expiration time and payload.
@@ -329,18 +231,20 @@ export function decrypt(encryptedData_1, key_1) {
329
231
  * @param {number} [expiresInSeconds=3600] - Token expiration in seconds
330
232
  * @returns {string} Signed token string
331
233
  */
332
- export function createSignedToken(payload, secret, expiresInSeconds) {
333
- if (expiresInSeconds === void 0) { expiresInSeconds = 3600; }
234
+ export function createSignedToken(payload, secret, expiresInSeconds = 3600) {
334
235
  // Create payload with expiration
335
- var tokenPayload = __assign(__assign({}, payload), { exp: Math.floor(Date.now() / 1000) + expiresInSeconds });
236
+ const tokenPayload = {
237
+ ...payload,
238
+ exp: Math.floor(Date.now() / 1000) + expiresInSeconds
239
+ };
336
240
  // Convert to string
337
- var payloadStr = JSON.stringify(tokenPayload);
241
+ const payloadStr = JSON.stringify(tokenPayload);
338
242
  // Base64 encode the payload
339
- var base64Payload = Buffer.from(payloadStr).toString('base64url');
243
+ const base64Payload = Buffer.from(payloadStr).toString('base64url');
340
244
  // Create signature
341
- var signature = hmac('sha256', base64Payload, secret, 'base64url');
245
+ const signature = hmac('sha256', base64Payload, secret, 'base64url');
342
246
  // Combine payload and signature
343
- return "".concat(base64Payload, ".").concat(signature);
247
+ return `${base64Payload}.${signature}`;
344
248
  }
345
249
  /**
346
250
  * Verifies and decodes a signed token.
@@ -352,24 +256,23 @@ export function createSignedToken(payload, secret, expiresInSeconds) {
352
256
  export function verifySignedToken(token, secret) {
353
257
  try {
354
258
  // Split token into parts
355
- var _a = __read(token.split('.'), 2), payloadB64 = _a[0], signature = _a[1];
259
+ const [payloadB64, signature] = token.split('.');
356
260
  if (!payloadB64 || !signature)
357
261
  return null;
358
262
  // Verify signature
359
- var expectedSignature = hmac('sha256', payloadB64, secret, 'base64url');
263
+ const expectedSignature = hmac('sha256', payloadB64, secret, 'base64url');
360
264
  if (!safeCompare(signature, expectedSignature))
361
265
  return null;
362
266
  // Decode payload
363
- var payloadStr = Buffer.from(payloadB64, 'base64url').toString('utf8');
364
- var payload = JSON.parse(payloadStr);
267
+ const payloadStr = Buffer.from(payloadB64, 'base64url').toString('utf8');
268
+ const payload = JSON.parse(payloadStr);
365
269
  // Check expiration
366
270
  if (payload.exp && payload.exp < Math.floor(Date.now() / 1000)) {
367
271
  return null;
368
272
  }
369
273
  return payload;
370
274
  }
371
- catch (_b) {
275
+ catch {
372
276
  return null;
373
277
  }
374
278
  }
375
- //# sourceMappingURL=crypto.utils.js.map
@@ -156,4 +156,3 @@ export declare function isLeapYear(year: number | Date): boolean;
156
156
  * @returns Number of days in the month
157
157
  */
158
158
  export declare function daysInMonth(year: number | Date, month?: number): number;
159
- //# sourceMappingURL=date.utils.d.ts.map
@@ -40,32 +40,31 @@
40
40
  * formatDate(new Date(), { format: 'PPPP', locale: 'fr-FR' }); // 'lundi 15 mai 2023'
41
41
  * ```
42
42
  */
43
- export function formatDate(date, options) {
44
- if (options === void 0) { options = {}; }
45
- var _a = options.format, format = _a === void 0 ? 'yyyy-MM-dd' : _a, locale = options.locale, timeZone = options.timeZone;
46
- var d = date instanceof Date ? date : new Date(date);
43
+ export function formatDate(date, options = {}) {
44
+ const { format = 'yyyy-MM-dd', locale, timeZone } = options;
45
+ const d = date instanceof Date ? date : new Date(date);
47
46
  // Custom formatter for common patterns
48
47
  if (format === 'yyyy-MM-dd') {
49
- var yyyy = d.getFullYear();
50
- var mm = String(d.getMonth() + 1).padStart(2, '0');
51
- var dd = String(d.getDate()).padStart(2, '0');
52
- return "".concat(yyyy, "-").concat(mm, "-").concat(dd);
48
+ const yyyy = d.getFullYear();
49
+ const mm = String(d.getMonth() + 1).padStart(2, '0');
50
+ const dd = String(d.getDate()).padStart(2, '0');
51
+ return `${yyyy}-${mm}-${dd}`;
53
52
  }
54
53
  if (format === 'yyyy-MM-dd HH:mm:ss') {
55
- var yyyy = d.getFullYear();
56
- var mm = String(d.getMonth() + 1).padStart(2, '0');
57
- var dd = String(d.getDate()).padStart(2, '0');
58
- var HH = String(d.getHours()).padStart(2, '0');
59
- var MM = String(d.getMinutes()).padStart(2, '0');
60
- var SS = String(d.getSeconds()).padStart(2, '0');
61
- return "".concat(yyyy, "-").concat(mm, "-").concat(dd, " ").concat(HH, ":").concat(MM, ":").concat(SS);
54
+ const yyyy = d.getFullYear();
55
+ const mm = String(d.getMonth() + 1).padStart(2, '0');
56
+ const dd = String(d.getDate()).padStart(2, '0');
57
+ const HH = String(d.getHours()).padStart(2, '0');
58
+ const MM = String(d.getMinutes()).padStart(2, '0');
59
+ const SS = String(d.getSeconds()).padStart(2, '0');
60
+ return `${yyyy}-${mm}-${dd} ${HH}:${MM}:${SS}`;
62
61
  }
63
62
  if (format === 'relative') {
64
63
  return formatRelativeTime(date);
65
64
  }
66
65
  // Fallback to Intl.DateTimeFormat for other formats
67
66
  return new Intl.DateTimeFormat(locale, {
68
- timeZone: timeZone,
67
+ timeZone,
69
68
  year: format.includes('yyyy') || format.includes('y') ? 'numeric' : undefined,
70
69
  month: format.includes('MM') || format.includes('M') ? 'numeric' : undefined,
71
70
  day: format.includes('dd') || format.includes('d') ? 'numeric' : undefined,
@@ -83,18 +82,17 @@ export function formatDate(date, options) {
83
82
  * @param locale - Locale to use for formatting
84
83
  * @returns Formatted relative time string
85
84
  */
86
- export function formatRelativeTime(date, now, locale) {
87
- if (now === void 0) { now = new Date(); }
88
- var d1 = date instanceof Date ? date : new Date(date);
89
- var d2 = now instanceof Date ? now : new Date(now);
90
- var diffMs = d1.getTime() - d2.getTime();
91
- var diffSecs = Math.round(diffMs / 1000);
92
- var diffMins = Math.round(diffSecs / 60);
93
- var diffHours = Math.round(diffMins / 60);
94
- var diffDays = Math.round(diffHours / 24);
95
- var diffMonths = Math.round(diffDays / 30);
96
- var diffYears = Math.round(diffDays / 365);
97
- var formatter = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });
85
+ export function formatRelativeTime(date, now = new Date(), locale) {
86
+ const d1 = date instanceof Date ? date : new Date(date);
87
+ const d2 = now instanceof Date ? now : new Date(now);
88
+ const diffMs = d1.getTime() - d2.getTime();
89
+ const diffSecs = Math.round(diffMs / 1000);
90
+ const diffMins = Math.round(diffSecs / 60);
91
+ const diffHours = Math.round(diffMins / 60);
92
+ const diffDays = Math.round(diffHours / 24);
93
+ const diffMonths = Math.round(diffDays / 30);
94
+ const diffYears = Math.round(diffDays / 365);
95
+ const formatter = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });
98
96
  if (Math.abs(diffSecs) < 60)
99
97
  return formatter.format(diffSecs, 'second');
100
98
  if (Math.abs(diffMins) < 60)
@@ -125,14 +123,14 @@ export function parseDate(input, fallback) {
125
123
  return new Date(input);
126
124
  }
127
125
  try {
128
- var date = new Date(input);
126
+ const date = new Date(input);
129
127
  // Check if date is valid
130
128
  if (isNaN(date.getTime())) {
131
129
  return fallback || null;
132
130
  }
133
131
  return date;
134
132
  }
135
- catch (_a) {
133
+ catch {
136
134
  return fallback || null;
137
135
  }
138
136
  }
@@ -153,12 +151,10 @@ export function parseDate(input, fallback) {
153
151
  * dateDiff(new Date('2023-05-15T10:00:00'), new Date('2023-05-15T06:00:00'), 'hours'); // 4
154
152
  * ```
155
153
  */
156
- export function dateDiff(date1, date2, unit) {
157
- if (date2 === void 0) { date2 = new Date(); }
158
- if (unit === void 0) { unit = 'days'; }
159
- var d1 = date1 instanceof Date ? date1 : new Date(date1);
160
- var d2 = date2 instanceof Date ? date2 : new Date(date2);
161
- var diffMs = d1.getTime() - d2.getTime();
154
+ export function dateDiff(date1, date2 = new Date(), unit = 'days') {
155
+ const d1 = date1 instanceof Date ? date1 : new Date(date1);
156
+ const d2 = date2 instanceof Date ? date2 : new Date(date2);
157
+ const diffMs = d1.getTime() - d2.getTime();
162
158
  switch (unit) {
163
159
  case 'milliseconds':
164
160
  return diffMs;
@@ -175,7 +171,7 @@ export function dateDiff(date1, date2, unit) {
175
171
  case 'years':
176
172
  return d1.getFullYear() - d2.getFullYear();
177
173
  default:
178
- throw new Error("Unsupported unit: ".concat(unit));
174
+ throw new Error(`Unsupported unit: ${unit}`);
179
175
  }
180
176
  }
181
177
  /**
@@ -196,7 +192,7 @@ export function dateDiff(date1, date2, unit) {
196
192
  * ```
197
193
  */
198
194
  export function addToDate(date, amount, unit) {
199
- var d = date instanceof Date ? new Date(date) : new Date(date);
195
+ const d = date instanceof Date ? new Date(date) : new Date(date);
200
196
  switch (unit) {
201
197
  case 'milliseconds':
202
198
  d.setMilliseconds(d.getMilliseconds() + amount);
@@ -214,11 +210,11 @@ export function addToDate(date, amount, unit) {
214
210
  d.setDate(d.getDate() + amount);
215
211
  break;
216
212
  case 'months': {
217
- var origDate = d.getDate();
218
- var origMonth = d.getMonth();
213
+ const origDate = d.getDate();
214
+ const origMonth = d.getMonth();
219
215
  d.setDate(1); // Prevent overflow
220
216
  d.setMonth(origMonth + amount);
221
- var lastDay = new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
217
+ const lastDay = new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
222
218
  d.setDate(Math.min(origDate, lastDay));
223
219
  break;
224
220
  }
@@ -226,7 +222,7 @@ export function addToDate(date, amount, unit) {
226
222
  d.setFullYear(d.getFullYear() + amount);
227
223
  break;
228
224
  default:
229
- throw new Error("Unsupported unit: ".concat(unit));
225
+ throw new Error(`Unsupported unit: ${unit}`);
230
226
  }
231
227
  return d;
232
228
  }
@@ -247,7 +243,7 @@ export function addToDate(date, amount, unit) {
247
243
  * ```
248
244
  */
249
245
  export function startOf(date, unit) {
250
- var d = date instanceof Date ? new Date(date) : new Date(date);
246
+ const d = date instanceof Date ? new Date(date) : new Date(date);
251
247
  switch (unit) {
252
248
  case 'second':
253
249
  d.setMilliseconds(0);
@@ -278,7 +274,7 @@ export function startOf(date, unit) {
278
274
  d.setHours(0, 0, 0, 0);
279
275
  break;
280
276
  default:
281
- throw new Error("Unsupported unit: ".concat(unit));
277
+ throw new Error(`Unsupported unit: ${unit}`);
282
278
  }
283
279
  return d;
284
280
  }
@@ -299,7 +295,7 @@ export function startOf(date, unit) {
299
295
  * ```
300
296
  */
301
297
  export function endOf(date, unit) {
302
- var d = date instanceof Date ? new Date(date) : new Date(date);
298
+ const d = date instanceof Date ? new Date(date) : new Date(date);
303
299
  switch (unit) {
304
300
  case 'second':
305
301
  d.setMilliseconds(999);
@@ -330,7 +326,7 @@ export function endOf(date, unit) {
330
326
  d.setHours(23, 59, 59, 999);
331
327
  break;
332
328
  default:
333
- throw new Error("Unsupported unit: ".concat(unit));
329
+ throw new Error(`Unsupported unit: ${unit}`);
334
330
  }
335
331
  return d;
336
332
  }
@@ -352,11 +348,10 @@ export function endOf(date, unit) {
352
348
  * isBetween(date, start, end); // true
353
349
  * ```
354
350
  */
355
- export function isBetween(date, start, end, inclusive) {
356
- if (inclusive === void 0) { inclusive = true; }
357
- var d = date instanceof Date ? date.getTime() : date;
358
- var s = start instanceof Date ? start.getTime() : start;
359
- var e = end instanceof Date ? end.getTime() : end;
351
+ export function isBetween(date, start, end, inclusive = true) {
352
+ const d = date instanceof Date ? date.getTime() : date;
353
+ const s = start instanceof Date ? start.getTime() : start;
354
+ const e = end instanceof Date ? end.getTime() : end;
360
355
  return inclusive ? d >= s && d <= e : d > s && d < e;
361
356
  }
362
357
  /**
@@ -366,7 +361,7 @@ export function isBetween(date, start, end, inclusive) {
366
361
  * @returns True if the year is a leap year
367
362
  */
368
363
  export function isLeapYear(year) {
369
- var y = year instanceof Date ? year.getFullYear() : year;
364
+ const y = year instanceof Date ? year.getFullYear() : year;
370
365
  return (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0;
371
366
  }
372
367
  /**
@@ -386,4 +381,3 @@ export function daysInMonth(year, month) {
386
381
  }
387
382
  return new Date(year, month + 1, 0).getDate();
388
383
  }
389
- //# sourceMappingURL=date.utils.js.map