@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
@@ -5,3 +5,4 @@ export * from './types/enum/global';
5
5
  export * from './types/global';
6
6
  export * from './types/errors/index';
7
7
  export * from './validators/index';
8
+ export * from './helpers/helpers';
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,2 +1,3 @@
1
1
  export declare const emailRegex: RegExp;
2
2
  export declare const phoneNumberRegex: RegExp;
3
+ export declare const stringDurationToMsRegex: RegExp;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chopkola/common",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "akrosoft technology ltd",