Compare commits

...

2 Commits

Author SHA1 Message Date
Julien Fontanet
410ba973c8 build before publish and test 2024-09-24 16:18:02 +02:00
Stephane MEYER
853729a11d chore: convert parseDuration to TS
Changes after code review
2024-09-24 16:15:52 +02:00
6 changed files with 52 additions and 18 deletions

View File

@@ -54,7 +54,7 @@ module.exports = {
},
},
{
files: ['@xen-orchestra/{web-core,lite,web}/**/*.{vue,ts}'],
files: ['@vates/**/*.{vue,ts}', '@xen-orchestra/{web-core,lite,web}/**/*.{vue,ts}'],
parser: 'vue-eslint-parser',
parserOptions: {
sourceType: 'module',
@@ -85,6 +85,10 @@ module.exports = {
XO_LITE_GIT_HEAD: true,
},
rules: {
// allow "use strict"
strict: 'off',
// allow "require"
'@typescript-eslint/no-var-requires': 'off',
'import/order': [
'error',
{

View File

@@ -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}`)
}

View File

@@ -27,7 +27,12 @@
"ms": "^2.1.2"
},
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"postversion": "npm publish --access public",
"prepublishOnly": "yarn run build",
"pretest": "yarn run build",
"test": "node --test"
}
},
"main": "dist/index.js"
}

View File

@@ -0,0 +1,22 @@
'use strict'
const ms = require('ms')
exports.parseDuration = (value: number | string): number => {
const throwError = () => {
throw new TypeError(`not a valid duration: ${value}`)
}
if (typeof value === 'number') {
return value
}
try {
const duration: number | undefined = ms(value)
if (typeof duration !== 'number') {
return throwError()
}
return duration
} catch (err) {
return throwError()
}
}

View File

@@ -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"]
}

View File

@@ -44,6 +44,7 @@
<!--packages-start-->
- @vates/parse-duration minor
- @xen-orchestra/defined patch
- @xen-orchestra/lite minor
- @xen-orchestra/web minor