@alwatr/parse-duration 5.5.30 → 6.0.0

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/dist/main.js ADDED
@@ -0,0 +1,5 @@
1
+ /* 📦 @alwatr/parse-duration v6.0.0 */
2
+ import{toNumber as A}from"@alwatr/is-number";var z=Object.freeze({s:1000,m:60000,h:3600000,d:86400000,w:604800000,M:2592000000,y:31536000000}),D=(h,k)=>{let j;if(typeof h==="number")j=h;else{if(h.length<2)throw Error("invalid_format",{cause:{duration:h}});let q=h.slice(-1),x=z[q];if(x===void 0)throw Error("invalid_unit",{cause:{durationUnit:q}});let y=A(h.slice(0,-1));if(y===null)throw Error("not_a_number",{cause:{duration:h}});j=y*x}if(k===void 0)return j;let p=z[k];if(p===void 0)throw Error("invalid_unit",{cause:{toUnit:k}});return j/p};export{D as parseDuration};
3
+
4
+ //# debugId=1C5D6051084B13EC64756E2164756E21
5
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/main.ts"],
4
+ "sourcesContent": [
5
+ "import {toNumber} from '@alwatr/is-number';\n\n/**\n * Unit conversion table (milliseconds)\n */\nconst unitConversion = Object.freeze({\n s: 1_000,\n m: 60_000,\n h: 3_600_000,\n d: 86_400_000,\n w: 604_800_000,\n M: 2_592_000_000,\n y: 31_536_000_000,\n} as const);\n\n/**\n * Duration unit: `s` for seconds, `m` for minutes, `h` for hours, `d` for days, `w` for weeks, `M` for months, `y` for years.\n */\nexport type DurationUnit = keyof typeof unitConversion;\n\n/**\n * Duration string format: `number + unit`, for example `10m` means 10 minutes.\n */\nexport type Duration = `${number}${DurationUnit}` | number;\n\n/**\n * Error types that can be thrown by parseDuration\n */\nexport type DurationError = 'not_a_number' | 'invalid_unit' | 'invalid_format';\n\n/**\n * Parse duration string to milliseconds number.\n *\n * @param duration - Duration string or number, for example `10m` means 10 minutes.\n * @param toUnit - Convert to unit, default is `ms` for milliseconds.\n * @throws {Error} With message 'not_a_number' if duration string doesn't contain a valid number.\n * @throws {Error} With message 'invalid_unit' if the unit is not recognized.\n * @throws {Error} With message 'invalid_format' if the duration format is invalid.\n * @returns Duration in specified unit (or milliseconds by default).\n *\n * @example\n * ```ts\n * parseDuration('10m'); // 600000\n * parseDuration('10m', 's'); // 600\n * parseDuration(120_000, 'm'); // 2\n * ```\n */\nexport const parseDuration = (duration: Duration, toUnit?: DurationUnit): number => {\n let ms: number;\n\n // Convert input to milliseconds\n if (typeof duration === 'number') {\n ms = duration;\n }\n else {\n if (duration.length < 2) {\n throw new Error('invalid_format', {cause: {duration}});\n }\n\n const durationUnit = duration.slice(-1) as DurationUnit;\n const unitConversionFactor = unitConversion[durationUnit];\n\n if (unitConversionFactor === undefined) {\n throw new Error('invalid_unit', {cause: {durationUnit}});\n }\n\n const durationNumber = toNumber(duration.slice(0, -1));\n if (durationNumber === null) {\n throw new Error('not_a_number', {cause: {duration}});\n }\n\n ms = durationNumber * unitConversionFactor;\n }\n\n // Return as is if no conversion needed\n if (toUnit === undefined) {\n return ms;\n }\n\n // Convert to target unit\n const toFactor = unitConversion[toUnit];\n if (toFactor === undefined) {\n throw new Error('invalid_unit', {cause: {toUnit}});\n }\n\n return ms / toFactor;\n};\n"
6
+ ],
7
+ "mappings": ";AAAA,mBAAQ,0BAKR,IAAM,EAAiB,OAAO,OAAO,CACnC,EAAG,KACH,EAAG,MACH,EAAG,QACH,EAAG,SACH,EAAG,UACH,EAAG,WACH,EAAG,WACL,CAAU,EAkCG,EAAgB,CAAC,EAAoB,IAAkC,CAClF,IAAI,EAGJ,GAAI,OAAO,IAAa,SACtB,EAAK,EAEF,KACH,GAAI,EAAS,OAAS,EACpB,MAAU,MAAM,iBAAkB,CAAC,MAAO,CAAC,UAAQ,CAAC,CAAC,EAGvD,IAAM,EAAe,EAAS,MAAM,EAAE,EAChC,EAAuB,EAAe,GAE5C,GAAI,IAAyB,OAC3B,MAAU,MAAM,eAAgB,CAAC,MAAO,CAAC,cAAY,CAAC,CAAC,EAGzD,IAAM,EAAiB,EAAS,EAAS,MAAM,EAAG,EAAE,CAAC,EACrD,GAAI,IAAmB,KACrB,MAAU,MAAM,eAAgB,CAAC,MAAO,CAAC,UAAQ,CAAC,CAAC,EAGrD,EAAK,EAAiB,EAIxB,GAAI,IAAW,OACb,OAAO,EAIT,IAAM,EAAW,EAAe,GAChC,GAAI,IAAa,OACf,MAAU,MAAM,eAAgB,CAAC,MAAO,CAAC,QAAM,CAAC,CAAC,EAGnD,OAAO,EAAK",
8
+ "debugId": "1C5D6051084B13EC64756E2164756E21",
9
+ "names": []
10
+ }
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
2
  "name": "@alwatr/parse-duration",
3
3
  "description": "A simple utility to parse a duration string into milliseconds number.",
