Remove semicolons, update imports
Remove semicolons from camel, update imports Remove semicolons in kebab, update imports
This commit is contained in:
@ -10,16 +10,16 @@ Use `title()` to capitalize the first letter of each word convert the rest to lo
|
||||
Finally, use `replace()` to remove spaces between words.
|
||||
|
||||
```py
|
||||
import re
|
||||
from re import sub
|
||||
|
||||
def camel(s):
|
||||
s = re.sub(r"(_|-)+", " ", s).title().replace(" ", "")
|
||||
s = sub(r"(_|-)+", " ", s).title().replace(" ", "")
|
||||
return s[0].lower() + s[1:]
|
||||
```
|
||||
|
||||
```py
|
||||
camel('some_database_field_name'); # 'someDatabaseFieldName'
|
||||
camel('Some label that needs to be camelized'); # 'someLabelThatNeedsToBeCamelized'
|
||||
camel('some-javascript-property'); # 'someJavascriptProperty'
|
||||
camel('some-mixed_string with spaces_underscores-and-hyphens'); # 'someMixedStringWithSpacesUnderscoresAndHyphens'
|
||||
camel('some_database_field_name') # 'someDatabaseFieldName'
|
||||
camel('Some label that needs to be camelized') # 'someLabelThatNeedsToBeCamelized'
|
||||
camel('some-javascript-property') # 'someJavascriptProperty'
|
||||
camel('some-mixed_string with spaces_underscores-and-hyphens') # 'someMixedStringWithSpacesUnderscoresAndHyphens'
|
||||
```
|
||||
|
||||
@ -8,18 +8,19 @@ Converts a string to kebab case.
|
||||
Break the string into words and combine them adding `-` as a separator, using a regexp.
|
||||
|
||||
```py
|
||||
import re
|
||||
from re import sub
|
||||
|
||||
def kebab(s):
|
||||
return re.sub(r"(\s|_|-)+","-",
|
||||
re.sub(r"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+",
|
||||
lambda mo: mo.group(0).lower(), s)
|
||||
)
|
||||
return sub(
|
||||
r"(\s|_|-)+","-",
|
||||
sub(
|
||||
r"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+",
|
||||
lambda mo: mo.group(0).lower(), s))
|
||||
```
|
||||
|
||||
```py
|
||||
kebab('camelCase'); # 'camel-case'
|
||||
kebab('some text'); # 'some-text'
|
||||
kebab('some-mixed_string With spaces_underscores-and-hyphens'); # 'some-mixed-string-with-spaces-underscores-and-hyphens'
|
||||
kebab('AllThe-small Things'); # "all-the-small-things"
|
||||
kebab('camelCase') # 'camel-case'
|
||||
kebab('some text') # 'some-text'
|
||||
kebab('some-mixed_string With spaces_underscores-and-hyphens') # 'some-mixed-string-with-spaces-underscores-and-hyphens'
|
||||
kebab('AllThe-small Things') # "all-the-small-things"
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user