Skip to content

Commit 48639f4

Browse files
committed
1. Change the default alphabet in utils.base_encode to "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", which follows the order of ASCII characters.
1 parent 17c2616 commit 48639f4

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
### 1.2.0 (2025-03-03)
1+
### 1.2.2 (2025-03-04)
2+
1. Change the default alphabet in `utils.base_encode` to "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", which follows the order of ASCII characters.
3+
4+
### 1.2.1 (2025-03-03)
25
1. add `utils.get_size` to get size of objects recursively.
36
2. add `base_encode, base_decode, gen_id, timeti` to `utils`
47
3. add alias for AsyncQueueListener: `functools.async_logger`

doc.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@
11071107

11081108
Args:
11091109
num (int): The number to encode.
1110-
alphabet (str, optional): Defaults to "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".
1110+
alphabet (str, optional): Defaults to "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", which follows the order of ASCII characters.
11111111

11121112
Returns:
11131113
str: The encoded string.
@@ -1118,9 +1118,12 @@
11181118
>>> base_encode(1)
11191119
'1'
11201120
>>> base_encode(10000000000000)
1121-
'2Q3rKTOE'
1121+
'2q3Rktoe'
11221122
>>> base_encode(10000000000000, "0123456789")
11231123
'10000000000000'
1124+
>>> a = [base_encode(i).zfill(10) for i in range(10000)]
1125+
>>> sorted(a) == a
1126+
True
11241127

11251128
```
11261129

morebuiltins/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "1.2.1"
1+
__version__ = "1.2.2"
22
__all__ = [
33
"morebuiltins.utils",
44
"morebuiltins.date",

morebuiltins/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,13 +1774,13 @@ def get_size(obj, seen=None, iterate_unsafe=False) -> int:
17741774

17751775
def base_encode(
17761776
num: int,
1777-
alphabet: str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
1777+
alphabet: str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
17781778
) -> str:
17791779
"""Encode a number to a base-N string.
17801780
17811781
Args:
17821782
num (int): The number to encode.
1783-
alphabet (str, optional): Defaults to "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".
1783+
alphabet (str, optional): Defaults to "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", which follows the order of ASCII characters.
17841784
17851785
Returns:
17861786
str: The encoded string.
@@ -1791,9 +1791,12 @@ def base_encode(
17911791
>>> base_encode(1)
17921792
'1'
17931793
>>> base_encode(10000000000000)
1794-
'2Q3rKTOE'
1794+
'2q3Rktoe'
17951795
>>> base_encode(10000000000000, "0123456789")
17961796
'10000000000000'
1797+
>>> a = [base_encode(i).zfill(10) for i in range(10000)]
1798+
>>> sorted(a) == a
1799+
True
17971800
"""
17981801
length = len(alphabet)
17991802
result = ""

0 commit comments

Comments
 (0)