4
- "version": "5.5.30",
4
+ "version": "6.0.0",
5
5
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
6
  "bugs": "https://github.com/Alwatr/nanolib/issues",
7
7
  "dependencies": {
8
- "@alwatr/is-number": "5.7.26"
8
+ "@alwatr/is-number": "6.0.0"
9
9
  },
10
10
  "devDependencies": {
11
- "@alwatr/nano-build": "6.4.2",
12
- "@alwatr/prettier-config": "6.0.2",
13
- "@alwatr/tsconfig-base": "6.0.4",
11
+ "@alwatr/nano-build": "7.0.0",
12
+ "@alwatr/prettier-config": "7.0.0",
13
+ "@alwatr/tsconfig-base": "7.0.0",
14
14
  "typescript": "^5.9.3"
15
15
  },
16
16
  "exports": {
17
17
  ".": {
18
18
  "types": "./dist/main.d.ts",
19
- "import": "./dist/main.mjs",
20
- "require": "./dist/main.cjs"
19
+ "default": "./dist/main.js"
21
20
  }
22
21
  },
23
22
  "files": [
24
- "**/*.{js,mjs,cjs,map,d.ts,html,md,LEGAL.txt}",
23
+ "**/*.{js,mjs,cjs,ts,map,d.ts,html,LEGAL.txt}",
24
+ "README.md",
25
25
  "LICENSE",
26
26
  "!demo/**/*",
27
27
  "!**/*.test.js"
@@ -48,8 +48,6 @@
48
48
  "utils"
49
49
  ],
50
50
  "license": "MPL-2.0",
51
- "main": "./dist/main.cjs",
52
- "module": "./dist/main.mjs",
53
51
  "prettier": "@alwatr/prettier-config",
