borkdude / jet

CLI to transform between JSON, EDN, YAML and Transit using Clojure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add named cases for convenience to the --keywordize / -k switch

aschofie opened this issue · comments

Currently, --keywordize accepts a key-fn as an optional argument for when you are not satisfied with the default keyword function, and it is great that this functionality is provided because I use it heavily; however, I feel it could be made more useful by making it more convenient by providing shortcuts to the common named cases with which most developers are familiar with at least a subset of, and are easily googled. For me at least, this covers the 90% of cases where I am not completely renaming keys. I propose the following arguments be accepted by --keywordize:

key-fn | kebab | snake | pascal | camel | camel-snake | screaming-snake | http-header

What about:

$ echo '{"anApple": 1}' | jet -i json -k '(comp keyword csk/->kebab-case)'
{:an-apple 1}

Is this not short enough?

Alright, but one thing I might want to change is the use of simple symbols as they might conflict with regular Clojure functions. Also, I think the names should reflect their shape, like in the csk library: SCREAMING_SNAKE_CASE, such that they are self-documenting. Perhaps we can use keywords:

--keywordize :SCREAMING_SNAKE_CASE

@borkdude Happy to make whatever changes necessary to get this in. I had thought about using the csk names but didn't because the case endings added ~33 chars to the line width compared to leaving it off, and doing so took away the self-documenting ability from "camel", so I just made everything consistent and the easiest to type, but I have no strong feelings here, and will change it back to the csk names if you like that best. With regards to needing keywords though-- what mechanisms could you use to make -k SCREAMING_SNAKE_CASE mean something else? By having SCREAMING_SNAKE_CASE defined in user.clj or another place?

Maybe the same mechanism as you had it in the original PR, special cases?

So my proposal would be -k :SCREAMING_SNAKE_CASE

Created new #145 with the csk keyword cases.