Skip to content

Commit

Permalink
Changes asked in code review
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-m-dev committed Sep 13, 2024
1 parent a6c0713 commit 94d9674
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
13 changes: 6 additions & 7 deletions @vates/parse-duration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ exports.parseDuration = value => {
if (typeof value === 'number') {
return value
}
if (typeof value !== 'string' || value === '') {
throw new TypeError(`not a valid duration: ${value}`)
if (typeof value === 'string' && value !== '') {
const duration = ms(value)
if (duration !== undefined) {
return duration
}
}
const duration = ms(value)
if (duration === undefined) {
throw new TypeError(`not a valid duration: ${value}`)
}
return duration
throw new TypeError(`not a valid duration: ${value}`)
}
3 changes: 2 additions & 1 deletion @vates/parse-duration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"ms": "^2.1.2"
},
"scripts": {
"postversion": "npm publish --access public"
"postversion": "npm publish --access public",
"test": "node--test"
}
}
7 changes: 4 additions & 3 deletions @vates/parse-duration/parse-duration.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ describe('parseDuration()', () => {
assert.strictEqual(parseDuration(input), expected)
})

it('should throw an error for an undefined duration', () => {
const input = undefined
assert.throws(() => parseDuration(input), { message: 'not a valid duration: undefined' })
it('should throw an error for an invalid duration', () => {
;[undefined, '', 'invalid duration'].forEach(input => {
assert.throws(() => parseDuration(input), { message: `not a valid duration: ${input}` })
})
})
})
1 change: 0 additions & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<!--packages-start-->

- @vates/parse-duration minor
- @xen-orchestra/lite minor
- @xen-orchestra/web minor
- @xen-orchestra/web-core minor
Expand Down

0 comments on commit 94d9674

Please sign in to comment.