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

mangle-css-class-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mangle-css-class-webpack-plugin - npm Package Compare versions

Comparing version 4.0.3 to 4.0.5

lib/classGenerator.js

41

lib/optimizer.js
const { ReplaceSource } = require('webpack-sources');
const chalk = require('./chalk');
const classGenerator = require('./classGenerator');
const newClassMap = {};
let newClassSize = 0;
const reservedPrefixMap = {}
const acceptChars = 'abcdefghijklmnopqrstuvwxyz'.split('');
const acceptSuffixes = 'abcdefghijklmnopqrstuvwxyz0123456789'.split('');
const maximumClassNames = acceptChars.length * acceptSuffixes.length;
const generateClassName = (original, opts) => {
const cn = newClassMap[original];
if (cn) return cn;
const acceptCharsIndex = newClassSize % acceptChars.length;
const prefix = acceptChars[acceptCharsIndex];
const reservedPrefixCount = reservedPrefixMap[acceptCharsIndex] || 0;
let newClassName;
if (reservedPrefixCount === 0) {
newClassName = prefix;
reservedPrefixMap[acceptCharsIndex] = 1;
} else {
newClassName = prefix + acceptSuffixes[reservedPrefixCount - 1];
reservedPrefixMap[acceptCharsIndex]++;
}
newClassSize++;
if (newClassSize > maximumClassNames) {
throw Error('Maximum class names generated. Change the generator.');
}
if (opts.log) {
console.log(`Minify class name from ${chalk.green(original)} to ${chalk.green(newClassName)}`);
}
const newClass = {
name: newClassName,
usedBy: [],
};
newClassMap[original] = newClass;
return newClass;
};
const validate = (opts) => {

@@ -72,3 +35,3 @@ if (opts.log) return;

const originalName = match[1];
newClass = generateClassName(originalName, opts);
newClass = classGenerator.generateClassName(originalName, opts);
if (!source) source = new ReplaceSource(originalSource);

@@ -75,0 +38,0 @@ const startPos = match.index + match[0].indexOf(match[1]);

{
"name": "mangle-css-class-webpack-plugin",
"version": "4.0.3",
"version": "4.0.5",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Minifies and obfuscates the class names in your existing JavaScript, CSS, and HTML without any modern css modules.",

@@ -0,5 +1,7 @@

[![Build Status](https://travis-ci.org/sndyuk/mangle-css-class-webpack-plugin.svg?branch=master)](https://travis-ci.org/sndyuk/mangle-css-class-webpack-plugin)
<div align="center">
<a href="https://github.com/webpack/webpack">
<img width="100" height="100"
src="https://webpack.js.org/assets/icon-square-small.svg">
src="https://raw.githubusercontent.com/webpack/media/master/logo/icon-square-big.png">
</a>

@@ -6,0 +8,0 @@ <h1>mangle-css-class-webpack-plugin</h1>

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