
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
Catnip greatly reduces boilerplate class generation code. It's still beta, so use it in production code with caution.
Catnip first should be initiated with string for BEM generator and styles object for CSS modules generator.
import catnip from 'catnip';
const cn = catnip('block'); // Will generate strings
import catnip from 'catnip';
import styles from './styles.scss';
const cn = catnip(styles); // Will generate strings and takes corresponging items from styles object
Generator function takes 3 arguments, all optional
const className = cn(
'button', // Element (string)
{ style: 'amazing', disabled: false }, // Mods (object)
['global-input'] // Mixes (array)
)
Element defines basic class name of element.
Mods used for dynamic stuff, eg. styles and states.
Mixes are just global styles which will be added to final class.
Catnip uses BEM-like syntax for generating classes
cn() // block
cn('element') // block__element
cn('element', { mod: true }) // block__element block__element_mod_true
cn('element', ['mix']) // block__element mix
CCS modules works in the similar way but don't need block
import catnip from 'catnip';
import styles from './styles.scss';
const cn = catnip(styles);
function someComonent ({ mod }) {
return (
<div className={cn('element', { mod })}>
Hi there!
</div>
);
}
// Adds styles[element] and styles[element_mod_modValue]
Catnip automatically converts camel case to snake case in mod names, so it works great with JS object shorthand
const someMod = true;
cn('element', { someMod }) // block__element block__element_some-mod_true
Mods with null and undefined (but not false) values will be ignored
cn('element', { mod: undefined }) // block__element
cn('element', { mod: null }) // block__element
cn('element', { mod: false }) // block__element block__element_mod_false
If result is empty string, null will be returned instead, so React will not create unnecessary class attribute.
const cn = catnip('');
cn('') // null
const cn = catnip(styles);
cn('not-exists') // null
If there is no such class in CSS module it will be silently ignored
// CSS module have element_mod_true, but not element
cn('element', { mod: true }) // element_mod_true
Default element for CSS modules generator is root
cn({ mod: true }) // root root_mod_true
FAQs
BEM-flavoured class name generator. Works great with React and CSS modules
The npm package catnip receives a total of 7 weekly downloads. As such, catnip popularity was classified as not popular.
We found that catnip demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.