153. uglify CSS class names
Share
medium - accepted / - tried
If you use css-loader in your webpack project,
localIdentName
could be used to transform class names, like below:
localIdentName: "[path][name]__[local]--[hash:base64:5]",
Or you can create your own function to generate class names by setting getLocalIdent
.
Now please create a function to generate unique class names following rules below.
- only use alphabets:
a
toz
,A
toZ
- return one unique class name each time function is called
- the class name sequence should first be in order of length, then in Alphabetical order(lowercase in front).
- should provide a function to reset the sequence
getUniqueClassName()
// 'a'
getUniqueClassName()
// 'b'
getUniqueClassName()
// 'c'
// skip cases till 'Y'
getUniqueClassName()
// 'Z'
getUniqueClassName()
// 'aa'
getUniqueClassName()
// 'ab'
getUniqueClassName()
// 'ac'
// skip more cases
getUniqueClassName()
// 'ZZ'
getUniqueClassName()
// 'aaa'
getUniqueClassName()
// 'aab'
getUniqueClassName()
// 'aac'
getUniqueClassName.reset()
getUniqueClassName()
// 'a'