I have problems when using postcss-modules to obfuscate class names.
I add the prefix and suffix to start and end of class names likes .ABC_className_XYZ.
And now when writing JS(Jquery), I need to convert the class name to the same format.
I write a function to convert that.
But now, whenever i write JS(Jquery) i will have to write in the format $(className("some_class_name")).
Does anyone have a solution to modify the queryselector, so that we only need to write the class of the element each time, without passing it through the name conversion function?
NOTE: could somehow include all query functions like: $(), addClass(), removeClass(), hasClass(), closets(), ....
And it only changes with the class, the id and tag won't change
Thank you very much.
Here is one solution, monkey patch:
$__ = (function(cls){
const myHash = {};
return function(cls){
let converted = myHash[cls] || (myHash[cls] = className(cls));
return $_(converted);
}
}());
If you want replace $__ with $_ directly, or maybe Jquery has an inbuilt method to modify prototype methods, you might want to check that first