@pbkware/dot-net-date-number-formatting 0.2.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Paul Klink
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # dot-net-date-number-formatting
2
+
3
+ A TypeScript library that provides .NET-compatible date/time and numeric formatting for JavaScript/TypeScript applications. This library implements format string parsing and formatting similar to Microsoft's .NET Framework, enabling cross-platform compatibility for applications that need to maintain consistent formatting between .NET and JavaScript/TypeScript.
4
+
5
+ ## Overview
6
+
7
+ This library provides three main components:
8
+
9
+ - **DateTime Formatting** - Format dates using .NET standard and custom date/time format strings
10
+ - **Numeric Formatting** - Format numbers using .NET standard and custom numeric format strings
11
+ - **Number Parsing** - Parse numbers with configurable style requirements (hex, currency, thousands separators, etc.)
12
+
13
+ Built on top of JavaScript's `Intl` API for locale-aware formatting while maintaining compatibility with .NET format string syntax.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @pbkware/dot-net-date-number-formatting
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ### DateTime Formatting
24
+
25
+ ```typescript
26
+ import { DotNetDateTimeFormatter, DotNetLocaleSettings } from '@pbkware/dot-net-date-number-formatting';
27
+
28
+ const formatter = new DotNetDateTimeFormatter();
29
+ formatter.localeSettings = DotNetLocaleSettings.createInvariant();
30
+
31
+ // Standard format
32
+ formatter.trySetFormat('d'); // Short date
33
+ console.log(formatter.toString(new Date(2024, 6, 5))); // "7/5/2024"
34
+
35
+ // Custom format
36
+ formatter.trySetFormat('yyyy-MM-dd HH:mm:ss');
37
+ console.log(formatter.toString(new Date(2024, 6, 5, 14, 30, 0))); // "2024-07-05 14:30:00"
38
+ ```
39
+
40
+ ### Numeric Formatting
41
+
42
+ ```typescript
43
+ import { DotNetFloatFormatter, DotNetLocaleSettings } from '@pbkware/dot-net-date-number-formatting';
44
+
45
+ const formatter = new DotNetFloatFormatter();
46
+ formatter.localeSettings = DotNetLocaleSettings.createInvariant();
47
+
48
+ // Currency format
49
+ formatter.trySetFormat('C2');
50
+ console.log(formatter.toString(1234.56)); // "$1,234.56"
51
+
52
+ // Custom format
53
+ formatter.trySetFormat('#,##0.00');
54
+ console.log(formatter.toString(1234.56)); // "1,234.56"
55
+ ```
56
+
57
+ ### Number Parsing
58
+
59
+ ```typescript
60
+ import { DotNetFloatFormatter, DotNetNumberStyles } from '@pbkware/dot-net-date-number-formatting';
61
+
62
+ const formatter = new DotNetFloatFormatter();
63
+ formatter.styles = DotNetNumberStyles.number;
64
+
65
+ const result = formatter.tryFromString('1,234.56');
66
+ if (result.isOk()) {
67
+ console.log(result.value); // 1234.56
68
+ }
69
+ ```
70
+
71
+ ## Documentation
72
+
73
+ Comprehensive documentation is available at library [website](https://pbkware.github.io/dot-net-date-number-formatting/)
74
+
75
+ ## Use Cases
76
+
77
+ - **Cross-platform applications** - Maintain consistent formatting between .NET backends and JavaScript/TypeScript frontends
78
+ - **Data export/import** - Format data for consistent serialization across platforms
79
+ - **Multi-locale applications** - Support users in different regions with locale-aware formatting
80
+ - **Financial applications** - Format currency and numeric values with precise control
81
+ - **Report generation** - Create formatted reports with .NET-compatible output
82
+ - **Round trip formatting/parsing** - Formatting and then parsing a value with the same format string will return the same value.
83
+
84
+ ## Features
85
+
86
+ ### DateTime Formatting
87
+ - ✅ All standard date/time format strings (d, D, f, F, g, G, M, O, s, t, T, u, Y)
88
+ - ✅ Custom format strings with day, month, year, hour, minute, second specifiers
89
+ - ✅ Fractional seconds (f, F)
90
+ - ✅ AM/PM designators
91
+ - ✅ Literal text in format strings
92
+ - ⚠️ Limited time zone support
93
+
94
+ ### Numeric Formatting
95
+ - ✅ All standard numeric format strings (C, D, E, F, G, N, P, R, X, B)
96
+ - ✅ Custom format strings with digit placeholders (0, #)
97
+ - ✅ Section separators for positive/negative/zero values
98
+ - ✅ Thousands separators and number scaling
99
+ - ✅ Percentage and per mille formatting
100
+ - ✅ Scientific notation
101
+ - ✅ Hexadecimal and binary formats
102
+
103
+ ### Number Parsing
104
+ - ✅ Configurable parsing styles (whitespace, signs, parentheses, etc.)
105
+ - ✅ Currency symbol support
106
+ - ✅ Thousands separator support
107
+ - ✅ Exponential notation
108
+ - ✅ Hexadecimal parsing
109
+
110
+ ## Downloads
111
+
112
+ - [npm package](https://www.npmjs.com/package/@pbkware/dot-net-date-number-formatting)
113
+ - [GitHub repository](https://github.com/pbkware/dot-net-date-number-formatting)
114
+
115
+ ## License
116
+
117
+ See [LICENSE](./LICENSE) file for details.
118
+
119
+ ```bash
120
+ # Install dependencies
121
+ npm install
122
+
123
+ # Run tests
124
+ npm test
125
+
126
+ # Build
127
+ npm run build
128
+
129
+ # Generate documentation
130
+ npm run docs:build
131
+ ```
132
+
133
+ ## Support
134
+
135
+ For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/pbkware/dot-net-date-number-formatting).
136
+
137
+ ## History
138
+
139
+ This library was created by porting the relevant portions of the Delphi library [TFieldedText](https://sourceforge.net/projects/tfieldedtext/) (at [SourceForge](https://sourceforge.net/projects/tfieldedtext/)) (Note that the commit attributions are incorrect in TFieldedText - they should be attributed to Paul Klink.) The porting and documentation was carried out with AI (GitHub co-pilot).
140
+
141
+ ## Contributing
142
+
143
+ Contributions are welcome! Please ensure all tests pass before submitting pull requests.