mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
fix: toStyleString omit nullish values (#8940)
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
parent
ca10dd7a7a
commit
937522fb70
2 changed files with 6 additions and 0 deletions
5
.changeset/long-roses-shave.md
Normal file
5
.changeset/long-roses-shave.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Omit nullish and falsy (non-zero) values when stringifying object-form `style` attributes in Astro files
|
|
@ -28,6 +28,7 @@ const kebab = (k: string) =>
|
|||
k.toLowerCase() === k ? k : k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
||||
const toStyleString = (obj: Record<string, any>) =>
|
||||
Object.entries(obj)
|
||||
.filter(([k, v]) => typeof v === 'string' && v.trim() || typeof v === 'number')
|
||||
.map(([k, v]) => {
|
||||
if (k[0] !== '-' && k[1] !== '-') return `${kebab(k)}:${v}`;
|
||||
return `${k}:${v}`;
|
||||
|
|
Loading…
Reference in a new issue