@pbkware/dot-net-date-number-formatting 0.2.0 → 0.3.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.
@@ -1,211 +0,0 @@
1
- import { CommaText, Err, Ok } from "@pbkware/js-utils";
2
- /**
3
- * Individual style flags that control which number formats are allowed during parsing.
4
- *
5
- * These flags can be combined to create custom parsing behavior.
6
- *
7
- * @example
8
- * ```typescript
9
- * // Combine individual flags
10
- * formatter.styles = new Set([
11
- * DotNetNumberStyleId.AllowLeadingSign,
12
- * DotNetNumberStyleId.AllowDecimalPoint,
13
- * DotNetNumberStyleId.AllowThousands
14
- * ]);
15
- * ```
16
- *
17
- * @public
18
- * @category Number Styles
19
- */
20
- export var DotNetNumberStyleId;
21
- (function (DotNetNumberStyleId) {
22
- /** Allow currency symbol in the number string. */
23
- DotNetNumberStyleId["AllowCurrencySymbol"] = "AllowCurrencySymbol";
24
- /** Allow decimal point in the number string. */
25
- DotNetNumberStyleId["AllowDecimalPoint"] = "AllowDecimalPoint";
26
- /** Allow exponential notation (e.g., 1.23e+10). */
27
- DotNetNumberStyleId["AllowExponent"] = "AllowExponent";
28
- /** Parse the number as hexadecimal. */
29
- DotNetNumberStyleId["AllowHexSpecifier"] = "AllowHexSpecifier";
30
- /** Allow a leading plus (+) or minus (-) sign. */
31
- DotNetNumberStyleId["AllowLeadingSign"] = "AllowLeadingSign";
32
- /** Allow leading whitespace characters. */
33
- DotNetNumberStyleId["AllowLeadingWhite"] = "AllowLeadingWhite";
34
- /** Allow parentheses to indicate negative numbers. */
35
- DotNetNumberStyleId["AllowParentheses"] = "AllowParentheses";
36
- /** Allow thousands separator characters. */
37
- DotNetNumberStyleId["AllowThousands"] = "AllowThousands";
38
- /** Allow a trailing plus (+) or minus (-) sign. */
39
- DotNetNumberStyleId["AllowTrailingSign"] = "AllowTrailingSign";
40
- /** Allow trailing whitespace characters. */
41
- DotNetNumberStyleId["AllowTrailingWhite"] = "AllowTrailingWhite";
42
- })(DotNetNumberStyleId || (DotNetNumberStyleId = {}));
43
- /**
44
- * Predefined number style combinations for common parsing scenarios.
45
- *
46
- * @example
47
- * ```typescript
48
- * // Use predefined style
49
- * formatter.styles = DotNetNumberStyles.number;
50
- * formatter.tryFromString('1,234.56'); // Parses successfully
51
- *
52
- * // Use currency style
53
- * formatter.styles = DotNetNumberStyles.currency;
54
- * formatter.tryFromString('$1,234.56'); // Parses successfully
55
- * ```
56
- *
57
- * @internal
58
- * @category Number Styles
59
- */
60
- export const DotNetNumberStyles = {
61
- /** No styles - only basic digits allowed. */
62
- none: new Set(),
63
- /**
64
- * All styles allowed (except hex).
65
- * Includes: AllowCurrencySymbol, AllowDecimalPoint, AllowExponent, AllowLeadingSign,
66
- * AllowLeadingWhite, AllowParentheses, AllowThousands, AllowTrailingSign, AllowTrailingWhite.
67
- */
68
- any: new Set([
69
- DotNetNumberStyleId.AllowCurrencySymbol,
70
- DotNetNumberStyleId.AllowDecimalPoint,
71
- DotNetNumberStyleId.AllowExponent,
72
- DotNetNumberStyleId.AllowLeadingSign,
73
- DotNetNumberStyleId.AllowLeadingWhite,
74
- DotNetNumberStyleId.AllowParentheses,
75
- DotNetNumberStyleId.AllowThousands,
76
- DotNetNumberStyleId.AllowTrailingSign,
77
- DotNetNumberStyleId.AllowTrailingWhite,
78
- ]),
79
- /**
80
- * Currency parsing style.
81
- * Includes: AllowCurrencySymbol, AllowDecimalPoint, AllowLeadingSign, AllowLeadingWhite,
82
- * AllowParentheses, AllowThousands, AllowTrailingSign, AllowTrailingWhite.
83
- */
84
- currency: new Set([
85
- DotNetNumberStyleId.AllowCurrencySymbol,
86
- DotNetNumberStyleId.AllowDecimalPoint,
87
- DotNetNumberStyleId.AllowLeadingSign,
88
- DotNetNumberStyleId.AllowLeadingWhite,
89
- DotNetNumberStyleId.AllowParentheses,
90
- DotNetNumberStyleId.AllowThousands,
91
- DotNetNumberStyleId.AllowTrailingSign,
92
- DotNetNumberStyleId.AllowTrailingWhite,
93
- ]),
94
- /**
95
- * Floating-point parsing style.
96
- * Includes: AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign,
97
- * AllowDecimalPoint, AllowExponent.
98
- */
99
- float: new Set([
100
- DotNetNumberStyleId.AllowLeadingWhite,
101
- DotNetNumberStyleId.AllowTrailingWhite,
102
- DotNetNumberStyleId.AllowLeadingSign,
103
- DotNetNumberStyleId.AllowDecimalPoint,
104
- DotNetNumberStyleId.AllowExponent,
105
- ]),
106
- /**
107
- * Hexadecimal parsing style.
108
- * Includes: AllowLeadingWhite, AllowTrailingWhite, AllowHexSpecifier.
109
- */
110
- hexNumber: new Set([
111
- DotNetNumberStyleId.AllowLeadingWhite,
112
- DotNetNumberStyleId.AllowTrailingWhite,
113
- DotNetNumberStyleId.AllowHexSpecifier,
114
- ]),
115
- /**
116
- * Basic integer parsing style.
117
- * Includes: AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign.
118
- */
119
- integer: new Set([
120
- DotNetNumberStyleId.AllowLeadingWhite,
121
- DotNetNumberStyleId.AllowTrailingWhite,
122
- DotNetNumberStyleId.AllowLeadingSign,
123
- ]),
124
- /**
125
- * Standard number parsing style.
126
- * Includes: AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign, AllowTrailingSign,
127
- * AllowDecimalPoint, AllowThousands.
128
- */
129
- number: new Set([
130
- DotNetNumberStyleId.AllowLeadingWhite,
131
- DotNetNumberStyleId.AllowTrailingWhite,
132
- DotNetNumberStyleId.AllowLeadingSign,
133
- DotNetNumberStyleId.AllowTrailingSign,
134
- DotNetNumberStyleId.AllowDecimalPoint,
135
- DotNetNumberStyleId.AllowThousands,
136
- ]),
137
- };
138
- const isSameSet = (left, right) => {
139
- if (left.size !== right.size) {
140
- return false;
141
- }
142
- for (const value of left) {
143
- if (!right.has(value)) {
144
- return false;
145
- }
146
- }
147
- return true;
148
- };
149
- /** @internal */
150
- export class DotNetNumberStylesInfo {
151
- static toString(styles) {
152
- return this.toXmlValue(styles);
153
- }
154
- static toXmlValue(styles) {
155
- if (isSameSet(styles, DotNetNumberStyles.any))
156
- return "Any";
157
- if (isSameSet(styles, DotNetNumberStyles.currency))
158
- return "Currency";
159
- if (isSameSet(styles, DotNetNumberStyles.float))
160
- return "Float";
161
- if (isSameSet(styles, DotNetNumberStyles.hexNumber))
162
- return "HexNumber";
163
- if (isSameSet(styles, DotNetNumberStyles.integer))
164
- return "Integer";
165
- if (isSameSet(styles, DotNetNumberStyles.number))
166
- return "Number";
167
- return CommaText.fromStringArray(Array.from(styles.values()));
168
- }
169
- static tryFromString(value) {
170
- return this.tryFromXmlValue(value);
171
- }
172
- static tryFromXmlValue(value) {
173
- const normalized = value.trim();
174
- if (normalized.length === 0 || normalized.toLowerCase() === "none") {
175
- return new Ok(new Set(DotNetNumberStyles.none));
176
- }
177
- const canonical = normalized.toLowerCase();
178
- if (canonical === "any")
179
- return new Ok(new Set(DotNetNumberStyles.any));
180
- if (canonical === "currency")
181
- return new Ok(new Set(DotNetNumberStyles.currency));
182
- if (canonical === "float")
183
- return new Ok(new Set(DotNetNumberStyles.float));
184
- if (canonical === "hexnumber")
185
- return new Ok(new Set(DotNetNumberStyles.hexNumber));
186
- if (canonical === "integer")
187
- return new Ok(new Set(DotNetNumberStyles.integer));
188
- if (canonical === "number")
189
- return new Ok(new Set(DotNetNumberStyles.number));
190
- const commaTextResult = CommaText.tryToStringArray(normalized);
191
- if (commaTextResult.isErr()) {
192
- return commaTextResult.createOuter("Invalid comma-separated styles string");
193
- }
194
- const result = new Set();
195
- for (const part of commaTextResult.value) {
196
- const match = Object.values(DotNetNumberStyleId).find((x) => x.toLowerCase() === part.toLowerCase());
197
- if (match === undefined) {
198
- return new Err(`Invalid style: ${part}`);
199
- }
200
- result.add(match);
201
- }
202
- return new Ok(result);
203
- }
204
- static tryFromXmlValueWithDefault(value, defaultStyles) {
205
- if (value.trim().length === 0) {
206
- return new Ok(new Set(defaultStyles));
207
- }
208
- return this.tryFromXmlValue(value);
209
- }
210
- }
211
- //# sourceMappingURL=number-style.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"number-style.js","sourceRoot":"","sources":["../../src/code/number-style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,EAAU,MAAM,mBAAmB,CAAC;AAE/D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAN,IAAY,mBA8BX;AA9BD,WAAY,mBAAmB;IAC7B,kDAAkD;IAClD,kEAA2C,CAAA;IAE3C,gDAAgD;IAChD,8DAAuC,CAAA;IAEvC,mDAAmD;IACnD,sDAA+B,CAAA;IAE/B,uCAAuC;IACvC,8DAAuC,CAAA;IAEvC,kDAAkD;IAClD,4DAAqC,CAAA;IAErC,2CAA2C;IAC3C,8DAAuC,CAAA;IAEvC,sDAAsD;IACtD,4DAAqC,CAAA;IAErC,4CAA4C;IAC5C,wDAAiC,CAAA;IAEjC,mDAAmD;IACnD,8DAAuC,CAAA;IAEvC,4CAA4C;IAC5C,gEAAyC,CAAA;AAC3C,CAAC,EA9BW,mBAAmB,KAAnB,mBAAmB,QA8B9B;AAUD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,6CAA6C;IAC7C,IAAI,EAAE,IAAI,GAAG,EAAuB;IAEpC;;;;OAIG;IACH,GAAG,EAAE,IAAI,GAAG,CAAsB;QAChC,mBAAmB,CAAC,mBAAmB;QACvC,mBAAmB,CAAC,iBAAiB;QACrC,mBAAmB,CAAC,aAAa;QACjC,mBAAmB,CAAC,gBAAgB;QACpC,mBAAmB,CAAC,iBAAiB;QACrC,mBAAmB,CAAC,gBAAgB;QACpC,mBAAmB,CAAC,cAAc;QAClC,mBAAmB,CAAC,iBAAiB;QACrC,mBAAmB,CAAC,kBAAkB;KACvC,CAAC;IAEF;;;;OAIG;IACH,QAAQ,EAAE,IAAI,GAAG,CAAsB;QACrC,mBAAmB,CAAC,mBAAmB;QACvC,mBAAmB,CA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WAAW,EAAE,KAAK,IAAI,CAAC,WAAW,EAAE,CAC9C,CAAC;YACF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,IAAI,GAAG,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC;YAC3C,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;QAED,OAAO,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,0BAA0B,CAC/B,KAAa,EACb,aAAmC;QAEnC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,EAAE,CAAC,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;CACF"}
@@ -1,128 +0,0 @@
1
- import { CommaText, Err, Ok, Result } from "@pbkware/js-utils";
2
-
3
- /**
4
- * Individual style flags that control date/time parsing behavior.
5
- *
6
- * These flags can be combined to create custom parsing rules.
7
- *
8
- * @example
9
- * ```typescript
10
- * // Combine individual flags
11
- * formatter.styles = new Set([
12
- * DotNetDateTimeStyleId.AllowLeadingWhite,
13
- * DotNetDateTimeStyleId.AllowTrailingWhite
14
- * ]);
15
- * ```
16
- *
17
- * @public
18
- * @category DateTime Styles
19
- */
20
- export enum DotNetDateTimeStyleId {
21
- /** Allow leading whitespace characters. */
22
- AllowLeadingWhite = "AllowLeadingWhite",
23
-
24
- /** Allow trailing whitespace characters. */
25
- AllowTrailingWhite = "AllowTrailingWhite",
26
-
27
- /** Allow whitespace within the date/time string. */
28
- AllowInnerWhite = "AllowInnerWhite",
29
-
30
- /** Do not use current date for missing date components. */
31
- NoCurrentDateDefault = "NoCurrentDateDefault",
32
-
33
- /** Adjust date/time to UTC (not implemented). */
34
- AdjustToUniversal = "AdjustToUniversal",
35
-
36
- /** Assume local time zone if not specified (not implemented). */
37
- AssumeLocal = "AssumeLocal",
38
-
39
- /** Assume UTC time zone if not specified (not implemented). */
40
- AssumeUniversal = "AssumeUniversal",
41
-
42
- /** Preserve DateTimeKind when parsing (not implemented). */
43
- RoundTripKind = "RoundTripKind",
44
- }
45
-
46
- /**
47
- * A set of {@link DotNetDateTimeStyleId} flags.
48
- *
49
- * @public
50
- * @category DateTime Styles
51
- */
52
- export type DotNetDateTimeStyleSet = Set<DotNetDateTimeStyleId>;
53
-
54
- /**
55
- * Predefined date/time style combinations for common parsing scenarios.
56
- *
57
- * @internal
58
- * @category DateTime Styles
59
- */
60
- export const DotNetDateTimeStyles = {
61
- /** No styles - strict parsing. */
62
- none: new Set<DotNetDateTimeStyleId>(),
63
-
64
- /**
65
- * Allow whitespace in date/time strings.
66
- * Includes: AllowLeadingWhite, AllowTrailingWhite, AllowInnerWhite.
67
- */
68
- allowWhiteSpaces: new Set<DotNetDateTimeStyleId>([
69
- DotNetDateTimeStyleId.AllowLeadingWhite,
70
- DotNetDateTimeStyleId.AllowTrailingWhite,
71
- DotNetDateTimeStyleId.AllowInnerWhite,
72
- ]),
73
- };
74
-
75
- const isSameSet = (
76
- left: DotNetDateTimeStyleSet,
77
- right: DotNetDateTimeStyleSet,
78
- ): boolean => {
79
- if (left.size !== right.size) return false;
80
- for (const value of left) {
81
- if (!right.has(value)) return false;
82
- }
83
- return true;
84
- };
85
-
86
- /** @internal */
87
- export class DotNetDateTimeStylesInfo {
88
- static toString(styles: DotNetDateTimeStyleSet): string {
89
- return this.toXmlValue(styles);
90
- }
91
-
92
- static toXmlValue(styles: DotNetDateTimeStyleSet): string {
93
- if (isSameSet(styles, DotNetDateTimeStyles.allowWhiteSpaces)) {
94
- return "AllowWhiteSpaces";
95
- }
96
- return CommaText.fromStringArray(Array.from(styles.values()));
97
- }
98
-
99
- static tryFromString(value: string): Result<DotNetDateTimeStyleSet> {
100
- return this.tryFromXmlValue(value);
101
- }
102
-
103
- static tryFromXmlValue(value: string): Result<DotNetDateTimeStyleSet> {
104
- const normalized = value.trim();
105
- if (normalized.length === 0 || normalized.toLowerCase() === "none") {
106
- return new Ok(new Set(DotNetDateTimeStyles.none));
107
- }
108
- if (normalized.toLowerCase() === "allowwhitespaces") {
109
- return new Ok(new Set(DotNetDateTimeStyles.allowWhiteSpaces));
110
- }
111
-
112
- const commaTextResult = CommaText.tryToStringArray(normalized);
113
- if (commaTextResult.isErr())
114
- return commaTextResult.createOuter(
115
- "Invalid comma-separated styles string",
116
- );
117
-
118
- const styles = new Set<DotNetDateTimeStyleId>();
119
- for (const item of commaTextResult.value) {
120
- const match = Object.values(DotNetDateTimeStyleId).find(
121
- (x) => x.toLowerCase() === item.toLowerCase(),
122
- );
123
- if (match === undefined) return new Err(`Invalid style: ${item}`);
124
- styles.add(match);
125
- }
126
- return new Ok(styles);
127
- }
128
- }
@@ -1,247 +0,0 @@
1
- import { CommaText, Err, Ok, Result } from "@pbkware/js-utils";
2
-
3
- /**
4
- * Individual style flags that control which number formats are allowed during parsing.
5
- *
6
- * These flags can be combined to create custom parsing behavior.
7
- *
8
- * @example
9
- * ```typescript
10
- * // Combine individual flags
11
- * formatter.styles = new Set([
12
- * DotNetNumberStyleId.AllowLeadingSign,
13
- * DotNetNumberStyleId.AllowDecimalPoint,
14
- * DotNetNumberStyleId.AllowThousands
15
- * ]);
16
- * ```
17
- *
18
- * @public
19
- * @category Number Styles
20
- */
21
- export enum DotNetNumberStyleId {
22
- /** Allow currency symbol in the number string. */
23
- AllowCurrencySymbol = "AllowCurrencySymbol",
24
-
25
- /** Allow decimal point in the number string. */
26
- AllowDecimalPoint = "AllowDecimalPoint",
27
-
28
- /** Allow exponential notation (e.g., 1.23e+10). */
29
- AllowExponent = "AllowExponent",
30
-
31
- /** Parse the number as hexadecimal. */
32
- AllowHexSpecifier = "AllowHexSpecifier",
33
-
34
- /** Allow a leading plus (+) or minus (-) sign. */
35
- AllowLeadingSign = "AllowLeadingSign",
36
-
37
- /** Allow leading whitespace characters. */
38
- AllowLeadingWhite = "AllowLeadingWhite",
39
-
40
- /** Allow parentheses to indicate negative numbers. */
41
- AllowParentheses = "AllowParentheses",
42
-
43
- /** Allow thousands separator characters. */
44
- AllowThousands = "AllowThousands",
45
-
46
- /** Allow a trailing plus (+) or minus (-) sign. */
47
- AllowTrailingSign = "AllowTrailingSign",
48
-
49
- /** Allow trailing whitespace characters. */
50
- AllowTrailingWhite = "AllowTrailingWhite",
51
- }
52
-
53
- /**
54
- * A set of {@link DotNetNumberStyleId} flags.
55
- *
56
- * @public
57
- * @category Number Styles
58
- */
59
- export type DotNetNumberStyleSet = Set<DotNetNumberStyleId>;
60
-
61
- /**
62
- * Predefined number style combinations for common parsing scenarios.
63
- *
64
- * @example
65
- * ```typescript
66
- * // Use predefined style
67
- * formatter.styles = DotNetNumberStyles.number;
68
- * formatter.tryFromString('1,234.56'); // Parses successfully
69
- *
70
- * // Use currency style
71
- * formatter.styles = DotNetNumberStyles.currency;
72
- * formatter.tryFromString('$1,234.56'); // Parses successfully
73
- * ```
74
- *
75
- * @internal
76
- * @category Number Styles
77
- */
78
- export const DotNetNumberStyles = {
79
- /** No styles - only basic digits allowed. */
80
- none: new Set<DotNetNumberStyleId>(),
81
-
82
- /**
83
- * All styles allowed (except hex).
84
- * Includes: AllowCurrencySymbol, AllowDecimalPoint, AllowExponent, AllowLeadingSign,
85
- * AllowLeadingWhite, AllowParentheses, AllowThousands, AllowTrailingSign, AllowTrailingWhite.
86
- */
87
- any: new Set<DotNetNumberStyleId>([
88
- DotNetNumberStyleId.AllowCurrencySymbol,
89
- DotNetNumberStyleId.AllowDecimalPoint,
90
- DotNetNumberStyleId.AllowExponent,
91
- DotNetNumberStyleId.AllowLeadingSign,
92
- DotNetNumberStyleId.AllowLeadingWhite,
93
- DotNetNumberStyleId.AllowParentheses,
94
- DotNetNumberStyleId.AllowThousands,
95
- DotNetNumberStyleId.AllowTrailingSign,
96
- DotNetNumberStyleId.AllowTrailingWhite,
97
- ]),
98
-
99
- /**
100
- * Currency parsing style.
101
- * Includes: AllowCurrencySymbol, AllowDecimalPoint, AllowLeadingSign, AllowLeadingWhite,
102
- * AllowParentheses, AllowThousands, AllowTrailingSign, AllowTrailingWhite.
103
- */
104
- currency: new Set<DotNetNumberStyleId>([
105
- DotNetNumberStyleId.AllowCurrencySymbol,
106
- DotNetNumberStyleId.AllowDecimalPoint,
107
- DotNetNumberStyleId.AllowLeadingSign,
108
- DotNetNumberStyleId.AllowLeadingWhite,
109
- DotNetNumberStyleId.AllowParentheses,
110
- DotNetNumberStyleId.AllowThousands,
111
- DotNetNumberStyleId.AllowTrailingSign,
112
- DotNetNumberStyleId.AllowTrailingWhite,
113
- ]),
114
-
115
- /**
116
- * Floating-point parsing style.
117
- * Includes: AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign,
118
- * AllowDecimalPoint, AllowExponent.
119
- */
120
- float: new Set<DotNetNumberStyleId>([
121
- DotNetNumberStyleId.AllowLeadingWhite,
122
- DotNetNumberStyleId.AllowTrailingWhite,
123
- DotNetNumberStyleId.AllowLeadingSign,
124
- DotNetNumberStyleId.AllowDecimalPoint,
125
- DotNetNumberStyleId.AllowExponent,
126
- ]),
127
-
128
- /**
129
- * Hexadecimal parsing style.
130
- * Includes: AllowLeadingWhite, AllowTrailingWhite, AllowHexSpecifier.
131
- */
132
- hexNumber: new Set<DotNetNumberStyleId>([
133
- DotNetNumberStyleId.AllowLeadingWhite,
134
- DotNetNumberStyleId.AllowTrailingWhite,
135
- DotNetNumberStyleId.AllowHexSpecifier,
136
- ]),
137
-
138
- /**
139
- * Basic integer parsing style.
140
- * Includes: AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign.
141
- */
142
- integer: new Set<DotNetNumberStyleId>([
143
- DotNetNumberStyleId.AllowLeadingWhite,
144
- DotNetNumberStyleId.AllowTrailingWhite,
145
- DotNetNumberStyleId.AllowLeadingSign,
146
- ]),
147
-
148
- /**
149
- * Standard number parsing style.
150
- * Includes: AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign, AllowTrailingSign,
151
- * AllowDecimalPoint, AllowThousands.
152
- */
153
- number: new Set<DotNetNumberStyleId>([
154
- DotNetNumberStyleId.AllowLeadingWhite,
155
- DotNetNumberStyleId.AllowTrailingWhite,
156
- DotNetNumberStyleId.AllowLeadingSign,
157
- DotNetNumberStyleId.AllowTrailingSign,
158
- DotNetNumberStyleId.AllowDecimalPoint,
159
- DotNetNumberStyleId.AllowThousands,
160
- ]),
161
- };
162
-
163
- const isSameSet = (
164
- left: DotNetNumberStyleSet,
165
- right: DotNetNumberStyleSet,
166
- ): boolean => {
167
- if (left.size !== right.size) {
168
- return false;
169
- }
170
- for (const value of left) {
171
- if (!right.has(value)) {
172
- return false;
173
- }
174
- }
175
- return true;
176
- };
177
-
178
- /** @internal */
179
- export class DotNetNumberStylesInfo {
180
- static toString(styles: DotNetNumberStyleSet): string {
181
- return this.toXmlValue(styles);
182
- }
183
-
184
- static toXmlValue(styles: DotNetNumberStyleSet): string {
185
- if (isSameSet(styles, DotNetNumberStyles.any)) return "Any";
186
- if (isSameSet(styles, DotNetNumberStyles.currency)) return "Currency";
187
- if (isSameSet(styles, DotNetNumberStyles.float)) return "Float";
188
- if (isSameSet(styles, DotNetNumberStyles.hexNumber)) return "HexNumber";
189
- if (isSameSet(styles, DotNetNumberStyles.integer)) return "Integer";
190
- if (isSameSet(styles, DotNetNumberStyles.number)) return "Number";
191
-
192
- return CommaText.fromStringArray(Array.from(styles.values()));
193
- }
194
-
195
- static tryFromString(value: string): Result<DotNetNumberStyleSet> {
196
- return this.tryFromXmlValue(value);
197
- }
198
-
199
- static tryFromXmlValue(value: string): Result<DotNetNumberStyleSet> {
200
- const normalized = value.trim();
201
- if (normalized.length === 0 || normalized.toLowerCase() === "none") {
202
- return new Ok(new Set(DotNetNumberStyles.none));
203
- }
204
-
205
- const canonical = normalized.toLowerCase();
206
- if (canonical === "any") return new Ok(new Set(DotNetNumberStyles.any));
207
- if (canonical === "currency")
208
- return new Ok(new Set(DotNetNumberStyles.currency));
209
- if (canonical === "float") return new Ok(new Set(DotNetNumberStyles.float));
210
- if (canonical === "hexnumber")
211
- return new Ok(new Set(DotNetNumberStyles.hexNumber));
212
- if (canonical === "integer")
213
- return new Ok(new Set(DotNetNumberStyles.integer));
214
- if (canonical === "number")
215
- return new Ok(new Set(DotNetNumberStyles.number));
216
-
217
- const commaTextResult = CommaText.tryToStringArray(normalized);
218
- if (commaTextResult.isErr()) {
219
- return commaTextResult.createOuter(
220
- "Invalid comma-separated styles string",
221
- );
222
- }
223
-
224
- const result = new Set<DotNetNumberStyleId>();
225
- for (const part of commaTextResult.value) {
226
- const match = Object.values(DotNetNumberStyleId).find(
227
- (x) => x.toLowerCase() === part.toLowerCase(),
228
- );
229
- if (match === undefined) {
230
- return new Err(`Invalid style: ${part}`);
231
- }
232
- result.add(match);
233
- }
234
-
235
- return new Ok(result);
236
- }
237
-
238
- static tryFromXmlValueWithDefault(
239
- value: string,
240
- defaultStyles: DotNetNumberStyleSet,
241
- ): Result<DotNetNumberStyleSet> {
242
- if (value.trim().length === 0) {
243
- return new Ok(new Set(defaultStyles));
244
- }
245
- return this.tryFromXmlValue(value);
246
- }
247
- }