Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

digits problem. #31

Open
ribelo opened this issue Apr 4, 2015 · 3 comments
Open

digits problem. #31

ribelo opened this issue Apr 4, 2015 · 3 comments

Comments

@ribelo
Copy link

ribelo commented Apr 4, 2015

(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

@qerub
Copy link
Collaborator

qerub commented Apr 6, 2015

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"?

@mdaley
Copy link

mdaley commented Mar 24, 2017

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.

@lotuc
Copy link

lotuc commented May 6, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants