
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
@jcayzac/astro-classlist
Advanced tools
Helper for Astro components to coerce `class:list` into an array of strings.
@jcayzac/astro-classlist
Coerce Astro's
class:list
into an array of strings.
This module provides a single utility for Astro components, that coerce a value received as a class:list
prop into an array of strings.
You probably need this if your component receives a class:list
prop and passes it to a child component, and if you want to add other classes to the list.
Because class:list
can be an object or an iterable and contain things other than strings, it can get a bit messy if you want to add something to that.
// This is what you normally get from Astro
type AstroBuiltinAttributes['class:list'] =
| string
| Record<string, boolean>
| Record<any, any>
| Iterable<string>
| Iterable<any>
| undefined
// This is what you get when using this utility
type ClassList = string[]
# pnpm
pnpm add @jcayzac/astro-classlist
# bun
bunx add @jcayzac/astro-classlist
# npm
npx add @jcayzac/astro-classlist
# yarn
yarn add @jcayzac/astro-classlist
# deno
deno add npm:@jcayzac/astro-classlist
---
import type { AstroBuiltinAttributes } from 'astro'
import ChildComponent from '@components/ChildComponent.astro'
import { ClassList } from '@jcayzac/astro-classlist'
interface Props {
'class:list': AstroBuiltinAttributes['class:list']
}
const { 'class:list': classList } = Astro.props as Props
const classes: string[] = ClassList.toArray(classList)
---
<ChildComponent class:list={['mx-auto', ...classes]} />
If you like anything here, consider buying me a coffee using one of the following platforms:
FAQs
Helper for Astro components to coerce `class:list` into an array of strings.
We found that @jcayzac/astro-classlist demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.