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

(->snake_case :s3-key) ; => :s_3_key #22

Open
rsslldnphy opened this issue Nov 19, 2014 · 10 comments
Open

(->snake_case :s3-key) ; => :s_3_key #22

rsslldnphy opened this issue Nov 19, 2014 · 10 comments

Comments

@rsslldnphy
Copy link

Is there any way to avoid numbers creating separators? Had a quick scan of the code but couldn't see an obvious workaround. Thanks.

@qerub
Copy link
Collaborator

qerub commented Nov 19, 2014

This is quite tricky to solve correctly in the general case without first classifying the case of the input string. I've thought about it before but will look into it again this weekend. If you want to take a stab at it yourself, take a look at this expression: https://github.com/qerub/camel-snake-kebab/blob/master/src/camel_snake_kebab/internals/misc.cljx#L29

@rsslldnphy
Copy link
Author

Yes, it does seem like quite a tricky problem. The only thing I could think of was never adding split points when going from snake case to kebab case and vice versa, but this would mean conversions to and from camelcase would no longer be reversible, which doesn't sound ideal. Will have a ponder too.

@ToBeReplaced
Copy link
Contributor

The way I solved this in lettercase was to optionally allow the user to pass in their own separator regex. In your case, it would be (lower-underscore :s3-key #"-").

camel-snake-kebab has diverged a bunch from when we were similar in order to support CLJS, so enabling that is a bit tricky. I think one way you could do this is to enable you to pass the separators to classify-char and pass it all the way down from the top-level functions with varargs. Something like (->snake_case :s3-key :number []), which would prevent the split between s and 3.

Since you can't use a regex, perhaps better would be to name the split rules (ex. :whitespace or :number-after-letter) and then allow the user to omit rules on call.

@qerub
Copy link
Collaborator

qerub commented Nov 22, 2014

The way I solved this in lettercase was to optionally allow the user to pass in their own separator regex. […]

Yeah, this makes sense and can be viewed as a sort of manual classification of the input case. I'll give this approach a try in this shape:

(->snake_case ident :splitter \-)

(->CamelCase ident :splitter #"\s+")

An alternative I can think of is automatic classification based on the presence of certain chars (i.e. presence of \- will make split split on \-), but that gets very messy as soon as you put strings with multiple separator chars into the picture.

Another alternative would be to let the user state the expected input type (e.g. (->kebab-case ident :from snake_case) or (->kebab-case (<-snake_case ident)) which would also allow good input validation…

Since you can't use a regex […]

I can use regexes for simple char splits, just not for case shifts.

@qerub
Copy link
Collaborator

qerub commented Jan 10, 2015

I've created pull request #23 implementing the previously mentioned approach. Feedback is more than welcome.

@qerub
Copy link
Collaborator

qerub commented Jan 17, 2015

The just released version 0.3.0 allows you to do (->snake_case :s3-key :separator \-).

I'm leaving this issue open because I want a better solution.

@qerub qerub mentioned this issue Apr 6, 2015
@kenrestivo-stem
Copy link

There's a similar annoying problem with kebab-case"

  (csk/->kebab-case :s3_bucket_name)
;; >  :s-3-bucket-name

@agzam
Copy link

agzam commented Jul 8, 2019

Is there any update on this issue? I mean it's been hanging here since 2014 😱

@vincent-dm
Copy link

Yeah, I'd also very much like a way to disable letters followed by numbers being separated.

@waffletower
Copy link

waffletower commented Jun 28, 2023

A reminder that snake -> kebabs transforms containing non-leading numbers are not reversible:

(-> "a1_example"
    ->kebab-case-keyword
    ->snake_case_string)
"a_1_example"

(-> "a2a_example"
    ->kebab-case-keyword
    ->snake_case_string)
"a_2a_example"

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

7 participants