@catbee/utils 0.0.8-rc.0 → 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.
- package/README.md +25 -1
- package/build/esm/config.d.ts +0 -1
- package/build/esm/config.js +6 -7
- package/build/esm/index.d.ts +0 -1
- package/build/esm/index.js +0 -1
- package/build/esm/servers/server.builder.d.ts +0 -1
- package/build/esm/servers/server.builder.js +99 -147
- package/build/esm/servers/server.d.ts +0 -1
- package/build/esm/servers/server.js +591 -876
- package/build/esm/types/api-response.d.ts +0 -1
- package/build/esm/types/api-response.js +0 -1
- package/build/esm/types/index.d.ts +0 -1
- package/build/esm/types/index.js +0 -1
- package/build/esm/types/server.d.ts +0 -1
- package/build/esm/types/server.js +0 -1
- package/build/esm/utils/array.utils.d.ts +0 -1
- package/build/esm/utils/array.utils.js +48 -86
- package/build/esm/utils/async.utils.d.ts +0 -1
- package/build/esm/utils/async.utils.js +247 -524
- package/build/esm/utils/cache.utils.d.ts +0 -1
- package/build/esm/utils/cache.utils.js +96 -301
- package/build/esm/utils/context-store.utils.d.ts +0 -1
- package/build/esm/utils/context-store.utils.js +62 -79
- package/build/esm/utils/crypto.utils.d.ts +0 -1
- package/build/esm/utils/crypto.utils.js +78 -175
- package/build/esm/utils/date.utils.d.ts +0 -1
- package/build/esm/utils/date.utils.js +47 -53
- package/build/esm/utils/decorators.utils.d.ts +201 -5
- package/build/esm/utils/decorators.utils.js +632 -285
- package/build/esm/utils/dir.utils.d.ts +0 -1
- package/build/esm/utils/dir.utils.js +264 -786
- package/build/esm/utils/env.utils.d.ts +0 -1
- package/build/esm/utils/env.utils.js +180 -271
- package/build/esm/utils/exception.utils.d.ts +0 -1
- package/build/esm/utils/exception.utils.js +112 -289
- package/build/esm/utils/fs.utils.d.ts +0 -1
- package/build/esm/utils/fs.utils.js +169 -401
- package/build/esm/utils/http-status-codes.d.ts +0 -1
- package/build/esm/utils/http-status-codes.js +0 -1
- package/build/esm/utils/id.utils.d.ts +0 -1
- package/build/esm/utils/id.utils.js +5 -9
- package/build/esm/utils/logger.utils.d.ts +0 -1
- package/build/esm/utils/logger.utils.js +34 -71
- package/build/esm/utils/middleware.utils.d.ts +0 -1
- package/build/esm/utils/middleware.utils.js +65 -155
- package/build/esm/utils/obj.utils.d.ts +0 -1
- package/build/esm/utils/obj.utils.js +69 -176
- package/build/esm/utils/performance.utils.d.ts +0 -1
- package/build/esm/utils/performance.utils.js +92 -195
- package/build/esm/utils/request.utils.d.ts +0 -1
- package/build/esm/utils/request.utils.js +41 -74
- package/build/esm/utils/response.utils.d.ts +0 -1
- package/build/esm/utils/response.utils.js +84 -107
- package/build/esm/utils/stream.utils.d.ts +0 -1
- package/build/esm/utils/stream.utils.js +38 -113
- package/build/esm/utils/string.utils.d.ts +0 -1
- package/build/esm/utils/string.utils.js +6 -11
- package/build/esm/utils/type.utils.d.ts +0 -1
- package/build/esm/utils/type.utils.js +8 -12
- package/build/esm/utils/url.utils.d.ts +0 -1
- package/build/esm/utils/url.utils.js +49 -127
- package/build/esm/utils/validate.utils.d.ts +0 -1
- package/build/esm/utils/validate.utils.js +23 -40
- package/package.json +3 -33
- package/build/esm/config.js.map +0 -1
- package/build/esm/index.js.map +0 -1
- package/build/esm/servers/server.builder.js.map +0 -1
- package/build/esm/servers/server.js.map +0 -1
- package/build/esm/types/api-response.js.map +0 -1
- package/build/esm/types/index.js.map +0 -1
- package/build/esm/types/server.js.map +0 -1
- package/build/esm/utils/array.utils.js.map +0 -1
- package/build/esm/utils/async.utils.js.map +0 -1
- package/build/esm/utils/cache.utils.js.map +0 -1
- package/build/esm/utils/context-store.utils.js.map +0 -1
- package/build/esm/utils/crypto.utils.js.map +0 -1
- package/build/esm/utils/date.utils.js.map +0 -1
- package/build/esm/utils/decorators.utils.js.map +0 -1
- package/build/esm/utils/dir.utils.js.map +0 -1
- package/build/esm/utils/env.utils.js.map +0 -1
- package/build/esm/utils/exception.utils.js.map +0 -1
- package/build/esm/utils/fs.utils.js.map +0 -1
- package/build/esm/utils/http-status-codes.js.map +0 -1
- package/build/esm/utils/id.utils.js.map +0 -1
- package/build/esm/utils/logger.utils.js.map +0 -1
- package/build/esm/utils/middleware.utils.js.map +0 -1
- package/build/esm/utils/obj.utils.js.map +0 -1
- package/build/esm/utils/performance.utils.js.map +0 -1
- package/build/esm/utils/request.utils.js.map +0 -1
- package/build/esm/utils/response.utils.js.map +0 -1
- package/build/esm/utils/stream.utils.js.map +0 -1
- package/build/esm/utils/string.utils.js.map +0 -1
- package/build/esm/utils/type.utils.js.map +0 -1
- package/build/esm/utils/url.utils.js.map +0 -1
- package/build/esm/utils/validate.utils.js.map +0 -1
- package/build/esnext/config.d.ts +0 -122
- package/build/esnext/config.js +0 -133
- package/build/esnext/config.js.map +0 -1
- package/build/esnext/index.d.ts +0 -27
- package/build/esnext/index.js +0 -50
- package/build/esnext/index.js.map +0 -1
- package/build/esnext/servers/server.builder.d.ts +0 -508
- package/build/esnext/servers/server.builder.js +0 -657
- package/build/esnext/servers/server.builder.js.map +0 -1
- package/build/esnext/servers/server.d.ts +0 -256
- package/build/esnext/servers/server.js +0 -955
- package/build/esnext/servers/server.js.map +0 -1
- package/build/esnext/types/api-response.d.ts +0 -152
- package/build/esnext/types/api-response.js +0 -34
- package/build/esnext/types/api-response.js.map +0 -1
- package/build/esnext/types/index.d.ts +0 -125
- package/build/esnext/types/index.js +0 -25
- package/build/esnext/types/index.js.map +0 -1
- package/build/esnext/types/server.d.ts +0 -268
- package/build/esnext/types/server.js +0 -25
- package/build/esnext/types/server.js.map +0 -1
- package/build/esnext/utils/array.utils.d.ts +0 -168
- package/build/esnext/utils/array.utils.js +0 -345
- package/build/esnext/utils/array.utils.js.map +0 -1
- package/build/esnext/utils/async.utils.d.ts +0 -265
- package/build/esnext/utils/async.utils.js +0 -620
- package/build/esnext/utils/async.utils.js.map +0 -1
- package/build/esnext/utils/cache.utils.d.ts +0 -153
- package/build/esnext/utils/cache.utils.js +0 -293
- package/build/esnext/utils/cache.utils.js.map +0 -1
- package/build/esnext/utils/context-store.utils.d.ts +0 -189
- package/build/esnext/utils/context-store.utils.js +0 -289
- package/build/esnext/utils/context-store.utils.js.map +0 -1
- package/build/esnext/utils/crypto.utils.d.ts +0 -160
- package/build/esnext/utils/crypto.utils.js +0 -276
- package/build/esnext/utils/crypto.utils.js.map +0 -1
- package/build/esnext/utils/date.utils.d.ts +0 -159
- package/build/esnext/utils/date.utils.js +0 -384
- package/build/esnext/utils/date.utils.js.map +0 -1
- package/build/esnext/utils/decorators.utils.d.ts +0 -315
- package/build/esnext/utils/decorators.utils.js +0 -504
- package/build/esnext/utils/decorators.utils.js.map +0 -1
- package/build/esnext/utils/dir.utils.d.ts +0 -196
- package/build/esnext/utils/dir.utils.js +0 -477
- package/build/esnext/utils/dir.utils.js.map +0 -1
- package/build/esnext/utils/env.utils.d.ts +0 -377
- package/build/esnext/utils/env.utils.js +0 -785
- package/build/esnext/utils/env.utils.js.map +0 -1
- package/build/esnext/utils/exception.utils.d.ts +0 -230
- package/build/esnext/utils/exception.utils.js +0 -381
- package/build/esnext/utils/exception.utils.js.map +0 -1
- package/build/esnext/utils/fs.utils.d.ts +0 -164
- package/build/esnext/utils/fs.utils.js +0 -349
- package/build/esnext/utils/fs.utils.js.map +0 -1
- package/build/esnext/utils/http-status-codes.d.ts +0 -266
- package/build/esnext/utils/http-status-codes.js +0 -295
- package/build/esnext/utils/http-status-codes.js.map +0 -1
- package/build/esnext/utils/id.utils.d.ts +0 -36
- package/build/esnext/utils/id.utils.js +0 -84
- package/build/esnext/utils/id.utils.js.map +0 -1
- package/build/esnext/utils/logger.utils.d.ts +0 -160
- package/build/esnext/utils/logger.utils.js +0 -300
- package/build/esnext/utils/logger.utils.js.map +0 -1
- package/build/esnext/utils/middleware.utils.d.ts +0 -100
- package/build/esnext/utils/middleware.utils.js +0 -236
- package/build/esnext/utils/middleware.utils.js.map +0 -1
- package/build/esnext/utils/obj.utils.d.ts +0 -124
- package/build/esnext/utils/obj.utils.js +0 -413
- package/build/esnext/utils/obj.utils.js.map +0 -1
- package/build/esnext/utils/performance.utils.d.ts +0 -136
- package/build/esnext/utils/performance.utils.js +0 -271
- package/build/esnext/utils/performance.utils.js.map +0 -1
- package/build/esnext/utils/request.utils.d.ts +0 -86
- package/build/esnext/utils/request.utils.js +0 -186
- package/build/esnext/utils/request.utils.js.map +0 -1
- package/build/esnext/utils/response.utils.d.ts +0 -163
- package/build/esnext/utils/response.utils.js +0 -247
- package/build/esnext/utils/response.utils.js.map +0 -1
- package/build/esnext/utils/stream.utils.d.ts +0 -88
- package/build/esnext/utils/stream.utils.js +0 -210
- package/build/esnext/utils/stream.utils.js.map +0 -1
- package/build/esnext/utils/string.utils.d.ts +0 -93
- package/build/esnext/utils/string.utils.js +0 -165
- package/build/esnext/utils/string.utils.js.map +0 -1
- package/build/esnext/utils/type.utils.d.ts +0 -90
- package/build/esnext/utils/type.utils.js +0 -187
- package/build/esnext/utils/type.utils.js.map +0 -1
- package/build/esnext/utils/url.utils.d.ts +0 -141
- package/build/esnext/utils/url.utils.js +0 -304
- package/build/esnext/utils/url.utils.js.map +0 -1
- package/build/esnext/utils/validate.utils.d.ts +0 -177
- package/build/esnext/utils/validate.utils.js +0 -320
- package/build/esnext/utils/validate.utils.js.map +0 -1
- package/build/src/config.d.ts +0 -122
- package/build/src/config.js +0 -138
- package/build/src/config.js.map +0 -1
- package/build/src/index.d.ts +0 -27
- package/build/src/index.js +0 -69
- package/build/src/index.js.map +0 -1
- package/build/src/servers/server.builder.d.ts +0 -508
- package/build/src/servers/server.builder.js +0 -661
- package/build/src/servers/server.builder.js.map +0 -1
- package/build/src/servers/server.d.ts +0 -256
- package/build/src/servers/server.js +0 -962
- package/build/src/servers/server.js.map +0 -1
- package/build/src/types/api-response.d.ts +0 -152
- package/build/src/types/api-response.js +0 -37
- package/build/src/types/api-response.js.map +0 -1
- package/build/src/types/index.d.ts +0 -125
- package/build/src/types/index.js +0 -26
- package/build/src/types/index.js.map +0 -1
- package/build/src/types/server.d.ts +0 -268
- package/build/src/types/server.js +0 -26
- package/build/src/types/server.js.map +0 -1
- package/build/src/utils/array.utils.d.ts +0 -168
- package/build/src/utils/array.utils.js +0 -364
- package/build/src/utils/array.utils.js.map +0 -1
- package/build/src/utils/async.utils.d.ts +0 -265
- package/build/src/utils/async.utils.js +0 -641
- package/build/src/utils/async.utils.js.map +0 -1
- package/build/src/utils/cache.utils.d.ts +0 -153
- package/build/src/utils/cache.utils.js +0 -297
- package/build/src/utils/cache.utils.js.map +0 -1
- package/build/src/utils/context-store.utils.d.ts +0 -189
- package/build/src/utils/context-store.utils.js +0 -296
- package/build/src/utils/context-store.utils.js.map +0 -1
- package/build/src/utils/crypto.utils.d.ts +0 -160
- package/build/src/utils/crypto.utils.js +0 -293
- package/build/src/utils/crypto.utils.js.map +0 -1
- package/build/src/utils/date.utils.d.ts +0 -159
- package/build/src/utils/date.utils.js +0 -396
- package/build/src/utils/date.utils.js.map +0 -1
- package/build/src/utils/decorators.utils.d.ts +0 -315
- package/build/src/utils/decorators.utils.js +0 -516
- package/build/src/utils/decorators.utils.js.map +0 -1
- package/build/src/utils/dir.utils.d.ts +0 -196
- package/build/src/utils/dir.utils.js +0 -501
- package/build/src/utils/dir.utils.js.map +0 -1
- package/build/src/utils/env.utils.d.ts +0 -377
- package/build/src/utils/env.utils.js +0 -789
- package/build/src/utils/env.utils.js.map +0 -1
- package/build/src/utils/exception.utils.d.ts +0 -230
- package/build/src/utils/exception.utils.js +0 -407
- package/build/src/utils/exception.utils.js.map +0 -1
- package/build/src/utils/fs.utils.d.ts +0 -164
- package/build/src/utils/fs.utils.js +0 -372
- package/build/src/utils/fs.utils.js.map +0 -1
- package/build/src/utils/http-status-codes.d.ts +0 -266
- package/build/src/utils/http-status-codes.js +0 -298
- package/build/src/utils/http-status-codes.js.map +0 -1
- package/build/src/utils/id.utils.d.ts +0 -36
- package/build/src/utils/id.utils.js +0 -91
- package/build/src/utils/id.utils.js.map +0 -1
- package/build/src/utils/logger.utils.d.ts +0 -160
- package/build/src/utils/logger.utils.js +0 -346
- package/build/src/utils/logger.utils.js.map +0 -1
- package/build/src/utils/middleware.utils.d.ts +0 -100
- package/build/src/utils/middleware.utils.js +0 -244
- package/build/src/utils/middleware.utils.js.map +0 -1
- package/build/src/utils/obj.utils.d.ts +0 -124
- package/build/src/utils/obj.utils.js +0 -429
- package/build/src/utils/obj.utils.js.map +0 -1
- package/build/src/utils/performance.utils.d.ts +0 -136
- package/build/src/utils/performance.utils.js +0 -278
- package/build/src/utils/performance.utils.js.map +0 -1
- package/build/src/utils/request.utils.d.ts +0 -86
- package/build/src/utils/request.utils.js +0 -195
- package/build/src/utils/request.utils.js.map +0 -1
- package/build/src/utils/response.utils.d.ts +0 -163
- package/build/src/utils/response.utils.js +0 -260
- package/build/src/utils/response.utils.js.map +0 -1
- package/build/src/utils/stream.utils.d.ts +0 -88
- package/build/src/utils/stream.utils.js +0 -218
- package/build/src/utils/stream.utils.js.map +0 -1
- package/build/src/utils/string.utils.d.ts +0 -93
- package/build/src/utils/string.utils.js +0 -179
- package/build/src/utils/string.utils.js.map +0 -1
- package/build/src/utils/type.utils.d.ts +0 -90
- package/build/src/utils/type.utils.js +0 -196
- package/build/src/utils/type.utils.js.map +0 -1
- package/build/src/utils/url.utils.d.ts +0 -141
- package/build/src/utils/url.utils.js +0 -317
- package/build/src/utils/url.utils.js.map +0 -1
- package/build/src/utils/validate.utils.d.ts +0 -177
- package/build/src/utils/validate.utils.js +0 -345
- 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
|
-
|
|
195
|
-
|
|
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 ?
|
|
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
|
-
|
|
213
|
-
|
|
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
|
-
|
|
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(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
236
|
+
const tokenPayload = {
|
|
237
|
+
...payload,
|
|
238
|
+
exp: Math.floor(Date.now() / 1000) + expiresInSeconds
|
|
239
|
+
};
|
|
336
240
|
// Convert to string
|
|
337
|
-
|
|
241
|
+
const payloadStr = JSON.stringify(tokenPayload);
|
|
338
242
|
// Base64 encode the payload
|
|
339
|
-
|
|
243
|
+
const base64Payload = Buffer.from(payloadStr).toString('base64url');
|
|
340
244
|
// Create signature
|
|
341
|
-
|
|
245
|
+
const signature = hmac('sha256', base64Payload, secret, 'base64url');
|
|
342
246
|
// Combine payload and signature
|
|
343
|
-
return
|
|
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
|
-
|
|
259
|
+
const [payloadB64, signature] = token.split('.');
|
|
356
260
|
if (!payloadB64 || !signature)
|
|
357
261
|
return null;
|
|
358
262
|
// Verify signature
|
|
359
|
-
|
|
263
|
+
const expectedSignature = hmac('sha256', payloadB64, secret, 'base64url');
|
|
360
264
|
if (!safeCompare(signature, expectedSignature))
|
|
361
265
|
return null;
|
|
362
266
|
// Decode payload
|
|
363
|
-
|
|
364
|
-
|
|
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
|
|
275
|
+
catch {
|
|
372
276
|
return null;
|
|
373
277
|
}
|
|
374
278
|
}
|
|
375
|
-
//# sourceMappingURL=crypto.utils.js.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
|
-
|
|
45
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return
|
|
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
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
218
|
-
|
|
213
|
+
const origDate = d.getDate();
|
|
214
|
+
const origMonth = d.getMonth();
|
|
219
215
|
d.setDate(1); // Prevent overflow
|
|
220
216
|
d.setMonth(origMonth + amount);
|
|
221
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
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
|