DevToys-app / DevToys

A Swiss Army knife for developers.
https://devtoys.app/
MIT License
26.83k stars 1.44k forks source link

Conversion from camelCase or PascalCase to snake_case gives unexpected results #710

Open sylvain1811 opened 1 year ago

sylvain1811 commented 1 year ago

Description

TL;DR

Conversion to snake_case should be fixed

Explanations

Conversion from camelCase or PascalCase to snake case give unexpected results.

For an input written in camelCase or PascalCase, which use an upper case as word separator, the output of snake case conversion value lost separators.

Steps To Reproduce

  1. Go to Text Case Converter and Inspector
  2. Write myExampleInput
  3. Convert to snake_case

Expected behavior

Conversion of the camelCase string myExampleInput should give the snake_case string my_example_input.

DevToys Version

Version 1.0.10.0 | X64 | RELEASE | b949a18 | b949a18

Relevant Assets/Logs

ekansh-hash commented 1 year ago

Isn't snake_case supposed to add underscore only if there is any space in the string? I think snake_case conversion of myExampleInput should just give myexampleinput as the output (which is what we are getting in this instance).

heribertolugo commented 11 months ago

I think op interpretation is closer to what a dev would expect. Just as snake case would add underscore for a space, pascal/ camel would remove space and add/ convert to capital letter.

Using that train of thought, converting camel/ pascal to snake should add an underscore in place where the space would've been and demote the capital letter. I mean that would be the entire reason/ intention of why I would send a pascal through a snake converter - vs just sending the pascal through a toLowerCase() function.