Skip to content

Commit

Permalink
fix(toUnocssClass): add g and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Mar 19, 2024
1 parent f24d88e commit dd3ed6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/toUnocssClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function toUnocssClass(css: string, isRem = false): [string, string[]] {

return [
transferred
? transferred.replace(/([^\s\=]+)="([^"]+)"/, (_, v1, v2) => v2.split(' ').map((v: string) => `${v1}-${v}`).join(' '))
? transferred.replace(/([^\s\=]+)="([^"]+)"/g, (_, v1, v2) => v2.split(' ').map((v: string) => `${v1}-${v}`).join(' '))
: '',
noTransferred,
]
Expand Down
24 changes: 24 additions & 0 deletions test/toUnocssClass.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, expect, it } from 'vitest'
import { toUnocssClass } from '../src/toUnocssClass'

describe('toUnocssClass', () => {
it('toUnocssClass', () => {
expect(
toUnocssClass(
'transform-origin: center;background:red;width:100%;height:30px',
)[0],
).toBe('origin-center bg-red w-[100%] h-30px')

expect(
toUnocssClass(
'transform-origin: center;background:rgba(1,2,3,.5);width:100%;height:30px',
)[0],
).toBe('origin-center bg-[rgba(1,2,3,.5)] w-[100%] h-30px')

expect(
toUnocssClass(
'height: 100%; transform: scale(1.5);',
)[0],
).toBe('h-[100%] scale-150')
})
})

0 comments on commit dd3ed6c

Please sign in to comment.