File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ CheckKebabCase method checks the given string is in kebab-case or not.
3
+ Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)
4
+ """
5
+
6
+ import re
7
+
8
+
9
+ def is_kebab_case (var_name : str ) -> bool :
10
+ """
11
+ CheckKebabCase method checks the given string is in kebab-case or not.
12
+ Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)
13
+ >>> is_kebab_case('variable-name')
14
+ True
15
+ >>> is_kebab_case('VariableName')
16
+ False
17
+ >>> is_kebab_case('variable_name')
18
+ False
19
+ >>> is_kebab_case('variableName')
20
+ False
21
+ """
22
+
23
+ if not isinstance (var_name , str ):
24
+ raise TypeError ("Argument is not a string." )
25
+
26
+ pat = r"(\w+)-(\w)([\w-]*)"
27
+ return bool (re .match (pat , var_name )) and "_" not in var_name
28
+
29
+
30
+ if __name__ == "__main__" :
31
+ from doctest import testmod
32
+
33
+ testmod ()
34
+ input_var = input ("Enter the variable name: " ).strip ()
35
+
36
+ status = is_kebab_case (input_var )
37
+ print (f"{ input_var } is { 'in ' if status else 'not in ' } kebab-case." )
You can’t perform that action at this time.
0 commit comments