tivac/modular-css

shortnames: Add possibility to set classname characters

Opened this issue ยท 2 comments

๐Ÿ‘‹ Hey, it would be great if it was possible to set characters, used in shortnames generated classes. For example, I'd prefer them to be only lowercase.

Feature Use Case

namer: shortnames({ letters: [a...z, 0...9] })

// or

namer: shortnames({ case: 'lower' })

Feature Proposal

Add option to set letters used in classes or letter case.

From source code, alphabet package is used inside which already has methods to return only lowercase/uppercase letters.

Btw shortnames is located under packages/namer, wondering why ๐Ÿค”

tivac commented

Btw shortnames is located under packages/namer, wondering why

That's left over from before this was a monorepo, hasn't been important to rename it but wanted to give the package a more-descriptive name on NPM.

I think this would be really easy to add, based on looking at namer.js:

module.exports = () => {

Would need to take an option like shortnames({ identifiers : [ ... ] }), and the default value should be the already-existing everything value from up above.

const everything = [ ...letters, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ];

Then it's a matter of using the identifiers param instead of everything whenever value(...) is called.

const output = value(letters, id) + value(everything, selectors.get(selector));

I have a package that generates short strings in a given alphabet: darthmaim/short-string.

I even wrote a package specifically for modular-css: darthmaim/modular-css-short-namer, but this will always use the default alphabet.