String Module
capitalize_string(string, separator=' ')
Capitalize each word in a string using a specified separator.
Splits the input string by the given separator, capitalizes the first letter of each part, and then joins the parts back together using the same separator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
The string to be capitalized. |
required |
separator
|
str
|
The separator to use for splitting and joining the string. Defaults to " ". |
' '
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The capitalized string. |
Example
capitalize_string("hello world") 'Hello World' capitalize_string("john-doe", separator="-") 'John-Doe'
Source code in ures/string.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
format_memory(nbytes)
Format a memory size into a human-readable string.
Converts a memory size in bytes into a formatted string using appropriate units (B, KB, MB, or GB) with two decimal places of precision. If the provided value is None, it returns "0 bytes".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nbytes
|
int | None
|
The memory size in bytes, or None for "0 bytes". |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The memory size in a human-readable format. |
Example
format_memory(1024) '1.00 KB' format_memory(1048576) '1.00 MB'
Source code in ures/string.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
string2date(date_string)
Parses various date string formats ('YYYY', 'YYYY-MM', 'YYYY-MM-DD') and returns a dictionary with the month as a three-letter abbreviation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_string
|
str
|
The input date string. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int | str | None]
|
A dictionary like {'year': YYYY, 'month': 'Mon', 'day': DD}. |
dict[str, int | str | None]
|
Missing parts have a value of None. |
Source code in ures/string.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
unique_id()
Generate a unique identifier.
This function returns a unique identifier as a hexadecimal string generated from a UUID.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A unique hexadecimal identifier (e.g., "3f8a7c2d1e9b4a6f8d0e2c1b3a5f7e9d"). |
Example
uid = unique_id() len(uid) == 32 True
Source code in ures/string.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
zettelkasten_id()
Generate a Zettelkasten identifier.
This function creates a unique identifier suitable for a Zettelkasten note-taking system. It generates a UUID, then formats the hexadecimal string by taking the first 9 characters, appending a dot, and then the last 11 characters of the UUID.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A formatted unique identifier (e.g., "abc123def.ghi45678901"). |
Example
id_str = zettelkasten_id() isinstance(id_str, str) True
Source code in ures/string.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |