Skip to content

Commit

Permalink
feat: add formatting support for clamp, max & min functions unocss/un…
Browse files Browse the repository at this point in the history
  • Loading branch information
MellowCo committed Jul 9, 2022
1 parent d0f8411 commit 0385275
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/handlers/handlers.ts
Expand Up @@ -136,7 +136,7 @@ function bracketWithType(str: string, type?: string) {
return base
.replace(/(url\(.*?\))/g, v => v.replace(/_/g, '\\_'))
.replace(/([^\\])_/g, '$1 ')
.replace(/calc\((.*)/g, (v) => {
.replace(/(?:calc|clamp|max|min)\((.*)/g, (v) => {
return v.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ')
})
}
Expand Down
15 changes: 15 additions & 0 deletions test/handler.test.ts
@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest'
import { handler as h } from '../src/utils'

describe('value handler', () => {
it('bracket math function', () => {
expect(h.bracket('[calc(1-2)]')).eql('calc(1 - 2)')
expect(h.bracket('[min(1-2)]')).eql('min(1 - 2)')
expect(h.bracket('[max(1-2)]')).eql('max(1 - 2)')
expect(h.bracket('[clamp(1-2)]')).eql('clamp(1 - 2)')

expect(h.bracket('[calc(1+2)]')).eql('calc(1 + 2)')
expect(h.bracket('[calc(1/2)]')).eql('calc(1 / 2)')
expect(h.bracket('[calc(1*2)]')).eql('calc(1 * 2)')
})
})

0 comments on commit 0385275

Please sign in to comment.