add batch
This commit is contained in:
18
layercake/layercake/strutils.py
Normal file
18
layercake/layercake/strutils.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import hashlib
|
||||
|
||||
|
||||
def first_word(s: str) -> str:
|
||||
"""Returns the first word from a string."""
|
||||
return s.split(' ', 1)[0]
|
||||
|
||||
|
||||
def truncate_str(s: str, maxlen: int = 30) -> str:
|
||||
"""Truncates a string to fit within a maximum length, adding '...' if truncated."""
|
||||
if len(s) <= maxlen:
|
||||
return s
|
||||
return s[: maxlen - 3] + '...'
|
||||
|
||||
|
||||
def md5_hash(s: str) -> str:
|
||||
"""Computes the MD5 hash of a string."""
|
||||
return hashlib.md5(s.encode()).hexdigest()
|
||||
Reference in New Issue
Block a user