deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

add string case utilities

Open andrewbrey opened this issue 2 years ago • 2 comments
trafficstars

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:

  • upper (UPPER CASE)
  • lower (lower case)
  • title (Title Case)
  • snake (snake_case)
  • pascal (PascalCase)
  • camel (camelCase)
  • kebab (kebab-case)
  • constant (CONSTANT_CASE)

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)!

andrewbrey avatar Jan 18 '23 19:01 andrewbrey

@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.

naltun avatar Jan 19 '23 20:01 naltun

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.

andrewbrey avatar Jan 19 '23 20:01 andrewbrey

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

iuioiua avatar Jan 10 '24 10:01 iuioiua

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.

guy-borderless avatar Jun 20 '24 09:06 guy-borderless

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

kt3k avatar Jun 20 '24 10:06 kt3k

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 avatar Jun 20 '24 10:06 guy-borderless

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

guy-borderless avatar Jun 20 '24 10:06 guy-borderless

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.

BlackAsLight avatar Jun 20 '24 10:06 BlackAsLight

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.

guy-borderless avatar Jun 20 '24 10:06 guy-borderless

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 🤷🏾‍♂️

iuioiua avatar Jun 20 '24 10:06 iuioiua