54
52
  "publishConfig": {
55
53
  "access": "public"
@@ -62,14 +60,14 @@
62
60
  "scripts": {
63
61
  "b": "bun run build",
64
62
  "build": "bun run build:ts && bun run build:es",
65
- "build:es": "nano-build --preset=module",
63
+ "build:es": "nano-build --preset=module src/main.ts",
66
64
  "build:ts": "tsc --build",
67
65
  "c": "bun run clean",
68
66
  "cb": "bun run clean && bun run build",
69
67
  "clean": "rm -rfv dist *.tsbuildinfo",
70
- "d": "bun run build:es && bun --enable-source-maps --trace-warnings",
68
+ "d": "bun run build:es && bun",
71
69
  "t": "bun run test",
72
- "test": "echo test-skipped",
70
+ "test": "bun test",
73
71
  "w": "bun run watch",
74
72
  "watch": "bun run watch:ts & bun run watch:es",
75
73
  "watch:es": "bun run build:es --watch",
@@ -78,5 +76,5 @@
78
76
  "sideEffects": false,
79
77
  "type": "module",
80
78
  "types": "./dist/main.d.ts",
81
- "gitHead": "c3889e3756b0a0f9b935a1b702a1373ac52cb379"
79
+ "gitHead": "056102a1c8a563bbae8a290b6830450f467322a3"
82
80
  }
package/src/main.ts ADDED
@@ -0,0 +1,87 @@
1
+ import {toNumber} from '@alwatr/is-number';
2
+
3
+ /**
4
+ * Unit conversion table (milliseconds)
5
+ */
6
+ const unitConversion = Object.freeze({
7
+ s: 1_000,
8
+ m: 60_000,
9
+ h: 3_600_000,
10
+ d: 86_400_000,
11
+ w: 604_800_000,
12
+ M: 2_592_000_000,
13
+ y: 31_536_000_000,
14
+ } as const);
15
+
16
+ /**
17
+ * Duration unit: `s` for seconds, `m` for minutes, `h` for hours, `d` for days, `w` for weeks, `M` for months, `y` for years.
18
+ */
19
+ export type DurationUnit = keyof typeof unitConversion;
20
+
21
+ /**
22
+ * Duration string format: `number + unit`, for example `10m` means 10 minutes.
23
+ */
24
+ export type Duration = `${number}${DurationUnit}` | number;
25
+
26
+ /**
27
+ * Error types that can be thrown by parseDuration
28
+ */
29
+ export type DurationError = 'not_a_number' | 'invalid_unit' | 'invalid_format';
30
+
31
+ /**
32
+ * Parse duration string to milliseconds number.
33
+ *
34
+ * @param duration - Duration string or number, for example `10m` means 10 minutes.
35
+ * @param toUnit - Convert to unit, default is `ms` for milliseconds.
36
+ * @throws {Error} With message 'not_a_number' if duration string doesn't contain a valid number.
37
+ * @throws {Error} With message 'invalid_unit' if the unit is not recognized.
38
+ * @throws {Error} With message 'invalid_format' if the duration format is invalid.
39
+ * @returns Duration in specified unit (or milliseconds by default).
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * parseDuration('10m'); // 600000
44
+ * parseDuration('10m', 's'); // 600
45
+ * parseDuration(120_000, 'm'); // 2
46
+ * ```
47
+ */
48
+ export const parseDuration = (duration: Duration, toUnit?: DurationUnit): number => {
49
+ let ms: number;
50
+
51
+ // Convert input to milliseconds
52
+ if (typeof duration === 'number') {
53
+ ms = duration;
54
+ }
55
+ else {
56
+ if (duration.length < 2) {
57
+ throw new Error('invalid_format', {cause: {duration}});
58
+ }
59
+
60
+ const durationUnit = duration.slice(-1) as DurationUnit;
61
+ const unitConversionFactor = unitConversion[durationUnit];
62
+
63
+ if (unitConversionFactor === undefined) {
64
+ throw new Error('invalid_unit', {cause: {durationUnit}});
65
+ }
66
+
67
+ const durationNumber = toNumber(duration.slice(0, -1));
68
+ if (durationNumber === null) {
69
+ throw new Error('not_a_number', {cause: {duration}});
70
+ }
71
+
72
+ ms = durationNumber * unitConversionFactor;
73
+ }
74
+
75
+ // Return as is if no conversion needed
76
+ if (toUnit === undefined) {
77
+ return ms;
78
+ }
79
+
80
+ // Convert to target unit
81
+ const toFactor = unitConversion[toUnit];
82
+ if (toFactor === undefined) {
83
+ throw new Error('invalid_unit', {cause: {toUnit}});
84
+ }
85
+
86
+ return ms / toFactor;
87
+ };
package/CHANGELOG.md DELETED
@@ -1,389 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [5.5.30](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.29...@alwatr/parse-duration@5.5.30) (2026-03-16)
7
-
8
- ### 🔨 Code Refactoring
9
-
10
- * migrate build scripts from yarn to bun across multiple packages ([d90e962](https://github.com/Alwatr/nanolib/commit/d90e962f15e5c951e191d5f02341279b6472abc3))
11
-
12
- ## [5.5.29](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.28...@alwatr/parse-duration@5.5.29) (2026-02-18)
13
-
14
- **Note:** Version bump only for package @alwatr/parse-duration
15
-
16
- ## [5.5.28](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.27...@alwatr/parse-duration@5.5.28) (2025-12-23)
17
-
18
- **Note:** Version bump only for package @alwatr/parse-duration
19
-
20
- ## [5.5.27](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.26...@alwatr/parse-duration@5.5.27) (2025-12-13)
21
-
22
- **Note:** Version bump only for package @alwatr/parse-duration
23
-
24
- ## [5.5.26](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.25...@alwatr/parse-duration@5.5.26) (2025-12-10)
25
-
26
- **Note:** Version bump only for package @alwatr/parse-duration
27
-
28
- ## [5.5.25](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.24...@alwatr/parse-duration@5.5.25) (2025-11-18)
29
-
30
- ### 🔨 Code Refactoring
31
-
32
- * remove unnecessary type declarations from tsconfig.json files ([89bcc7d](https://github.com/Alwatr/nanolib/commit/89bcc7db839807110b80f8ba34414ea9734d9c75))
33
-
34
- ## [5.5.24](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.23...@alwatr/parse-duration@5.5.24) (2025-11-15)
35
-
36
- **Note:** Version bump only for package @alwatr/parse-duration
37
-
38
- ## [5.5.23](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.22...@alwatr/parse-duration@5.5.23) (2025-11-15)
39
-
40
- **Note:** Version bump only for package @alwatr/parse-duration
41
-
42
- ## [5.5.22](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.21...@alwatr/parse-duration@5.5.22) (2025-11-04)
43
-
44
- **Note:** Version bump only for package @alwatr/parse-duration
45
-
46
- ## [5.5.21](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.20...@alwatr/parse-duration@5.5.21) (2025-10-06)
47
-
48
- ### 🔗 Dependencies update
49
-
50
- * bump the npm-dependencies group with 4 updates ([9825815](https://github.com/Alwatr/nanolib/commit/982581552bbb4b97dca52af5e93a80937f0c3109))
51
-
52
- ## [5.5.20](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.19...@alwatr/parse-duration@5.5.20) (2025-09-27)
53
-
54
- ### 🧹 Miscellaneous Chores
55
-
56
- * exclude test files from package distribution ([86f4f2f](https://github.com/Alwatr/nanolib/commit/86f4f2f5985845c5cf3a3a9398de7b2f98ce53e7))
57
-
58
- ## [5.5.19](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.18...@alwatr/parse-duration@5.5.19) (2025-09-22)
59
-
60
- **Note:** Version bump only for package @alwatr/parse-duration
61
-
62
- ## [5.5.18](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.17...@alwatr/parse-duration@5.5.18) (2025-09-22)
63
-
64
- **Note:** Version bump only for package @alwatr/parse-duration
65
-
66
- ## [5.5.17](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.16...@alwatr/parse-duration@5.5.17) (2025-09-21)
67
-
68
- **Note:** Version bump only for package @alwatr/parse-duration
69
-
70
- ## [5.5.16](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.15...@alwatr/parse-duration@5.5.16) (2025-09-20)
71
-
72
- ### 🐛 Bug Fixes
73
-
74
- * add sideEffects property to package.json files for better tree-shaking ([c7b9e74](https://github.com/Alwatr/nanolib/commit/c7b9e74e1920c8e35b438742de61883ca62da58c))
75
- * add sideEffects property to package.json files for better tree-shaking ([e8402c4](https://github.com/Alwatr/nanolib/commit/e8402c481a14a1f807a37aaa862a936713d26176))
76
- * remove unnecessary pure annotations ([adeb916](https://github.com/Alwatr/nanolib/commit/adeb9166f8e911f59269032b76c36cb1888332cf))
77
-
78
- ### 🧹 Miscellaneous Chores
79
-
80
- * remove duplicate sideEffects property from multiple package.json files ([b123f86](https://github.com/Alwatr/nanolib/commit/b123f86be81481de2314aae9bb2eeb629743d24c))
81
-
82
- ## [5.5.15](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.14...@alwatr/parse-duration@5.5.15) (2025-09-19)
83
-
84
- **Note:** Version bump only for package @alwatr/parse-duration
85
-
86
- ## [5.5.14](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.13...@alwatr/parse-duration@5.5.14) (2025-09-15)
87
-
88
- **Note:** Version bump only for package @alwatr/parse-duration
89
-
90
- ## [5.5.13](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.12...@alwatr/parse-duration@5.5.13) (2025-09-13)
91
-
92
- **Note:** Version bump only for package @alwatr/parse-duration
93
-
94
- ## [5.5.12](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.11...@alwatr/parse-duration@5.5.12) (2025-09-13)
95
-
96
- ### 🧹 Miscellaneous Chores
97
-
98
- * remove package-tracer dependency and related code from fetch package ([96fe4e9](https://github.com/Alwatr/nanolib/commit/96fe4e9552a205f218ceed187c55e4e904a07089))
99
-
100
- ## [5.5.11](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.10...@alwatr/parse-duration@5.5.11) (2025-09-09)
101
-
102
- ### 🧹 Miscellaneous Chores
103
-
104
- * remove trailing newlines from contributing sections in README files ([e8ab1bc](https://github.com/Alwatr/nanolib/commit/e8ab1bc43e0addea5ccd4c897c2cec597cb9e15f))
105
-
106
- ## [5.5.10](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.9...@alwatr/parse-duration@5.5.10) (2025-09-06)
107
-
108
- **Note:** Version bump only for package @alwatr/parse-duration
109
-
110
- ## [5.5.9](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.8...@alwatr/parse-duration@5.5.9) (2025-09-05)
111
-
112
- ### 🔗 Dependencies update
113
-
114
- * update jest to version 30.1.3 and @types/node to version 22.18.1 ([754212b](https://github.com/Alwatr/nanolib/commit/754212b1523cfc4cfe26c9e9f6d634aa8311e0b7))
115
-
116
- ## [5.5.8](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.7...@alwatr/parse-duration@5.5.8) (2025-09-01)
117
-
118
- ### 🔗 Dependencies update
119
-
120
- * update lerna-lite dependencies to version 4.7.3 and jest to 30.1.2 ([95d7870](https://github.com/Alwatr/nanolib/commit/95d7870ec7ad1e6ed2688bafddcabf46857f6981))
121
-
122
- ## [5.5.7](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.6...@alwatr/parse-duration@5.5.7) (2025-08-23)
123
-
124
- **Note:** Version bump only for package @alwatr/parse-duration
125
-
126
- ## [5.5.6](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.4...@alwatr/parse-duration@5.5.6) (2025-08-23)
127
-
128
- ### 🐛 Bug Fixes
129
-
130
- * update license from AGPL-3.0-only to MPL-2.0 ([d20968e](https://github.com/Alwatr/nanolib/commit/d20968e60cc89b1dcdf9b96507178da6ed562f55))
131
- * update package versions in multiple package.json files ([7638b1c](https://github.com/Alwatr/nanolib/commit/7638b1cafee2b4e0f97db7a89ac9fba6384b9b10))
132
-
133
- ### 🔨 Code Refactoring
134
-
135
- * Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3))
136
-
137
- ### 🧹 Miscellaneous Chores
138
-
139
- * reformat all package.json files ([ceda45d](https://github.com/Alwatr/nanolib/commit/ceda45de186667790474f729cb4b161a5148ce19))
140
-
141
- ### 🔗 Dependencies update
142
-
143
- * update TypeScript and Jest versions across all packages to improve compatibility and performance ([31baf36](https://github.com/Alwatr/nanolib/commit/31baf366101e92e27db66a21c849fb101f19be47))
144
-
145
- ## [5.5.5](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.4...@alwatr/parse-duration@5.5.5) (2025-08-23)
146
-
147
- ### Code Refactoring
148
-
149
- * Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3)) by @alimd
150
-
151
- ## [5.5.4](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.3...@alwatr/parse-duration@5.5.4) (2025-04-20)
152
-
153
- **Note:** Version bump only for package @alwatr/parse-duration
154
-
155
- ## <small>5.5.3 (2025-04-15)</small>
156
-
157
- **Note:** Version bump only for package @alwatr/parse-duration
158
-
159
- ## [5.5.2](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.1...@alwatr/parse-duration@5.5.2) (2025-04-01)
160
-
161
- **Note:** Version bump only for package @alwatr/parse-duration
162
-
163
- ## [5.5.1](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.5.0...@alwatr/parse-duration@5.5.1) (2025-03-18)
164
-
165
- ### Code Refactoring
166
-
167
- * **parse-duration:** replace isNumber with toNumber for improved number conversion and enhance error handling ([4d63892](https://github.com/Alwatr/nanolib/commit/4d63892f914cebe73bd1dc1e688c2f4ea5b53de1)) by @alimd
168
-
169
- ## [5.5.0](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@5.4.0...@alwatr/parse-duration@5.5.0) (2025-03-06)
170
-
171
- ### Miscellaneous Chores
172
-
173
- * update username casing in changelog entries ([9722ac9](https://github.com/Alwatr/nanolib/commit/9722ac9a078438a4e8ebfa5826ea70e0e3a52ca6)) by @
174
-
175
- ### Dependencies update
176
-
177
- * bump the development-dependencies group across 1 directory with 11 updates ([720c395](https://github.com/Alwatr/nanolib/commit/720c3954da55c929fe8fb16957121f4c51fb7f0c)) by @dependabot[bot]
178
-
179
- ## [5.4.0](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.1.8...@alwatr/parse-duration@5.4.0) (2025-02-18)
180
-
181
- ## 5.3.0 (2025-02-03)
182
-
183
- ### Miscellaneous Chores
184
-
185
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @
186
-
187
- ### Dependencies update
188
-
189
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @
190
- * update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @
191
-
192
- ## 5.0.0 (2024-11-02)
193
-
194
- ### ⚠ BREAKING CHANGES
195
-
196
- * To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
197
-
198
- ### Code Refactoring
199
-
200
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
201
-
202
- ## [5.3.0](https://github.com/Alwatr/nanolib/compare/v5.2.1...v5.3.0) (2025-02-03)
203
-
204
- ### Miscellaneous Chores
205
-
206
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @ArmanAsadian
207
-
208
- ### Dependencies update
209
-
210
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @dependabot[bot]
211
- * update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @alimd
212
-
213
- ## 5.0.0 (2024-11-02)
214
-
215
- ### ⚠ BREAKING CHANGES
216
-
217
- * To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
218
-
219
- ### Features
220
-
221
- * **parse-duration:** rewrite module 🤦🏻 ([be62163](https://github.com/Alwatr/nanolib/commit/be6216345cb3d4458307f55b8ae44f5ac60dda89)) by @
222
- * **parse-duration:** rewrite with document ([43ffecc](https://github.com/Alwatr/nanolib/commit/43ffeccbc4a859ad838938a63fd52c82654cc9bb)) by @
223
- * **parse-duration:** seperate parseDuration from `@alwatr/math` ([f5e32d0](https://github.com/Alwatr/nanolib/commit/f5e32d080be1b5355463f77a2f23fbd0955b8b67)) by @
224
- * **parse-duration:** update parseDuration function to accept duration as number or string ([af413f5](https://github.com/Alwatr/nanolib/commit/af413f5399b7bb8c01d4e14ae1f9238e44368184)) by @
225
- * use `package-tracer` ([cc3c5f9](https://github.com/Alwatr/nanolib/commit/cc3c5f9c1a3d03f0d81b46835665f16a0426fd0d)) by @
226
-
227
- ### Bug Fixes
228
-
229
- * all dependeny topology ([1c17f34](https://github.com/Alwatr/nanolib/commit/1c17f349adf3e98e2a80ab2da4f0f81028dc9c5f)) by @
230
- * **parse-duration:** remove unused variables ([500f272](https://github.com/Alwatr/nanolib/commit/500f2727373daf12b6b8b84032244a88f197948e)) by @
231
-
232
- ### Code Refactoring
233
-
234
- * prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @
235
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
236
-
237
- ### Miscellaneous Chores
238
-
239
- * **deps:** update ([1a45030](https://github.com/Alwatr/nanolib/commit/1a450305440b710a300787d4ca24b1ed8c6a39d7)) by @
240
- * **deps:** update ([8e70dff](https://github.com/Alwatr/nanolib/commit/8e70dffb1e751496ef2e72d6cffd685f1fea44e3)) by @
241
- * include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @
242
- * **parse-duration:** add tsconfig.json ([e799038](https://github.com/Alwatr/nanolib/commit/e7990381f8820a3f6a449b908c0fc5da4e475abd)) by @
243
- * **parse-duration:** change the license to AGPL-3.0 ([896df6f](https://github.com/Alwatr/nanolib/commit/896df6f64bb1df5954d6c46694e18bfb3e944f22)) by @
244
- * **parse-duration:** deps ([1898f2e](https://github.com/Alwatr/nanolib/commit/1898f2ee41bb5561949d758a62754fd5086eb0c7)) by @
245
- * **parse-duration:** package.json ([97f970d](https://github.com/Alwatr/nanolib/commit/97f970dfeb4a84ad66050cc5dd2611a013853c15)) by @
246
- * **parse-duration:** rename main file ([be0d2fc](https://github.com/Alwatr/nanolib/commit/be0d2fc3d37f298936c9a85f7e095d670c805970)) by @
247
- * Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @
248
- * Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
249
- * Update test scripts and dependencies ([93d2fe6](https://github.com/Alwatr/nanolib/commit/93d2fe6d7ce9c38a300e0c7ed75874916767a14b)) by @
250
-
251
- ### Dependencies update
252
-
253
- * bump @types/node ([3d80fed](https://github.com/Alwatr/nanolib/commit/3d80fedaf720af792feb060c2f81c737ebb84e11)) by @
254
- * bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @
255
- * bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @
256
- * bump the development-dependencies group with 2 updates ([be5d6c2](https://github.com/Alwatr/nanolib/commit/be5d6c2d86b937f32cebc6848aaff85af07055dd)) by @
257
- * upd ([451d025](https://github.com/Alwatr/nanolib/commit/451d0255ba96ed55f897a6f44f62cf4e6d2b12be)) by @
258
- * update ([c36ed50](https://github.com/Alwatr/nanolib/commit/c36ed50f68da2f5608ccd96119963a16cfacb4ce)) by @
259
- * update all ([53342f6](https://github.com/Alwatr/nanolib/commit/53342f67a8a013127f073540bc11929f1813c05c)) by @
260
- * update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @
261
- * update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
262
- * upgrade ([6dbd300](https://github.com/Alwatr/nanolib/commit/6dbd300642c9bcc9e7d0b281e244bf1b06eb1c38)) by @
263
-
264
- ## [1.1.8](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.1.7...@alwatr/parse-duration@1.1.8) (2024-11-02)
265
-
266
- **Note:** Version bump only for package @alwatr/parse-duration
267
-
268
- ## [1.1.7](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.1.6...@alwatr/parse-duration@1.1.7) (2024-10-25)
269
-
270
- **Note:** Version bump only for package @alwatr/parse-duration
271
-
272
- ## [1.1.6](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.1.5...@alwatr/parse-duration@1.1.6) (2024-10-12)
273
-
274
- **Note:** Version bump only for package @alwatr/parse-duration
275
-
276
- ## [1.1.5](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.1.4...@alwatr/parse-duration@1.1.5) (2024-10-11)
277
-
278
- ### Code Refactoring
279
-
280
- - prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @mohammadhonarvar
281
-
282
- ## [1.1.4](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.1.3...@alwatr/parse-duration@1.1.4) (2024-10-11)
283
-
284
- ### Miscellaneous Chores
285
-
286
- - include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @alimd
287
-
288
- ## [1.1.3](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.1.2...@alwatr/parse-duration@1.1.3) (2024-10-11)
289
-
290
- **Note:** Version bump only for package @alwatr/parse-duration
291
-
292
- ## [1.1.2](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.1.1...@alwatr/parse-duration@1.1.2) (2024-10-10)
293
-
294
- ### Dependencies update
295
-
296
- - bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @dependabot[bot]
297
-
298
- ## [1.1.1](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.1.0...@alwatr/parse-duration@1.1.1) (2024-10-08)
299
-
300
- **Note:** Version bump only for package @alwatr/parse-duration
301
-
302
- ## [1.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.11...@alwatr/parse-duration@1.1.0) (2024-09-29)
303
-
304
- ### Features
305
-
306
- - **parse-duration:** update parseDuration function to accept duration as number or string ([af413f5](https://github.com/Alwatr/nanolib/commit/af413f5399b7bb8c01d4e14ae1f9238e44368184)) by @alimd
307
- - use `package-tracer` ([cc3c5f9](https://github.com/Alwatr/nanolib/commit/cc3c5f9c1a3d03f0d81b46835665f16a0426fd0d)) by @mohammadhonarvar
308
-
309
- ### Bug Fixes
310
-
311
- - all dependeny topology ([1c17f34](https://github.com/Alwatr/nanolib/commit/1c17f349adf3e98e2a80ab2da4f0f81028dc9c5f)) by @mohammadhonarvar
312
-
313
- ### Miscellaneous Chores
314
-
315
- - **parse-duration:** change the license to AGPL-3.0 ([896df6f](https://github.com/Alwatr/nanolib/commit/896df6f64bb1df5954d6c46694e18bfb3e944f22)) by @ArmanAsadian
316
- - Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @alimd
317
-
318
- ### Dependencies update
319
-
320
- - bump @types/node ([3d80fed](https://github.com/Alwatr/nanolib/commit/3d80fedaf720af792feb060c2f81c737ebb84e11)) by @dependabot[bot]
321
-
322
- ## [1.0.11](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.10...@alwatr/parse-duration@1.0.11) (2024-09-21)
323
-
324
- **Note:** Version bump only for package @alwatr/parse-duration
325
-
326
- ## [1.0.10](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.9...@alwatr/parse-duration@1.0.10) (2024-09-15)
327
-
328
- ### Dependencies update
329
-
330
- - bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @dependabot[bot]
331
- - update ([c36ed50](https://github.com/Alwatr/nanolib/commit/c36ed50f68da2f5608ccd96119963a16cfacb4ce)) by @alimd
332
-
333
- ## [1.0.9](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.8...@alwatr/parse-duration@1.0.9) (2024-08-31)
334
-
335
- ### Miscellaneous Chores
336
-
337
- - Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
338
-
339
- ## [1.0.8](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.7...@alwatr/parse-duration@1.0.8) (2024-08-31)
340
-
341
- ### Dependencies update
342
-
343
- - update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @alimd
344
-
345
- ## [1.0.7](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.6...@alwatr/parse-duration@1.0.7) (2024-07-04)
346
-
347
- ### Dependencies update
348
-
349
- - update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
350
-
351
- ## [1.0.6](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.5...@alwatr/parse-duration@1.0.6) (2024-05-12)
352
-
353
- ### Dependencies update
354
-
355
- - upgrade ([6dbd300](https://github.com/Alwatr/nanolib/commit/6dbd300642c9bcc9e7d0b281e244bf1b06eb1c38)) by @alimd
356
-
357
- ## [1.0.5](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.4...@alwatr/parse-duration@1.0.5) (2024-04-25)
358
-
359
- **Note:** Version bump only for package @alwatr/parse-duration
360
-
361
- ## [1.0.4](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.3...@alwatr/parse-duration@1.0.4) (2024-03-28)
362
-
363
- **Note:** Version bump only for package @alwatr/parse-duration
364
-
365
- ## [1.0.3](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.2...@alwatr/parse-duration@1.0.3) (2024-01-31)
366
-
367
- ### Miscellaneous Chores
368
-
369
- - **deps:** update ([1a45030](https://github.com/Alwatr/nanolib/commit/1a450305440b710a300787d4ca24b1ed8c6a39d7)) by @alimd
370
-
371
- ## [1.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.1...@alwatr/parse-duration@1.0.2) (2024-01-24)
372
-
373
- **Note:** Version bump only for package @alwatr/parse-duration
374
-
375
- ## [1.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/parse-duration@1.0.0...@alwatr/parse-duration@1.0.1) (2024-01-20)
376
-
377
- **Note:** Version bump only for package @alwatr/parse-duration
378
-
379
- # 1.0.0 (2024-01-16)
380
-
381
- ### Bug Fixes
382
-
383
- - **parse-duration:** remove unused variables ([500f272](https://github.com/Alwatr/nanolib/commit/500f2727373daf12b6b8b84032244a88f197948e)) by @adltalab
384
-
385
- ### Features
386
-
387
- - **parse-duration:** rewrite module 🤦🏻 ([be62163](https://github.com/Alwatr/nanolib/commit/be6216345cb3d4458307f55b8ae44f5ac60dda89)) by @alimd
388
- - **parse-duration:** rewrite with document ([43ffecc](https://github.com/Alwatr/nanolib/commit/43ffeccbc4a859ad838938a63fd52c82654cc9bb)) by @njfamirm
389
- - **parse-duration:** seperate parseDuration from `@alwatr/math` ([f5e32d0](https://github.com/Alwatr/nanolib/commit/f5e32d080be1b5355463f77a2f23fbd0955b8b67)) by @adltalab
package/dist/main.cjs DELETED
@@ -1,3 +0,0 @@
1
- /** 📦 @alwatr/parse-duration v5.5.30 */
2
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var main_exports={};__export(main_exports,{parseDuration:()=>parseDuration});module.exports=__toCommonJS(main_exports);var import_is_number=require("@alwatr/is-number");var unitConversion=Object.freeze({s:1e3,m:6e4,h:36e5,d:864e5,w:6048e5,M:2592e6,y:31536e6});var parseDuration=(duration,toUnit)=>{let ms;if(typeof duration==="number"){ms=duration}else{if(duration.length<2){throw new Error("invalid_format",{cause:{duration}})}const durationUnit=duration.slice(-1);const unitConversionFactor=unitConversion[durationUnit];if(unitConversionFactor===void 0){throw new Error("invalid_unit",{cause:{durationUnit}})}const durationNumber=(0,import_is_number.toNumber)(duration.slice(0,-1));if(durationNumber===null){throw new Error("not_a_number",{cause:{duration}})}ms=durationNumber*unitConversionFactor}if(toUnit===void 0){return ms}const toFactor=unitConversion[toUnit];if(toFactor===void 0){throw new Error("invalid_unit",{cause:{toUnit}})}return ms/toFactor};0&&(module.exports={parseDuration});
3
- //# sourceMappingURL=main.cjs.map
package/dist/main.cjs.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/main.ts"],
4
- "sourcesContent": ["import {toNumber} from '@alwatr/is-number';\n\n/**\n * Unit conversion table (milliseconds)\n */\nconst unitConversion = Object.freeze({\n s: 1_000,\n m: 60_000,\n h: 3_600_000,\n d: 86_400_000,\n w: 604_800_000,\n M: 2_592_000_000,\n y: 31_536_000_000,\n} as const);\n\n/**\n * Duration unit: `s` for seconds, `m` for minutes, `h` for hours, `d` for days, `w` for weeks, `M` for months, `y` for years.\n */\nexport type DurationUnit = keyof typeof unitConversion;\n\n/**\n * Duration string format: `number + unit`, for example `10m` means 10 minutes.\n */\nexport type Duration = `${number}${DurationUnit}` | number;\n\n/**\n * Error types that can be thrown by parseDuration\n */\nexport type DurationError = 'not_a_number' | 'invalid_unit' | 'invalid_format';\n\n/**\n * Parse duration string to milliseconds number.\n *\n * @param duration - Duration string or number, for example `10m` means 10 minutes.\n * @param toUnit - Convert to unit, default is `ms` for milliseconds.\n * @throws {Error} With message 'not_a_number' if duration string doesn't contain a valid number.\n * @throws {Error} With message 'invalid_unit' if the unit is not recognized.\n * @throws {Error} With message 'invalid_format' if the duration format is invalid.\n * @returns Duration in specified unit (or milliseconds by default).\n *\n * @example\n * ```ts\n * parseDuration('10m'); // 600000\n * parseDuration('10m', 's'); // 600\n * parseDuration(120_000, 'm'); // 2\n * ```\n */\nexport const parseDuration = (duration: Duration, toUnit?: DurationUnit): number => {\n let ms: number;\n\n // Convert input to milliseconds\n if (typeof duration === 'number') {\n ms = duration;\n }\n else {\n if (duration.length < 2) {\n throw new Error('invalid_format', {cause: {duration}});\n }\n\n const durationUnit = duration.slice(-1) as DurationUnit;\n const unitConversionFactor = unitConversion[durationUnit];\n\n if (unitConversionFactor === undefined) {\n throw new Error('invalid_unit', {cause: {durationUnit}});\n }\n\n const durationNumber = toNumber(duration.slice(0, -1));\n if (durationNumber === null) {\n throw new Error('not_a_number', {cause: {duration}});\n }\n\n ms = durationNumber * unitConversionFactor;\n }\n\n // Return as is if no conversion needed\n if (toUnit === undefined) {\n return ms;\n }\n\n // Convert to target unit\n const toFactor = unitConversion[toUnit];\n if (toFactor === undefined) {\n throw new Error('invalid_unit', {cause: {toUnit}});\n }\n\n return ms / toFactor;\n};\n"],
5
- "mappings": ";qqBAAA,4IAAuB,6BAKvB,IAAM,eAAiB,OAAO,OAAO,CACnC,EAAG,IACH,EAAG,IACH,EAAG,KACH,EAAG,MACH,EAAG,OACH,EAAG,OACH,EAAG,OACL,CAAU,EAkCH,IAAM,cAAgB,CAAC,SAAoB,SAAkC,CAClF,IAAI,GAGJ,GAAI,OAAO,WAAa,SAAU,CAChC,GAAK,QACP,KACK,CACH,GAAI,SAAS,OAAS,EAAG,CACvB,MAAM,IAAI,MAAM,iBAAkB,CAAC,MAAO,CAAC,QAAQ,CAAC,CAAC,CACvD,CAEA,MAAM,aAAe,SAAS,MAAM,EAAE,EACtC,MAAM,qBAAuB,eAAe,YAAY,EAExD,GAAI,uBAAyB,OAAW,CACtC,MAAM,IAAI,MAAM,eAAgB,CAAC,MAAO,CAAC,YAAY,CAAC,CAAC,CACzD,CAEA,MAAM,kBAAiB,2BAAS,SAAS,MAAM,EAAG,EAAE,CAAC,EACrD,GAAI,iBAAmB,KAAM,CAC3B,MAAM,IAAI,MAAM,eAAgB,CAAC,MAAO,CAAC,QAAQ,CAAC,CAAC,CACrD,CAEA,GAAK,eAAiB,oBACxB,CAGA,GAAI,SAAW,OAAW,CACxB,OAAO,EACT,CAGA,MAAM,SAAW,eAAe,MAAM,EACtC,GAAI,WAAa,OAAW,CAC1B,MAAM,IAAI,MAAM,eAAgB,CAAC,MAAO,CAAC,MAAM,CAAC,CAAC,CACnD,CAEA,OAAO,GAAK,QACd",
6
- "names": []
7
- }
package/dist/main.mjs DELETED
@@ -1,3 +0,0 @@
1
- /** 📦 @alwatr/parse-duration v5.5.30 */
2
- import{toNumber}from"@alwatr/is-number";var unitConversion=Object.freeze({s:1e3,m:6e4,h:36e5,d:864e5,w:6048e5,M:2592e6,y:31536e6});var parseDuration=(duration,toUnit)=>{let ms;if(typeof duration==="number"){ms=duration}else{if(duration.length<2){throw new Error("invalid_format",{cause:{duration}})}const durationUnit=duration.slice(-1);const unitConversionFactor=unitConversion[durationUnit];if(unitConversionFactor===void 0){throw new Error("invalid_unit",{cause:{durationUnit}})}const durationNumber=toNumber(duration.slice(0,-1));if(durationNumber===null){throw new Error("not_a_number",{cause:{duration}})}ms=durationNumber*unitConversionFactor}if(toUnit===void 0){return ms}const toFactor=unitConversion[toUnit];if(toFactor===void 0){throw new Error("invalid_unit",{cause:{toUnit}})}return ms/toFactor};export{parseDuration};
3
- //# sourceMappingURL=main.mjs.map
package/dist/main.mjs.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/main.ts"],
4
- "sourcesContent": ["import {toNumber} from '@alwatr/is-number';\n\n/**\n * Unit conversion table (milliseconds)\n */\nconst unitConversion = Object.freeze({\n s: 1_000,\n m: 60_000,\n h: 3_600_000,\n d: 86_400_000,\n w: 604_800_000,\n M: 2_592_000_000,\n y: 31_536_000_000,\n} as const);\n\n/**\n * Duration unit: `s` for seconds, `m` for minutes, `h` for hours, `d` for days, `w` for weeks, `M` for months, `y` for years.\n */\nexport type DurationUnit = keyof typeof unitConversion;\n\n/**\n * Duration string format: `number + unit`, for example `10m` means 10 minutes.\n */\nexport type Duration = `${number}${DurationUnit}` | number;\n\n/**\n * Error types that can be thrown by parseDuration\n */\nexport type DurationError = 'not_a_number' | 'invalid_unit' | 'invalid_format';\n\n/**\n * Parse duration string to milliseconds number.\n *\n * @param duration - Duration string or number, for example `10m` means 10 minutes.\n * @param toUnit - Convert to unit, default is `ms` for milliseconds.\n * @throws {Error} With message 'not_a_number' if duration string doesn't contain a valid number.\n * @throws {Error} With message 'invalid_unit' if the unit is not recognized.\n * @throws {Error} With message 'invalid_format' if the duration format is invalid.\n * @returns Duration in specified unit (or milliseconds by default).\n *\n * @example\n * ```ts\n * parseDuration('10m'); // 600000\n * parseDuration('10m', 's'); // 600\n * parseDuration(120_000, 'm'); // 2\n * ```\n */\nexport const parseDuration = (duration: Duration, toUnit?: DurationUnit): number => {\n let ms: number;\n\n // Convert input to milliseconds\n if (typeof duration === 'number') {\n ms = duration;\n }\n else {\n if (duration.length < 2) {\n throw new Error('invalid_format', {cause: {duration}});\n }\n\n const durationUnit = duration.slice(-1) as DurationUnit;\n const unitConversionFactor = unitConversion[durationUnit];\n\n if (unitConversionFactor === undefined) {\n throw new Error('invalid_unit', {cause: {durationUnit}});\n }\n\n const durationNumber = toNumber(duration.slice(0, -1));\n if (durationNumber === null) {\n throw new Error('not_a_number', {cause: {duration}});\n }\n\n ms = durationNumber * unitConversionFactor;\n }\n\n // Return as is if no conversion needed\n if (toUnit === undefined) {\n return ms;\n }\n\n // Convert to target unit\n const toFactor = unitConversion[toUnit];\n if (toFactor === undefined) {\n throw new Error('invalid_unit', {cause: {toUnit}});\n }\n\n return ms / toFactor;\n};\n"],
5
- "mappings": ";AAAA,OAAQ,aAAe,oBAKvB,IAAM,eAAiB,OAAO,OAAO,CACnC,EAAG,IACH,EAAG,IACH,EAAG,KACH,EAAG,MACH,EAAG,OACH,EAAG,OACH,EAAG,OACL,CAAU,EAkCH,IAAM,cAAgB,CAAC,SAAoB,SAAkC,CAClF,IAAI,GAGJ,GAAI,OAAO,WAAa,SAAU,CAChC,GAAK,QACP,KACK,CACH,GAAI,SAAS,OAAS,EAAG,CACvB,MAAM,IAAI,MAAM,iBAAkB,CAAC,MAAO,CAAC,QAAQ,CAAC,CAAC,CACvD,CAEA,MAAM,aAAe,SAAS,MAAM,EAAE,EACtC,MAAM,qBAAuB,eAAe,YAAY,EAExD,GAAI,uBAAyB,OAAW,CACtC,MAAM,IAAI,MAAM,eAAgB,CAAC,MAAO,CAAC,YAAY,CAAC,CAAC,CACzD,CAEA,MAAM,eAAiB,SAAS,SAAS,MAAM,EAAG,EAAE,CAAC,EACrD,GAAI,iBAAmB,KAAM,CAC3B,MAAM,IAAI,MAAM,eAAgB,CAAC,MAAO,CAAC,QAAQ,CAAC,CAAC,CACrD,CAEA,GAAK,eAAiB,oBACxB,CAGA,GAAI,SAAW,OAAW,CACxB,OAAO,EACT,CAGA,MAAM,SAAW,eAAe,MAAM,EACtC,GAAI,WAAa,OAAW,CAC1B,MAAM,IAAI,MAAM,eAAgB,CAAC,MAAO,CAAC,MAAM,CAAC,CAAC,CACnD,CAEA,OAAO,GAAK,QACd",
6
- "names": []
7
- }