mpl-richtext 0.1.7__py3-none-any.whl → 0.1.8__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.
mpl_richtext/__init__.py CHANGED
@@ -4,8 +4,9 @@ mpl-richtext: Rich text rendering for Matplotlib
4
4
 
5
5
  from .core import richtext
6
6
  from .version import __version__
7
+ from .utils import format_nepali_number
7
8
 
8
- __all__ = ['richtext', '__version__']
9
+ __all__ = ['richtext', '__version__', 'format_nepali_number']
9
10
 
10
11
  __author__ = 'Rabin Katel'
11
12
  __email__ = 'kattelrabinraja13@gmail.com'
mpl_richtext/utils.py ADDED
@@ -0,0 +1,72 @@
1
+ """
2
+ Utility functions for mpl-richtext
3
+ """
4
+
5
+
6
+ def format_nepali_number(number):
7
+ """
8
+ Format a number using the Nepali/Indian numbering system.
9
+
10
+ Uses the 3-2-2... grouping pattern from right to left.
11
+ Handles already-formatted input by stripping existing commas first.
12
+
13
+ Args:
14
+ number: int, float, or string representing a number.
15
+ Can include existing comma formatting.
16
+
17
+ Returns:
18
+ str: The number formatted with Nepali-style comma placement.
19
+
20
+ Examples:
21
+ >>> format_nepali_number(2553871)
22
+ '25,53,871'
23
+ >>> format_nepali_number("2,553,871") # Western format → Nepali
24
+ '25,53,871'
25
+ >>> format_nepali_number(1234567.89)
26
+ '12,34,567.89'
27
+ >>> format_nepali_number(-2553871)
28
+ '-25,53,871'
29
+ """
30
+ # Convert to string and strip existing commas
31
+ num_str = str(number).replace(',', '')
32
+
33
+ # Handle negative numbers
34
+ is_negative = num_str.startswith('-')
35
+ if is_negative:
36
+ num_str = num_str[1:]
37
+
38
+ # Separate integer and decimal parts
39
+ if '.' in num_str:
40
+ integer_part, decimal_part = num_str.split('.', 1)
41
+ else:
42
+ integer_part = num_str
43
+ decimal_part = None
44
+
45
+ # Apply Nepali grouping: first 3 digits from right, then 2 digits each
46
+ if len(integer_part) <= 3:
47
+ formatted = integer_part
48
+ else:
49
+ # Take last 3 digits
50
+ result = [integer_part[-3:]]
51
+ remaining = integer_part[:-3]
52
+
53
+ # Group remaining digits in pairs of 2 from right to left
54
+ while len(remaining) > 2:
55
+ result.insert(0, remaining[-2:])
56
+ remaining = remaining[:-2]
57
+
58
+ # Add any remaining digits (1 or 2)
59
+ if remaining:
60
+ result.insert(0, remaining)
61
+
62
+ formatted = ','.join(result)
63
+
64
+ # Rejoin with decimal part if present
65
+ if decimal_part is not None:
66
+ formatted = f"{formatted}.{decimal_part}"
67
+
68
+ # Add negative sign back
69
+ if is_negative:
70
+ formatted = f"-{formatted}"
71
+
72
+ return formatted
mpl_richtext/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '0.1.7'
1
+ __version__ = '0.1.8'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mpl-richtext
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary: Rich text rendering for Matplotlib with multi-color and multi-style support
5
5
  Home-page: https://github.com/ra8in/mpl-richtext
6
6
  Author: Rabin Katel
@@ -0,0 +1,10 @@
1
+ mpl_richtext/__init__.py,sha256=c-efxeIDOSU6EXIMfbLzBi4h3Rx4h88kx9U1Lx2DD1Q,310
2
+ mpl_richtext/core.py,sha256=S_BrL3SlsDcUpDlmwXmiRKPvguGASjbLYinH63dDJ5g,24772
3
+ mpl_richtext/shaping.py,sha256=wvn0PREs3SXNgnuIVVnxIWWtNyaQt5lhAbFmeem9U7w,10850
4
+ mpl_richtext/utils.py,sha256=25zBLnXKm_7Hg8x8fsDMVpB1DRWsmtfMJe96CY8vrHA,2094
5
+ mpl_richtext/version.py,sha256=zemvJ5zjFE6SQT2xmkxc-ZYwNkUTCEX7mz3Epb2qztE,21
6
+ mpl_richtext-0.1.8.dist-info/licenses/LICENSE,sha256=3ldFhzXg_DuFYRbdYJaN661E5PAzUpVjWxFCxVm7kG8,1067
7
+ mpl_richtext-0.1.8.dist-info/METADATA,sha256=dEZoRwIcuG4MRygIx04uNQsNmJRVgmIKAGJPV9cVIow,5443
8
+ mpl_richtext-0.1.8.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
9
+ mpl_richtext-0.1.8.dist-info/top_level.txt,sha256=3K_jSX3xxD2Dhaqm4jtejlO0HI_5tl7F7AMq4lGk6xw,13
10
+ mpl_richtext-0.1.8.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- mpl_richtext/__init__.py,sha256=430UvdXDNTa9xCoQ48OT_lzHrFCW_xCuVaTr1apEVq4,246
2
- mpl_richtext/core.py,sha256=S_BrL3SlsDcUpDlmwXmiRKPvguGASjbLYinH63dDJ5g,24772
3
- mpl_richtext/shaping.py,sha256=wvn0PREs3SXNgnuIVVnxIWWtNyaQt5lhAbFmeem9U7w,10850
4
- mpl_richtext/version.py,sha256=V7LnX330m3uiAO0EYQbPUYETPj2br2y1Pv-a7ApMj40,21
5
- mpl_richtext-0.1.7.dist-info/licenses/LICENSE,sha256=3ldFhzXg_DuFYRbdYJaN661E5PAzUpVjWxFCxVm7kG8,1067
6
- mpl_richtext-0.1.7.dist-info/METADATA,sha256=7sPFAvhjRLMRFg2wY2bmiWUSV53zQYX6yVwqF-hQ7IQ,5443
7
- mpl_richtext-0.1.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
8
- mpl_richtext-0.1.7.dist-info/top_level.txt,sha256=3K_jSX3xxD2Dhaqm4jtejlO0HI_5tl7F7AMq4lGk6xw,13
9
- mpl_richtext-0.1.7.dist-info/RECORD,,