1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
Files
netbox-community-netbox/netbox/utilities/string.py

19 lines
429 B
Python
Raw Permalink Normal View History

__all__ = (
'title',
2024-03-22 14:59:04 -04:00
'trailing_slash',
)
def title(value):
"""
Improved implementation of str.title(); retains all existing uppercase letters.
"""
return ' '.join([w[0].upper() + w[1:] for w in str(value).split()])
2024-03-22 14:59:04 -04:00
def trailing_slash(value):
"""
Remove a leading slash (if any) and include a trailing slash, except for empty strings.
"""
return f'{value.strip("/")}/' if value else ''