Skip to content

Commit

Permalink
fix(preset-mini): generate valid duration-0
Browse files Browse the repository at this point in the history
  • Loading branch information
sibbng committed Feb 14, 2023
1 parent 654c7f9 commit aa26195
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/preset-mini/src/_utils/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export function time(str: string) {
const [, n, unit] = match
const num = parseFloat(n)
if (!Number.isNaN(num)) {
if (num === 0)
return '0'
if (num === 0 && !unit)
return '0s'
return unit ? `${round(num)}${unit}` : `${round(num)}ms`
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ describe('value handler', () => {
expect(h.time('10 ms')).eql(undefined)
expect(h.time('10ms')).eql('10ms')
expect(h.time('10.0ms')).eql('10ms')
expect(h.time('0ms')).eql('0')
expect(h.time('0ms')).eql('0ms')
expect(h.time('0')).eql('0s')
expect(h.time('.1ms')).eql('0.1ms')
expect(h.time('.20ms')).eql('0.2ms')
expect(h.time('00.30ms')).eql('0.3ms')
Expand Down

0 comments on commit aa26195

Please sign in to comment.