Classcat is a minimalist, performant JavaScript utility for constructing HTML `class` attribute strings dynamically. It allows developers to combine strings, arrays, and objects (where keys are class names and values are booleans for conditional inclusion) into a single, space-delimited class string. The current stable version is 5.0.5, with releases occurring on an as-needed basis to address bug fixes, type improvements, and modernization efforts. Key differentiators include its small bundle size (217 B minified+gzipped), high performance (up to 2.5x faster than alternatives), and framework-agnostic nature, making it suitable for any JavaScript project, including those using React, Lit-HTML, or Mithril. Version 5.x introduced a shift to ES Modules as the primary distribution, modernizing the codebase and dropping some legacy support.
npm install classcatVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `classcat` within a functional component to conditionally apply CSS classes based on component state, showcasing its usage with objects and booleans.
Migrate import statements from `const cc = require('classcat')` to `import cc from 'classcat'`. Ensure your build setup or Node.js environment supports ES Modules.Refactor inputs to avoid nested objects. Flatten any complex structures into a single object or array of class names. For instance, `cc([{ one: true }, { two: true }])` should become `cc({ one: true, two: true })` or `cc(['one', 'two'])`.Upgrade to the latest `classcat` version (5.0.5 or newer) to ensure accurate and complete TypeScript type definitions.
Review existing code where `classcat` is used with objects that might have all falsy values. Ensure the desired behavior aligns with this change, especially if an empty string or specific class was expected when all conditions are false.
Change your import statement from `const cc = require('classcat')` to `import cc from 'classcat'`.Flatten the input structure. Instead of `cc([{ foo: { bar: true }}])`, use `cc({ foo: true })` if 'bar' is a sub-condition, or `cc({ 'foo-bar': true })` if it's a combined class name.Ensure you are using the correct default import syntax: `import cc from 'classcat'`.
No dependency data recorded yet.