File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed
Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 1313 { "command" : " convert_html_to_chars" , "caption" : " Convert HTML Entities to Chars" },
1414 { "caption" : " -" },
1515 { "command" : " convert_camel_underscores" , "caption" : " Convert camelCase <-> Underscores" },
16+ { "command" : " convert_camel_dash" , "caption" : " Convert camelCase <-> Dash" },
1617 { "command" : " convert_pascal_underscores" , "caption" : " Convert PascalCase <-> Underscores" },
1718 { "caption" : " -" },
1819 { "command" : " convert_single_quotes_to_double" , "caption" : " Convert Single Quotes To Double" },
Original file line number Diff line number Diff line change 2323 "caption" : " String Utilities: Convert camelCase <-> Underscores" ,
2424 "command" : " convert_camel_underscores"
2525 },
26+ {
27+ "caption" : " String Utilities: Convert camelCase <-> Dash" ,
28+ "command" : " convert_camel_dash"
29+ },
2630 {
2731 "caption" : " String Utilities: Convert PascalCase <-> Underscores" ,
2832 "command" : " convert_pascal_underscores"
Original file line number Diff line number Diff line change @@ -99,6 +99,22 @@ def toUnderscores(self, name):
9999 def toCamelCase (self , name ):
100100 return '' .join (ch .capitalize () if i > 0 else ch for i , ch in enumerate (name .split ('_' )))
101101
102+ class ConvertCamelDashCommand (sublime_plugin .TextCommand ):
103+ #Convert camelCase to dash and vice versa
104+ def run (self , edit ):
105+ for region in self .view .sel ():
106+ if not region .empty ():
107+ text = self .view .substr (region )
108+ text = self .toCamelCase (text ) if '-' in text and text [0 ].islower () else (text [0 ].islower () and self .toDash (text ))
109+ self .view .replace (edit , region , text )
110+
111+ def toDash (self , name ):
112+ s1 = re .sub ('(.)([A-Z][a-z]+)' , r'\1-\2' , name )
113+ return re .sub ('([a-z0-9])([A-Z])' , r'\1-\2' , s1 ).lower ()
114+
115+ def toCamelCase (self , name ):
116+ return '' .join (ch .capitalize () if i > 0 else ch for i , ch in enumerate (name .split ('-' )))
117+
102118
103119class ConvertPascalUnderscoresCommand (sublime_plugin .TextCommand ):
104120 #Convert PascalCase to under_scores and vice versa
You can’t perform that action at this time.
0 commit comments