camel-snake-kebab
camel-snake-kebab copied to clipboard
digits problem.
(let [s "word100word"]
(= (->snake_case (->kebab-case s))
"word100word"))
=> false
becaouse
(->kebab-case "word100word")
=> "word-100-word"
(->snake_case "word-100-word")
=> "word_100_word"
(->snake_case "word100word")
=> "word_100word"
In my opinion numbers case should be recognised as a case of the preceding word
As discussed in #22, it's non-trivial to do a perfect job of generically splitting strings in the presence of digits. My current recommendation is to use the :separator argument if the generic splitter is causing problems:
(-> "word100word"
(->kebab-case :separator \_)
(->snake_case :separator \-))
; => "word100word"
My long-term plan is to revise the library to be slighly more flexible.
In my opinion numbers case should be recognised as a case of the preceding word
So you'd like (->kebab-case "word100word") to be "word100-word"?
Hello, well I know this is a rather old issue but as I found it when trying to solve this precise problem, I thought I would suggest my solution. Basically, follow up ->kebab-case with this function:
(defn- fixup-dash-number
"Fixup any instances of -[0-9] to be [0-9]."
[s]
(replace s #"\-([0-9])" "$1"))
So, perhaps this avoids the need to make something complex inside CSK? Or perhaps it provides an idea for an internal fix? OK, it's not very clever or optimal (being a fix after the event) but it is nice and simple.
I prefer numbers case should be recognised as a case of the preceding word also.
Here we did a dirty alter-var-root patch on our code base which change the line which defines the behavior.
https://gist.github.com/lotuc/fba421f74ea8610494118bc899f9f1b5#file-camel_snake_kebab_utils-clj-L35