Created
September 27, 2022 15:58
-
-
Save CodePint/15560ae824e1b030c7a232a2bdf051ba to your computer and use it in GitHub Desktop.
detect what case a string is in using python humps package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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