wemake-services/recase

Consider using digits as separator in snake and related cases

jhchen opened this issue · 2 comments

Currently digits do not break up tokens in snake case and other (kebab case, dot case, constant case) so SnakeCase.convert("g2g") == "g2g". This is different from other implementations such as Lodash where _.lodash("g2g") === "g_2_g". I could not find an authoritative description of snake case as to which is the expected behavior but given the prevalence of Lodash, following its behavior might end up causing less surprise for developers/users.

After my fast research I found out, that it is a implementation detail of lodash only, since I did not find any other libraries that behave the same way.

What have I tried:

ruby's ActiveSupport

irb(main):001:0> require 'active_support/core_ext/string'
=> true
irb(main):002:0> 'g2g'.underscore
=> "g2g"

Link: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-underscore

python's stringcase

>>> import stringcase
>>> stringcase.snakecase('g2g')
'g2g'

Link: https://pypi.python.org/pypi/stringcase

elixir's Macro

iex(1)> Macro.underscore "g2g"
"g2g"

Link: https://hexdocs.pm/elixir/Macro.html#underscore/1

Conclusion

So, I guess without any solid reason we should not change this behavior.
Feel free to reopen this issue, if you do not agree with me.

No I agree given how other libraries behave. Thanks for digging into it!