0
Fork 0
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:
Marvin 2023-11-02 05:02:00 +08:00 committed by GitHub
parent ca10dd7a7a
commit 937522fb70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Omit nullish and falsy (non-zero) values when stringifying object-form `style` attributes in Astro files

View file

@ -28,6 +28,7 @@ const kebab = (k: string) =>
k.toLowerCase() === k ? k : k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`); k.toLowerCase() === k ? k : k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
const toStyleString = (obj: Record<string, any>) => const toStyleString = (obj: Record<string, any>) =>
Object.entries(obj) Object.entries(obj)
.filter(([k, v]) => typeof v === 'string' && v.trim() || typeof v === 'number')
.map(([k, v]) => { .map(([k, v]) => {
if (k[0] !== '-' && k[1] !== '-') return `${kebab(k)}:${v}`; if (k[0] !== '-' && k[1] !== '-') return `${kebab(k)}:${v}`;
return `${k}:${v}`; return `${k}:${v}`;