Skip to content

Instantly share code, notes, and snippets.

@CodePint
Created September 27, 2022 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodePint/fba5154d70b2ac572fb9240f47cea79b to your computer and use it in GitHub Desktop.
Save CodePint/fba5154d70b2ac572fb9240f47cea79b to your computer and use it in GitHub Desktop.
import humps
def detect_case(value):
for case in ['snake', 'camel', 'pascal', 'kebab']:
if getattr(humps, f"is_{case}case")(value):
return case
return 'unknown'
detect_case("im_in_this_big_ass_coat") # snake
detect_case"illWearYourGranddadsClothes") # camel
detect_case("ILookIncredible") # pascal
detect_case('from-that-thrift-shop') # kebab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment