What is generic-names?
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'));