1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +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 .asyncify import asyncify
from .safeformat import safeformat from .safeformat import safeformat
from .sleep_until import sleep_until 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 .urluuid import to_urluuid, from_urluuid
from .multilock import MultiLock from .multilock import MultiLock
__all__ = [ __all__ = [
"asyncify", "asyncify",
"safeformat", "safeformat",
"cdj",
"sleep_until", "sleep_until",
"plusformat",
"andformat", "andformat",
"plusformat",
"underscorize", "underscorize",
"ytdldateformat", "ytdldateformat",
"numberemojiformat", "numberemojiformat",
"telegram_escape",
"discord_escape",
"splitstring",
"ordinalformat", "ordinalformat",
"to_urluuid", "to_urluuid",
"from_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: 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", "🔟"] number_emojis = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "🔟"]
extra_emoji = "*️⃣" extra_emoji = "*️⃣"
result = "" result = ""
@ -91,15 +106,30 @@ def numberemojiformat(l: typing.List[str]) -> str:
return result return result
def splitstring(s: str, max: int) -> typing.List[str]: def ordinalformat(number: int) -> str:
l = [] """Convert a :class:`int` to the corresponding English ordinal :class:`str`.
while s:
l.append(s[:max])
s = s[max:]
return l
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: if 10 <= number % 100 < 20:
return f"{number}th" return f"{number}th"
if number % 10 == 1: if number % 10 == 1: