hash-css-selector
A function to hash CSS selectors, can be used with postcss-modules to generate short static unique class names.
Usage
hashCSSSelector
returns a 8 character long hash of the given string. The function is deterministic, so the same input will always result in the same output.
import { hashCSSSelector } from 'hash-css-selector';
hashCSSSelector('test-class');
hashCSSSelector('another-test-class');
hashCSSSelector('test-class', 'my-prefix');
Usage with postcss-modules
With default m
prefix:
import { generateScopedName } from 'hash-css-selector';
postcss([
require('postcss-modules')({
generateScopedName: generateScopedName,
}),
]);
With custom prefix:
import { createGenerateScopedName } from 'hash-css-selector';
postcss([
require('postcss-modules')({
generateScopedName: createGenerateScopedName('custom-prefix'),
}),
]);
License
MIT