From 3f087915ecc2d03edf425b8a268ac2e276833430 Mon Sep 17 00:00:00 2001 From: Stephane MEYER Date: Mon, 9 Sep 2024 16:42:45 +0200 Subject: [PATCH] chore: convert parseDuration to TS Changes after code review --- @vates/parse-duration/index.js | 16 ---------------- @vates/parse-duration/package.json | 5 ++++- @vates/parse-duration/src/index.ts | 14 ++++++++++++++ @vates/parse-duration/tsconfig.json | 18 ++++++++++++++++++ CHANGELOG.unreleased.md | 1 + 5 files changed, 37 insertions(+), 17 deletions(-) delete mode 100644 @vates/parse-duration/index.js create mode 100644 @vates/parse-duration/src/index.ts create mode 100644 @vates/parse-duration/tsconfig.json diff --git a/@vates/parse-duration/index.js b/@vates/parse-duration/index.js deleted file mode 100644 index 4d534d93aa6..00000000000 --- a/@vates/parse-duration/index.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict' - -const ms = require('ms') - -exports.parseDuration = value => { - if (typeof value === 'number') { - return value - } - if (typeof value === 'string' && value !== '') { - const duration = ms(value) - if (duration !== undefined) { - return duration - } - } - throw new TypeError(`not a valid duration: ${value}`) -} diff --git a/@vates/parse-duration/package.json b/@vates/parse-duration/package.json index 4dd15ead04e..e4368762e7f 100644 --- a/@vates/parse-duration/package.json +++ b/@vates/parse-duration/package.json @@ -27,7 +27,10 @@ "ms": "^2.1.2" }, "scripts": { + "build": "tsc", + "dev": "tsc --watch", "postversion": "npm publish --access public", "test": "node --test" - } + }, + "main": "dist/index.js" } diff --git a/@vates/parse-duration/src/index.ts b/@vates/parse-duration/src/index.ts new file mode 100644 index 00000000000..8233c125ce4 --- /dev/null +++ b/@vates/parse-duration/src/index.ts @@ -0,0 +1,14 @@ +'use strict' + +const ms = require('ms') + +exports.parseDuration = (value: number | string): number => { + if (typeof value === 'number') { + return value + } + const duration: number = ms(value) + if (duration === undefined) { + throw new TypeError(`not a valid duration: ${value}`) + } + return duration +} diff --git a/@vates/parse-duration/tsconfig.json b/@vates/parse-duration/tsconfig.json new file mode 100644 index 00000000000..44a364a09af --- /dev/null +++ b/@vates/parse-duration/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "esModuleInterop": true, + "module": "commonjs", + "moduleResolution": "node", + "newLine": "lf", + "noImplicitAny": true, + "strict": false, + "skipLibCheck": true, + "baseUrl": ".", + "sourceMap": false, + "strictNullChecks": true, + "target": "ES2015", + "outDir": "./dist", + "rootDir": "./src" + }, + "exclude": ["node_modules", "dist"] +} diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index b975766a1c9..e14e20c3606 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -41,6 +41,7 @@ +- @vates/parse-duration minor - @xen-orchestra/lite minor - @xen-orchestra/web minor - @xen-orchestra/web-core minor