Skip to content

Commit

Permalink
feat: generate valid duration-0 (unocss/unocss#2196)
Browse files Browse the repository at this point in the history
  • Loading branch information
MellowCo committed Feb 23, 2023
1 parent 794b943 commit d23e150
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/utils/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,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 d23e150

Please sign in to comment.