plur 0.4.0__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plur/__init__.py +48 -0
- plur/py.typed +0 -0
- {plur-0.4.0.dist-info → plur-1.1.0.dist-info}/METADATA +7 -8
- plur-1.1.0.dist-info/RECORD +5 -0
- {plur-0.4.0.dist-info → plur-1.1.0.dist-info}/WHEEL +1 -1
- plur-0.4.0.dist-info/RECORD +0 -4
- plur.py +0 -62
plur/__init__.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import typing as t
|
|
2
|
+
|
|
3
|
+
__all__ = (
|
|
4
|
+
'DEFAULT_PLURALS',
|
|
5
|
+
'plur',
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
DEFAULT_PLURALS = ('-s',)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def plur(
|
|
12
|
+
word: str,
|
|
13
|
+
*plurals: str,
|
|
14
|
+
sep: str = ' ',
|
|
15
|
+
num_first: bool = True,
|
|
16
|
+
zero: str = '',
|
|
17
|
+
) -> t.Callable[[t.Union[int, t.Sequence]], str]:
|
|
18
|
+
"""`plur()` returns a pluralizer
|
|
19
|
+
|
|
20
|
+
word:
|
|
21
|
+
The root word for a single item
|
|
22
|
+
|
|
23
|
+
plurals:
|
|
24
|
+
Zero or more plurals. If none are given, '-s' is used
|
|
25
|
+
|
|
26
|
+
sep:
|
|
27
|
+
The separator string between the number and the noun
|
|
28
|
+
|
|
29
|
+
num_first:
|
|
30
|
+
A boolean saying whether the number is written first or second
|
|
31
|
+
|
|
32
|
+
zero:
|
|
33
|
+
If there is a special case for zero items, it goes here
|
|
34
|
+
"""
|
|
35
|
+
plurals = plurals or DEFAULT_PLURALS
|
|
36
|
+
zero = zero or plurals[-1]
|
|
37
|
+
words = zero, word, *plurals
|
|
38
|
+
|
|
39
|
+
def pluralizer(count: t.Union[int, t.Sequence]) -> str:
|
|
40
|
+
n = len(count) if isinstance(count, t.Sequence) else count
|
|
41
|
+
i = min(n, len(words) - 1)
|
|
42
|
+
p = words[i]
|
|
43
|
+
if p.startswith('-'):
|
|
44
|
+
p = word + p[1:]
|
|
45
|
+
|
|
46
|
+
return f'{n}{sep}{p}' if num_first else f'{p}{sep}{n}'
|
|
47
|
+
|
|
48
|
+
return pluralizer
|
plur/py.typed
ADDED
|
File without changes
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: plur
|
|
3
|
-
Version:
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: 🔢 Simple universal word pluralizer 🔢
|
|
5
5
|
Author: Tom Ritchford
|
|
6
|
-
Author-email: tom@swirly.com
|
|
7
|
-
Requires-Python: >=3.8
|
|
6
|
+
Author-email: Tom Ritchford <tom@swirly.com>
|
|
8
7
|
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
11
8
|
Classifier: Programming Language :: Python :: 3.10
|
|
12
9
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
15
15
|
|
|
16
16
|
# plur: 🔢 simple universal word pluralizer 🔢
|
|
@@ -59,4 +59,3 @@ For words you use a lot, you can defer operation:
|
|
|
59
59
|
ox = plur('ox', '-en')
|
|
60
60
|
|
|
61
61
|
print(dog(dogs), 'live in my house with', ox(ox_list))
|
|
62
|
-
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
plur/__init__.py,sha256=ANCBfnsiOe5LFUZH5_10T3LqzPs3a2n62VQVOYa1T8o,1105
|
|
2
|
+
plur/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
plur-1.1.0.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
|
|
4
|
+
plur-1.1.0.dist-info/METADATA,sha256=-YWnVICzGfznL_W5PkC6zSmJhxYTZjij4bYVbWveUJU,1450
|
|
5
|
+
plur-1.1.0.dist-info/RECORD,,
|
plur-0.4.0.dist-info/RECORD
DELETED
plur.py
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
from numbers import Number
|
|
2
|
-
from typing import Sequence, Tuple, Union
|
|
3
|
-
import sys
|
|
4
|
-
|
|
5
|
-
__all__ = 'DEFAULT_PLURALS', 'plur',
|
|
6
|
-
|
|
7
|
-
DEFAULT_PLURALS = ['-s']
|
|
8
|
-
|
|
9
|
-
HasCount = Union[Number, Sequence]
|
|
10
|
-
Plural = Union[HasCount, str]
|
|
11
|
-
Plurals = Tuple[Plural, ...]
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def plur(
|
|
15
|
-
word: str,
|
|
16
|
-
*plurals: Plurals,
|
|
17
|
-
sep: str = ' ',
|
|
18
|
-
num_first: bool = True,
|
|
19
|
-
zero: str = '',
|
|
20
|
-
) -> str:
|
|
21
|
-
""" `plur()` pluralizes nouns.
|
|
22
|
-
|
|
23
|
-
word:
|
|
24
|
-
The root word for a single item
|
|
25
|
-
|
|
26
|
-
plurals:
|
|
27
|
-
Zero or more plurals. If none are given, '-s' is used
|
|
28
|
-
|
|
29
|
-
sep:
|
|
30
|
-
The separator string between the number and the noun
|
|
31
|
-
|
|
32
|
-
num_first:
|
|
33
|
-
A boolean saying whether the number is written first or second
|
|
34
|
-
|
|
35
|
-
zero:
|
|
36
|
-
If there is a special case for zero items, it goes here
|
|
37
|
-
"""
|
|
38
|
-
deferred = not plurals or isinstance(plurals[-1], str)
|
|
39
|
-
if not deferred:
|
|
40
|
-
*plurals, to_count = plurals
|
|
41
|
-
|
|
42
|
-
plurals = plurals or DEFAULT_PLURALS
|
|
43
|
-
zero = zero or plurals[-1]
|
|
44
|
-
words = zero, word, *plurals
|
|
45
|
-
|
|
46
|
-
def plur(n: HasCount) -> str:
|
|
47
|
-
if not isinstance(n, Number):
|
|
48
|
-
n = len(n)
|
|
49
|
-
|
|
50
|
-
i = min(n, len(words) - 1)
|
|
51
|
-
p = words[i]
|
|
52
|
-
if p.startswith('-'):
|
|
53
|
-
p = word + p[1:]
|
|
54
|
-
|
|
55
|
-
return f'{n}{sep}{p}' if num_first else f'{p}{sep}{n}'
|
|
56
|
-
|
|
57
|
-
return plur if deferred else plur(to_count)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if __name__ != '__main__':
|
|
61
|
-
[setattr(plur, k, globals()[k]) for k in __all__ + ('__all__',)]
|
|
62
|
-
sys.modules[__name__] = plur
|