Skip to content

Commit

Permalink
fix: 🐛 joinStyles should ignore undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Sullivan committed Oct 23, 2022
1 parent 3b9759f commit 6a36e59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export function joinStyles(...values: string[]) {
export function joinStyles(...values: (string | undefined)[]) {
return (
values
.filter(Boolean)
.map(value => value.split(';').map(v => v.trim()))
.flat()
.filter(Boolean)
Expand Down
9 changes: 9 additions & 0 deletions tests/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ test('joinStyles', () => {
'color: red;background: blue;font-size: 16px;line-height: 1.5;font-weight: bold',
'three complex styles'
)
assert.is(
joinStyles(
'color: red',
undefined,
'background: blue'
),
'color: red;background: blue',
'ignores undefined values'
)
})

0 comments on commit 6a36e59

Please sign in to comment.