Skip to content

Commit

Permalink
v1.2.1
Browse files Browse the repository at this point in the history
🚀 New Update Released: Added Support for Vue.js, Angular, and Plain HTML! 🎉
  • Loading branch information
ebokoo authored Nov 22, 2024
2 parents c6c68fb + 4aa0cb3 commit 18801be
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
index.js
node_modules
dist/index.js
dist/index.js
bun.lockb
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## 🚀 About
Prettier plugin that removes whitespaces of className
Prettier plugin that removes whitespaces of className, class


## 🗂 Install
Expand Down
41 changes: 31 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
const { parsers: typescriptParsers } = require('prettier/parser-typescript')
const { parsers: javascriptParsers } = require('prettier/parser-babel')
const { parsers: typescriptParsers } = require('prettier/parser-typescript');
const { parsers: javascriptParsers } = require('prettier/parser-babel');
const { parsers: htmlParsers } = require('prettier/parser-html');

function preprocess(text, opts) {
const classNamePattern = /className\s*=\s*["']([^"']+)["']/g
function preprocessClassName(text) {
const classNamePattern = /className\s*=\s*["']([^"']+)["']/g;
return text.replace(classNamePattern, (match, classNames) => {
const cleanClassNames = classNames.trim().replace(/\s+/g, ' ')
return `className="${cleanClassNames}"`
})
const cleanClassNames = classNames.trim().replace(/\s+/g, ' ');
return `className="${cleanClassNames}"`;
});
}

function preprocessClass(text) {
const classPattern = /class\s*=\s*["']([^"']+)["']/g;
return text.replace(classPattern, (match, classNames) => {
const cleanClassNames = classNames.trim().replace(/\s+/g, ' ');
return `class="${cleanClassNames}"`;
});
}

module.exports = {
parsers: {
typescript: {
...typescriptParsers.typescript,
preprocess
preprocess: preprocessClassName
},
babel: {
...javascriptParsers.babel,
preprocess
preprocess: preprocessClassName
},
vue: {
...htmlParsers.html,
preprocess: preprocessClass
},
angular: {
...htmlParsers.html,
preprocess: preprocessClass
},
html: {
...htmlParsers.html,
preprocess: preprocessClass
}
}
}
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@softonus/prettier-plugin-whitespace-remover",
"version": "1.0.1",
"description": "Prettier plugin that removes whitespaces of className",
"version": "1.2.1",
"description": "Prettier plugin that removes whitespaces of className, class",
"main": "dist/index.min.js",
"files": [
"dist/index.min.js"
Expand Down Expand Up @@ -33,7 +33,7 @@
"bugs": {
"url": "https://github.com/softonus-io/prettier-plugin-whitespace-remover/issues"
},
"homepage": "https://github.com/softonus-io/prettier-plugin-whitespace-remover#readme"
"homepage": "https://github.com/softonus-io/prettier-plugin-whitespace-remover#readme",
"license": "ISC",
"devDependencies": {
"@typescript-eslint/parser": "^7.6.0",
Expand Down

0 comments on commit 18801be

Please sign in to comment.