Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
`cs` is a lightweight (~.3kb) CSS utility function, similar to [Classnames](https://github.com/JedWatson/classnames) but with a very important distinction: **CS allows you to mix custom styles with class names**. This is great for working with utility cla
cs
User Guidecs
is a lightweight (~.3kb) CSS utility function, similar to Classnames but with a very important distinction: CS allows you to mix custom styles with class names. This is great for working with utility classes (e.g. tailwindcss, basscss) but still allowing the flexibility of custom styles.
For these style declarations, bring your own CSS-in-JS lib: emotion, otion, etc..
Even with CSS utility classes, there is always a need to reach for custom style properties. This is fine in many cases, but what about when you want to conditionally apply both a className and some custom styles? Generally, you would do this:
function Component() {
const [isEnabled, setIsEnabled] = React.useState();
return (
<div
className={isEnabled ? 'bold' : ''}
style={isEnabled ? { color: 'green' } : { opacity: 0.7 }}
/* I am now defining the styles related to the `isEnabled` flag in multiple spots. */
/* What happens if I want to add a single `style` property that always applies? Messy. */
>
Is Enabled?
</div>
);
}
Instead, use cs
to combine both classNames and style properties, like so:
// using `cs`
function Component() {
const [isEnabled, setIsEnabled] = React.useState();
return (
<div
className={cs(
isEnabled ? ['bold', { color: 'green' }] : { opacity: 0.7 }
)}
>
Is Enabled?
</div>
);
}
npm install @tibfib/cs
# or
yarn add @tibfib/cs
IMPORTANT: cs
exports a generator for you to create your own cs
function
// in some sort of utils.js file
import { generate } from '@tibfib/cs';
import { css } from '@emotion/css';
export const cs = generate(css);
// in usage
import { cs } from '../utils';
function Component() {
return (
<div classname={cs('bold', { color: 'yellow' })}>Bold Yellow Text</div>
);
}
For the cs
function, you can pass in:
string
s, which will be added as classes.falsy
values, which will be ignored: null
, undefined
, false
(this is to help with conditional logic)object
which will be forwarded along to the css
function you pass in to the generatorreturn (
<div className={cs('mb0', isEnabled ? 'bold' : { opacity: 0.5 })}>...</div>
);
return (
<div className={cs(isEnabled ? ['underline', { opacity: 0.1 }] : null)}>
...
</div>
);
classnames
?cs
allows you to use custom css in your classNames array. With classnames
, when you use an object, it will apply the keys of the object as classes based on the truthiness of the value.
cs
allows you to nest arrays of values, making it easy to conditionally apply both css classNames and custom styles together.
css
functions do you recommend?import { css } from 'otion';
import { generate } from '@tibfib/cs';
export const cs = generate(css);
import { css } from '@emotion/css';
import { generate } from '@tibfib/cs';
export const cs = generate(css);
Yes, as long as your css
function supports it. Both otion
and @emotion/css
do.
For older browsers, you will need to polyfill Array.prototype.flat
. (see core-js
)
styled-components
and their tagged template literal?Great question. Investigating support...
FAQs
`cs` is a lightweight (~.3kb) CSS utility function, similar to [Classnames](https://github.com/JedWatson/classnames) but with a very important distinction: **CS allows you to mix custom styles with class names**. This is great for working with utility cla
We found that @tibfib/cs 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.