@alwatr/parse-duration 5.5.29 → 5.5.30
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/CHANGELOG.md +6 -0
- package/dist/main.cjs +1 -2
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +1 -2
- package/dist/main.mjs.map +1 -1
- package/package.json +15 -16
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
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
|
+
|
|
6
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)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @alwatr/parse-duration
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** 📦 @alwatr/parse-duration v5.5.
|
|
2
|
-
__dev_mode__: console.debug("📦 @alwatr/parse-duration v5.5.29");
|
|
1
|
+
/** 📦 @alwatr/parse-duration v5.5.30 */
|
|
3
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});
|
|
4
3
|
//# sourceMappingURL=main.cjs.map
|
package/dist/main.cjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/main.ts"],
|
|
4
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": "
|
|
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
6
|
"names": []
|
|
7
7
|
}
|
package/dist/main.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** 📦 @alwatr/parse-duration v5.5.
|
|
2
|
-
__dev_mode__: console.debug("📦 @alwatr/parse-duration v5.5.29");
|
|
1
|
+
/** 📦 @alwatr/parse-duration v5.5.30 */
|
|
3
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};
|
|
4
3
|
//# sourceMappingURL=main.mjs.map
|
package/dist/main.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/main.ts"],
|
|
4
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": "
|
|
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
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
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.
|
|
4
|
+
"version": "5.5.30",
|
|
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.
|
|
8
|
+
"@alwatr/is-number": "5.7.26"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@alwatr/nano-build": "6.4.
|
|
11
|
+
"@alwatr/nano-build": "6.4.2",
|
|
12
12
|
"@alwatr/prettier-config": "6.0.2",
|
|
13
13
|
"@alwatr/tsconfig-base": "6.0.4",
|
|
14
|
-
"jest": "^30.2.0",
|
|
15
14
|
"typescript": "^5.9.3"
|
|
16
15
|
},
|
|
17
16
|
"exports": {
|
|
@@ -61,23 +60,23 @@
|
|
|
61
60
|
"directory": "packages/parse-duration"
|
|
62
61
|
},
|
|
63
62
|
"scripts": {
|
|
64
|
-
"b": "
|
|
65
|
-
"build": "
|
|
63
|
+
"b": "bun run build",
|
|
64
|
+
"build": "bun run build:ts && bun run build:es",
|
|
66
65
|
"build:es": "nano-build --preset=module",
|
|
67
66
|
"build:ts": "tsc --build",
|
|
68
|
-
"c": "
|
|
69
|
-
"cb": "
|
|
67
|
+
"c": "bun run clean",
|
|
68
|
+
"cb": "bun run clean && bun run build",
|
|
70
69
|
"clean": "rm -rfv dist *.tsbuildinfo",
|
|
71
|
-
"d": "
|
|
72
|
-
"t": "
|
|
73
|
-
"test": "
|
|
74
|
-
"w": "
|
|
75
|
-
"watch": "
|
|
76
|
-
"watch:es": "
|
|
77
|
-
"watch:ts": "
|
|
70
|
+
"d": "bun run build:es && bun --enable-source-maps --trace-warnings",
|
|
71
|
+
"t": "bun run test",
|
|
72
|
+
"test": "echo test-skipped",
|
|
73
|
+
"w": "bun run watch",
|
|
74
|
+
"watch": "bun run watch:ts & bun run watch:es",
|
|
75
|
+
"watch:es": "bun run build:es --watch",
|
|
76
|
+
"watch:ts": "bun run build:ts --watch --preserveWatchOutput"
|
|
78
77
|
},
|
|
79
78
|
"sideEffects": false,
|
|
80
79
|
"type": "module",
|
|
81
80
|
"types": "./dist/main.d.ts",
|
|
82
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "c3889e3756b0a0f9b935a1b702a1373ac52cb379"
|
|
83
82
|
}
|