plur 0.4.0__py3-none-any.whl → 1.0.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 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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: plur
3
- Version: 0.4.0
3
+ Version: 1.0.0
4
4
  Summary: 🔢 Simple universal word pluralizer 🔢
5
5
  Author: Tom Ritchford
6
6
  Author-email: tom@swirly.com
@@ -10,7 +10,6 @@ Classifier: Programming Language :: Python :: 3.8
10
10
  Classifier: Programming Language :: Python :: 3.9
11
11
  Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
- Requires-Dist: flake8-pyproject (>=1.2.0,<2.0.0)
14
13
  Description-Content-Type: text/markdown
15
14
 
16
15
  # plur: 🔢 simple universal word pluralizer 🔢
@@ -0,0 +1,5 @@
1
+ plur/__init__.py,sha256=SxaKx2jY-zn60-LdAdFIGPkL-IRzzNiI2GW-4obdbTA,1105
2
+ plur/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ plur-1.0.0.dist-info/METADATA,sha256=lHkuKaZ6i8HWTAlMqpM_jHhw71355MahMQ8kTy8EzFc,1381
4
+ plur-1.0.0.dist-info/WHEEL,sha256=WGfLGfLX43Ei_YORXSnT54hxFygu34kMpcQdmgmEwCQ,88
5
+ plur-1.0.0.dist-info/RECORD,,
@@ -1,4 +0,0 @@
1
- plur.py,sha256=XjBiY4T6vnW-SecK0Thbs2itAjQj3aeO5aoYNVhalNI,1474
2
- plur-0.4.0.dist-info/METADATA,sha256=puJmPUQmjQCR4r0RqH1dSJFFk0LayPoXx2Zm3C_MC7Y,1430
3
- plur-0.4.0.dist-info/WHEEL,sha256=WGfLGfLX43Ei_YORXSnT54hxFygu34kMpcQdmgmEwCQ,88
4
- plur-0.4.0.dist-info/RECORD,,
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
File without changes