string
zettelkasten_id
zettelkasten_id() -> str
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:
-
str(str) –A formatted unique identifier (e.g., "abc123def.ghi45678901").
Examples:
>>> 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 | |
unique_id
unique_id() -> str
Generate a unique identifier.
This function returns a unique identifier as a hexadecimal string generated from a UUID.
Returns:
-
str(str) –A unique hexadecimal identifier (e.g., "3f8a7c2d1e9b4a6f8d0e2c1b3a5f7e9d").
Examples:
>>> 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 | |
format_memory
format_memory(nbytes: int | None) -> str
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:
-
nbytes(int | None) –The memory size in bytes, or None for "0 bytes".
Returns:
-
str(str) –The memory size in a human-readable format.
Examples:
>>> 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 | |
capitalize_string
capitalize_string(string: str, separator: str = ' ') -> str
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:
-
string(str) –The string to be capitalized.
-
separator(str, default:' ') –The separator to use for splitting and joining the string. Defaults to " ".
Returns:
-
str(str) –The capitalized string.
Examples:
>>> 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 | |
string2date
string2date(date_string: str) -> dict[str, int | str | None]
Parses various date string formats ('YYYY', 'YYYY-MM', 'YYYY-MM-DD') and returns a dictionary with the month as a three-letter abbreviation.
Parameters:
-
date_string(str) –The input date string.
Returns:
-
dict[str, int | str | None]–dict[str, int | str | None]: Keys
year,month, andday. -
dict[str, int | str | None]–Missing parts are
None.
Examples:
>>> parsed = string2date("2024-03-15")
>>> parsed["year"], parsed["day"]
(2024, 15)
>>> string2date("2024")["day"] is None
True
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 139 140 141 142 143 144 145 | |