Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
unique-classname.macro
Advanced tools
This is a babel-macros to generate unique className for css-in-js.
If you are coming from CSS modules and want to convert a large code base to emotion
, sometimes you might have some empty classNames added to the container div as state of the component.
For example. You might have React component like this
import classNames from 'classnames'
import styles from './styles.css'
const MyComponent = ({ isDisabled }) => (
<div
className={classNames(
styles.container,
isDisabled ? styles.isDisabled : false
)}
>
<div className={styles.content}>Content</div>
</div>
)
and your styles looks like this:
.container {
background: white;
}
.content {
padding: 10px;
.disabled & {
cursor: not-allowed;
color: '#777';
}
}
With unique-classname.macro
, it will help you generate a hash from both filename and variable name.
With babel-macros and this package installed, you can use it like this.
import className from 'unique-classname.macro'
import { css } from 'emotion'
const disabledClass = className() // or const disabled = className('disabled')
const containerClass = css`
background: white;
`
const contentClass = css`
padding: 10px;
.${disabled} & {
cursor: not-allowed;
color: '#777';
}
`
const MyComponent = ({ isDisabled }) => (
<div
className={classNames(containerClass, isDisabled ? disabledClass : false)}
>
<div className={contentClass}>Content</div>
</div>
)
The above snippet will be compiled in build time:
import className from 'unique-classname.macro'
import { css } from 'emotion'
const disabled = 'disabled-1u6x1nq'
const container = css`
background: white;
`
const content = css`
padding: 10px;
.${disabled} & {
cursor: not-allowed;
color: '#777';
}
`
FAQs
Babel Plugin Macro to generate unique className
The npm package unique-classname.macro receives a total of 2 weekly downloads. As such, unique-classname.macro popularity was classified as not popular.
We found that unique-classname.macro 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.