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/15560ae824e1b030c7a232a2bdf051ba to your computer and use it in GitHub Desktop.
Save CodePint/15560ae824e1b030c7a232a2bdf051ba to your computer and use it in GitHub Desktop.
detect what case a string is in using python humps package
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