@chopkola/common 1.0.12 → 1.0.13
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const convertStringDurationToMs: (value: string) => number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertStringDurationToMs = void 0;
|
|
4
|
+
const validators_1 = require("../validators");
|
|
5
|
+
const convertStringDurationToMs = (value) => {
|
|
6
|
+
const match = value.match(validators_1.stringDurationToMsRegex);
|
|
7
|
+
if (!match) {
|
|
8
|
+
throw new Error(`Invalid duration format: ${value}`);
|
|
9
|
+
}
|
|
10
|
+
const amount = parseInt(match[1], 10);
|
|
11
|
+
const unit = match[2].toLowerCase();
|
|
12
|
+
const unitMap = {
|
|
13
|
+
ms: 1,
|
|
14
|
+
s: 1000,
|
|
15
|
+
m: 1000 * 60,
|
|
16
|
+
h: 1000 * 60 * 60,
|
|
17
|
+
d: 1000 * 60 * 60 * 24,
|
|
18
|
+
w: 1000 * 60 * 60 * 24 * 7,
|
|
19
|
+
y: 1000 * 60 * 60 * 24 * 365,
|
|
20
|
+
};
|
|
21
|
+
return amount * unitMap[unit];
|
|
22
|
+
};
|
|
23
|
+
exports.convertStringDurationToMs = convertStringDurationToMs;
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -21,3 +21,4 @@ __exportStar(require("./types/enum/global"), exports);
|
|
|
21
21
|
__exportStar(require("./types/global"), exports);
|
|
22
22
|
__exportStar(require("./types/errors/index"), exports);
|
|
23
23
|
__exportStar(require("./validators/index"), exports);
|
|
24
|
+
__exportStar(require("./helpers/helpers"), exports);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.phoneNumberRegex = exports.emailRegex = void 0;
|
|
3
|
+
exports.stringDurationToMsRegex = exports.phoneNumberRegex = exports.emailRegex = void 0;
|
|
4
4
|
exports.emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
5
5
|
exports.phoneNumberRegex = /^(?:\+234|234|0)(7[0-9]|8[01]|9[01])\d{8}$/;
|
|
6
|
+
exports.stringDurationToMsRegex = /^(\d+)\s*(ms|s|m|h|d|w|y)$/i;
|