Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-preprocess-cssmodules

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-preprocess-cssmodules - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

5

CHANGELOG.md
# Svelte preprocess CSS Modules, changelog
## 1.1.1
- Fix the use of `[path]` in the `localIdentName` rule.
- Escape css on the classname
- Dependencies update
## 1.1.0

@@ -4,0 +9,0 @@ - Add optional shortand syntax `$.MY_CLASSNAME` to increase development speed and remove verbosity.

32

index.js

@@ -1,3 +0,4 @@

const path = require('path')
const { interpolateName } = require('loader-utils')
const path = require('path');
const cssesc = require('cssesc');
const { interpolateName } = require('loader-utils');

@@ -7,3 +8,3 @@ const pluginOptions = {

localIdentName: '[local]-[hash:base64:6]'
}
};

@@ -13,2 +14,3 @@ const regex = {

style: /<style(\s[^]*?)?>([^]*?)<\/style>/gi,
pathUnallowed: /[<>:"/\\|?*]/g,
class: (className) => {

@@ -22,15 +24,23 @@ return new RegExp(`\\.(${className})\\b(?![-_])`, 'gm')

function generateName(resourcePath, styles, className) {
const filePath = resourcePath
const fileName = path.basename(filePath)
const filePath = resourcePath;
const fileName = path.basename(filePath);
const localName = pluginOptions.localIdentName.length
? pluginOptions.localIdentName.replace(/\[local\]/gi, () => className)
: className
: className;
const content = `${styles}-${filePath}-${fileName}-${className}`
const content = `${styles}-${filePath}-${fileName}-${className}`;
let interpolatedName = interpolateName({ resourcePath }, localName, { content })
let interpolatedName = cssesc(
interpolateName({ resourcePath }, localName, { content })
.replace(/\./g, '-')
);
// replace unwanted characters from [path]
if (regex.pathUnallowed.test(interpolatedName)) {
interpolatedName = interpolatedName.replace(regex.pathUnallowed, '_');
}
// prevent class error when the generated classname starts from a non word charater
if (/^(?![a-zA-Z_])/.test(interpolatedName)) {
interpolatedName = `_${interpolatedName}`
interpolatedName = `_${interpolatedName}`;
}

@@ -40,6 +50,6 @@

if (interpolatedName.slice(-1) === '-') {
interpolatedName = interpolatedName.slice(0, -1)
interpolatedName = interpolatedName.slice(0, -1);
}
return interpolatedName
return interpolatedName;
}

@@ -46,0 +56,0 @@

{
"name": "svelte-preprocess-cssmodules",
"version": "1.1.0",
"version": "1.1.1",
"description": "Svelte preprocessor to generate CSS Modules classname on Svelte components",

@@ -30,2 +30,3 @@ "keywords": [

"dependencies": {
"cssesc": "^3.0.0",
"loader-utils": "^2.0.0"

@@ -32,0 +33,0 @@ },

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