1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Document formatters (and remove splitstring)

This commit is contained in:
Steffo 2019-11-17 18:58:14 +01:00
parent 4764e27d72
commit 8148e6f44e
2 changed files with 38 additions and 14 deletions

View file

@ -1,24 +1,18 @@
from .asyncify import asyncify
from .safeformat import safeformat
from .sleep_until import sleep_until
from .formatters import andformat, underscorize, ytdldateformat, numberemojiformat, splitstring, ordinalformat
from .formatters import andformat, underscorize, ytdldateformat, numberemojiformat, ordinalformat
from .urluuid import to_urluuid, from_urluuid
from .multilock import MultiLock
__all__ = [
"asyncify",
"safeformat",
"cdj",
"sleep_until",
"plusformat",
"andformat",
"plusformat",
"underscorize",
"ytdldateformat",
"numberemojiformat",
"telegram_escape",
"discord_escape",
"splitstring",
"ordinalformat",
"to_urluuid",
"from_urluuid",

View file

@ -80,6 +80,21 @@ def ytdldateformat(string: typing.Optional[str], separator: str = "-") -> str:
def numberemojiformat(l: typing.List[str]) -> str:
"""Convert a :class:`list` to a Unicode string with one item on every line numbered with emojis.
Parameters:
l: the list to convert.
Returns:
The resulting Unicode string.
Examples:
::
>>> numberemojiformat(["First", "Second", "Third"])
"1⃣ First\n2⃣ Second\n3⃣ Third\n"
>>> numberemojiformat(list(range(13)))
"1⃣ 1\n2⃣ 2\n3⃣ 3\n4⃣ 4\n5⃣ 5\n6⃣ 6\n7⃣ 7\n8⃣ 8\n9⃣ 9\n🔟 10\n*️⃣ 11\n*️⃣ 12"
"""
number_emojis = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "🔟"]
extra_emoji = "*️⃣"
result = ""
@ -91,15 +106,30 @@ def numberemojiformat(l: typing.List[str]) -> str:
return result
def splitstring(s: str, max: int) -> typing.List[str]:
l = []
while s:
l.append(s[:max])
s = s[max:]
return l
def ordinalformat(number: int) -> str:
"""Convert a :class:`int` to the corresponding English ordinal :class:`str`.
Parameters:
number: the number to convert.
def ordinalformat(number: int):
Returns:
The corresponding English `ordinal numeral <https://en.wikipedia.org/wiki/Ordinal_numeral>`.
Examples:
::
>>> ordinalformat(1)
"1st"
>>> ordinalformat(2)
"2nd"
>>> ordinalformat(11)
"11th"
>>> ordinalformat(101)
"101st"
>>> ordinalformat(112)
"112th"
>>> ordinalformat(0)
"0th"
"""
if 10 <= number % 100 < 20:
return f"{number}th"
if number % 10 == 1: