denoland / std

The Deno Standard Library
https://jsr.io/@std
MIT License
3.24k stars 624 forks source link

add string case utilities #3125

Closed andrewbrey closed 10 months ago

andrewbrey commented 1 year ago

Today, there are no string case utilities in the std lib, but one need only look around to npm briefly to see that there is a healthy appetite for shared modules to handle the complexities of converting strings between different cases:

Note that lodash has lots of string utilities that would be excellent to have "official" std lib support for

Some of these examples are "general" string case conversion modules, and others are for a specific case conversion (and in the case of lodash.deburr it is a module for removing diacritical marks from Latin character sets to make the case conversions more reliable).

I myself incorporate case via npm: specifiers in my largest Deno project because having access to a well tested and well implemented module to convert a string to:

which handles the edge cases around diacritical marks, weird spacing, etc is very helpful.

I saw https://github.com/denoland/deno_std/pull/3124 which attempts to establish a strings module category for the std lib, so these are related requests, though neither depends on the other.

Thank you for considering, and thank you for Deno (and the excellent std lib)!

naltun commented 1 year ago

@andrewbrey do you see this being part of an existing module or something new?

E: I think this could easily be added to fmt.

As per the discussion in #3124, a strings module might be unneeded. I do think a fmt/case.ts file would be very useful. I'd be interested in coding this.

andrewbrey commented 1 year ago

do you see this being part of an existing module or something new?

That's not something I have an opinion on - I mentioned the related PR because it's attempting to establish a strings top-level folder in the stdlib, where I could see the outcome of this feature request living, but I could also see this feature request tucking neatly within the existing fmt top-level folder as well.

iuioiua commented 10 months ago

This has been mostly completed in #4082. Functions for more casing will be handled in new issues. Thank you for the suggestions and contributions.

guy-borderless commented 5 months ago

Was just reaching for a CONSTANT_CASE function and realized it doesn't exist. Needed to dynamically generate an env variable name. I think this should be added.

kt3k commented 5 months ago

Is CONSTANT_CASE the common name? I found one usage in https://www.npmjs.com/package/change-case, but wikipedia and MDN seem referencing it is SCREAMING_SNAKE_CASE https://en.wikipedia.org/wiki/Snake_case https://developer.mozilla.org/en-US/docs/Glossary/Snake_case

guy-borderless commented 5 months ago

Is CONSTANT_CASE the common name? I found one usage in https://www.npmjs.com/package/change-case, but wikipedia and MDN seem referencing it is SCREAMING_SNAKE_CASE https://en.wikipedia.org/wiki/Snake_case https://developer.mozilla.org/en-US/docs/Glossary/Snake_case

I think CONSTANT is the most common and understandable for devs. However IMHO no problem to export a symbol with more than one name when different names exist. But I think if you need one, constantCase is more common than SCREAMING_SNAKE_CASE. CAPITAL_SNAKE_CASE is maybe a more literal name, regardless of what's common.

guy-borderless commented 5 months ago

Anyway, I don't mind that much. Hope it gets added.

BlackAsLight commented 5 months ago

Was just reaching for a CONSTANT_CASE function and realized it doesn't exist. Needed to dynamically generate an env variable name. I think this should be added.

What is your use case for a dynamic env variable? This sounds like a similar thing situation to wanting dynamic variable names.

guy-borderless commented 5 months ago

Was just reaching for a CONSTANT_CASE function and realized it doesn't exist. Needed to dynamically generate an env variable name. I think this should be added.

What is your use case for a dynamic env variable? This sounds like a similar thing situation to wanting dynamic variable names.

the scenario is using a convention for env var names.

iuioiua commented 5 months ago

Good idea. A PR would be welcome. CONSTANT_CASE makes sense to me, and I'd expect most devs to understand it. Also, it's shorter. As long as the name makes sense 🤷🏾‍♂️