New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hash-css-selector

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hash-css-selector

A function to hash CSS selectors, can be used with postcss-modules to generate short static unique class names

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
419
decreased by-4.77%
Maintainers
1
Weekly downloads
 
Created
Source

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'); // -> 'm-a530cc7d'
hashCSSSelector('another-test-class'); // -> 'm-c43ac187'

// Default prefix is 'm'
// Customize prefix by passing a second argument
hashCSSSelector('test-class', 'my-prefix'); // -> 'my-prefix-a530cc7d'

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

Keywords

FAQs

Package last updated on 26 Mar 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc