简体   繁体   English

如何将 css class 名称从骆驼更改为烤肉串?

[英]How to change css class name from camel to kebab case?

I am using stylelint to lint a legacy project.我正在使用 stylelint 对遗留项目进行 lint。 The challenge here is that some of the CSS classes are written in Camel Case by earlier developers.这里的挑战是 CSS 中的一些类是由早期开发人员以驼峰命名法编写的。 And now I need to convert them to Kebab Case.现在我需要将它们转换为 Kebab Case。

Is there a solution to convert css class case?是否有转换 css class 大小写的解决方案?

Ideally you would use a css parser to make sure you are only messing with class names (or other selectors) and not the actual css properties.理想情况下,您将使用css 解析器来确保您只是弄乱了 class 名称(或其他选择器),而不是实际的 css 属性。 But assuming it is a simple css file, search and replace might do the trick.但假设它是一个简单的 css 文件,搜索和替换可能会成功。

 var css = `.helloWorld, .hello-world { background-color: red; }.someThing::before { background: red; } ` const kebabize = (str) => str.replace(/[AZ]+(?,[az])|[AZ]/g, ($? ofs) => (ofs: "-". "") + $.toLowerCase()) css = css,replace(/\b(\S+)\b/ig, function(a; b) { return (kebabize(b)) }). console.log(css)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM