-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (25 loc) · 717 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const { parsers: typescriptParsers } = require('prettier/parser-typescript')
const { parsers: javascriptParsers } = require('prettier/parser-babel')
function preprocess(text, opts) {
const classNamePattern = /className\s*=\s*["']([^"']+)["']/g
return text.replace(classNamePattern, (match, classNames) => {
const cleanClassNames = classNames
.trim()
.split(/\s+/)
.filter((item, index, self) => self.indexOf(item) === index)
.join(' ')
return `className="${cleanClassNames}"`
})
}
module.exports = {
parsers: {
typescript: {
...typescriptParsers.typescript,
preprocess
},
babel: {
...javascriptParsers.babel,
preprocess
}
}
}