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.
generic-names
Advanced tools
The `generic-names` package is a utility for generating generic names based on a pattern. It is commonly used in the context of CSS module development to create consistent and unique class names based on the file name and local name (class name) to avoid naming collisions. This package allows developers to customize the naming convention, making it a flexible tool for managing CSS class names in a modular fashion.
Generating generic names
This feature demonstrates how to generate a generic name using the `generic-names` package. The `generate` function takes a pattern and options as arguments. The pattern includes placeholders like `[name]`, `[local]`, and `[hash:base64:5]` which are replaced with the file name, local name (class name), and a hash respectively. The `context` option specifies the directory to consider as the root for relative paths. The generated name is unique and consistent, making it suitable for use as a CSS class name in modular CSS systems.
const generate = require('generic-names');
const nameGenerator = generate('[name]__[local]___[hash:base64:5]', { context: process.cwd() });
console.log(nameGenerator('className', '/path/to/file.css'));
The `classnames` package is a utility for conditionally joining classNames together. Unlike `generic-names`, which is focused on generating unique class names based on a pattern, `classnames` is used to dynamically construct class names based on the state of the application. It's more about managing class names in the runtime rather than generating them based on a static pattern.
The `css-loader` package is part of Webpack's loader system, and it interprets `@import` and `url()` like import/require() and will resolve them. It also has features for modularizing CSS by local scoping class names. While `css-loader` and `generic-names` both deal with CSS modules and class names, `css-loader` is more comprehensive, handling the loading and processing of CSS files, whereas `generic-names` focuses solely on generating names.
Helper for building generic names, similar to webpack. Designed to be used with postcss‑modules‑scope.
Uses interpolateName from the webpack/loader-utils.
var genericNames = require('generic-names');
var generate = genericNames('[name]__[local]___[hash:base64:5]', {
context: process.cwd()
});
generate('foo', '/case/source.css'); // 'source__foo___3mRq8'
FAQs
Helper for building generic names, similar to webpack
The npm package generic-names receives a total of 1,494,730 weekly downloads. As such, generic-names popularity was classified as popular.
We found that generic-names demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
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.