@parischap/conversions 0.1.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 +21 -0
- package/README.md +1304 -0
- package/cjs/BigDecimal.js +16 -0
- package/cjs/BigDecimal.js.map +1 -0
- package/cjs/BigInt.js +34 -0
- package/cjs/BigInt.js.map +1 -0
- package/cjs/DateTime.js +2202 -0
- package/cjs/DateTime.js.map +1 -0
- package/cjs/DateTimeFormat.js +269 -0
- package/cjs/DateTimeFormat.js.map +1 -0
- package/cjs/DateTimeFormatContext.js +327 -0
- package/cjs/DateTimeFormatContext.js.map +1 -0
- package/cjs/Email.js +73 -0
- package/cjs/Email.js.map +1 -0
- package/cjs/Integer.js +155 -0
- package/cjs/Integer.js.map +1 -0
- package/cjs/NumberBase10Format.js +759 -0
- package/cjs/NumberBase10Format.js.map +1 -0
- package/cjs/PositiveInteger.js +191 -0
- package/cjs/PositiveInteger.js.map +1 -0
- package/cjs/PositiveReal.js +162 -0
- package/cjs/PositiveReal.js.map +1 -0
- package/cjs/Real.js +113 -0
- package/cjs/Real.js.map +1 -0
- package/cjs/RoundingMode.js +86 -0
- package/cjs/RoundingMode.js.map +1 -0
- package/cjs/RoundingOption.js +152 -0
- package/cjs/RoundingOption.js.map +1 -0
- package/cjs/Schema.js +218 -0
- package/cjs/Schema.js.map +1 -0
- package/cjs/SemVer.js +73 -0
- package/cjs/SemVer.js.map +1 -0
- package/cjs/Template.js +189 -0
- package/cjs/Template.js.map +1 -0
- package/cjs/TemplatePart.js +51 -0
- package/cjs/TemplatePart.js.map +1 -0
- package/cjs/TemplateParts.js +46 -0
- package/cjs/TemplateParts.js.map +1 -0
- package/cjs/TemplatePlaceholder.js +381 -0
- package/cjs/TemplatePlaceholder.js.map +1 -0
- package/cjs/TemplateSeparator.js +116 -0
- package/cjs/TemplateSeparator.js.map +1 -0
- package/cjs/index.js +67 -0
- package/cjs/index.js.map +1 -0
- package/cjs/internal/Int.js +50 -0
- package/cjs/internal/Int.js.map +1 -0
- package/cjs/internal/Positive.js +50 -0
- package/cjs/internal/Positive.js.map +1 -0
- package/dts/BigDecimal.d.ts +11 -0
- package/dts/BigDecimal.d.ts.map +1 -0
- package/dts/BigInt.d.ts +30 -0
- package/dts/BigInt.d.ts.map +1 -0
- package/dts/DateTime.d.ts +1421 -0
- package/dts/DateTime.d.ts.map +1 -0
- package/dts/DateTimeFormat.d.ts +257 -0
- package/dts/DateTimeFormat.d.ts.map +1 -0
- package/dts/DateTimeFormatContext.d.ts +112 -0
- package/dts/DateTimeFormatContext.d.ts.map +1 -0
- package/dts/Email.d.ts +61 -0
- package/dts/Email.d.ts.map +1 -0
- package/dts/Integer.d.ts +123 -0
- package/dts/Integer.d.ts.map +1 -0
- package/dts/NumberBase10Format.d.ts +641 -0
- package/dts/NumberBase10Format.d.ts.map +1 -0
- package/dts/PositiveInteger.d.ts +161 -0
- package/dts/PositiveInteger.d.ts.map +1 -0
- package/dts/PositiveReal.d.ts +130 -0
- package/dts/PositiveReal.d.ts.map +1 -0
- package/dts/Real.d.ts +102 -0
- package/dts/Real.d.ts.map +1 -0
- package/dts/RoundingMode.d.ts +72 -0
- package/dts/RoundingMode.d.ts.map +1 -0
- package/dts/RoundingOption.d.ts +79 -0
- package/dts/RoundingOption.d.ts.map +1 -0
- package/dts/Schema.d.ts +159 -0
- package/dts/Schema.d.ts.map +1 -0
- package/dts/SemVer.d.ts +61 -0
- package/dts/SemVer.d.ts.map +1 -0
- package/dts/Template.d.ts +113 -0
- package/dts/Template.d.ts.map +1 -0
- package/dts/TemplatePart.d.ts +28 -0
- package/dts/TemplatePart.d.ts.map +1 -0
- package/dts/TemplateParts.d.ts +23 -0
- package/dts/TemplateParts.d.ts.map +1 -0
- package/dts/TemplatePlaceholder.d.ts +274 -0
- package/dts/TemplatePlaceholder.d.ts.map +1 -0
- package/dts/TemplateSeparator.d.ts +130 -0
- package/dts/TemplateSeparator.d.ts.map +1 -0
- package/dts/index.d.ts +21 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/internal/Int.d.ts +6 -0
- package/dts/internal/Int.d.ts.map +1 -0
- package/dts/internal/Positive.d.ts +6 -0
- package/dts/internal/Positive.d.ts.map +1 -0
- package/esm/BigDecimal.js +9 -0
- package/esm/BigDecimal.js.map +1 -0
- package/esm/BigInt.js +27 -0
- package/esm/BigInt.js.map +1 -0
- package/esm/DateTime.js +2130 -0
- package/esm/DateTime.js.map +1 -0
- package/esm/DateTimeFormat.js +238 -0
- package/esm/DateTimeFormat.js.map +1 -0
- package/esm/DateTimeFormatContext.js +296 -0
- package/esm/DateTimeFormatContext.js.map +1 -0
- package/esm/Email.js +65 -0
- package/esm/Email.js.map +1 -0
- package/esm/Integer.js +128 -0
- package/esm/Integer.js.map +1 -0
- package/esm/NumberBase10Format.js +717 -0
- package/esm/NumberBase10Format.js.map +1 -0
- package/esm/PositiveInteger.js +164 -0
- package/esm/PositiveInteger.js.map +1 -0
- package/esm/PositiveReal.js +135 -0
- package/esm/PositiveReal.js.map +1 -0
- package/esm/Real.js +106 -0
- package/esm/Real.js.map +1 -0
- package/esm/RoundingMode.js +79 -0
- package/esm/RoundingMode.js.map +1 -0
- package/esm/RoundingOption.js +120 -0
- package/esm/RoundingOption.js.map +1 -0
- package/esm/Schema.js +203 -0
- package/esm/Schema.js.map +1 -0
- package/esm/SemVer.js +65 -0
- package/esm/SemVer.js.map +1 -0
- package/esm/Template.js +158 -0
- package/esm/Template.js.map +1 -0
- package/esm/TemplatePart.js +22 -0
- package/esm/TemplatePart.js.map +1 -0
- package/esm/TemplateParts.js +19 -0
- package/esm/TemplateParts.js.map +1 -0
- package/esm/TemplatePlaceholder.js +342 -0
- package/esm/TemplatePlaceholder.js.map +1 -0
- package/esm/TemplateSeparator.js +107 -0
- package/esm/TemplateSeparator.js.map +1 -0
- package/esm/index.js +21 -0
- package/esm/index.js.map +1 -0
- package/esm/internal/Int.js +43 -0
- package/esm/internal/Int.js.map +1 -0
- package/esm/internal/Positive.js +43 -0
- package/esm/internal/Positive.js.map +1 -0
- package/esm/package.json +3 -0
- package/package.json +49 -0
@@ -0,0 +1,717 @@
|
|
1
|
+
/**
|
2
|
+
* This module implements conversions from number to string and string to number in base-10
|
3
|
+
* notation.
|
4
|
+
*/
|
5
|
+
import { MBigDecimal, MBigInt, MFunction, MInspectable, MMatch, MNumber, MPipeable, MPredicate, MRegExpString, MString, MStruct, MTypes } from '@parischap/effect-lib';
|
6
|
+
import { Array, BigDecimal, BigInt, Either, flow, Function, Number, Option, pipe, Predicate, String, Struct, Tuple } from 'effect';
|
7
|
+
import * as CVReal from './Real.js';
|
8
|
+
import * as CVRoundingMode from './RoundingMode.js';
|
9
|
+
import * as CVRoundingOption from './RoundingOption.js';
|
10
|
+
/**
|
11
|
+
* Module tag
|
12
|
+
*
|
13
|
+
* @category Module markers
|
14
|
+
*/
|
15
|
+
export const moduleTag = '@parischap/conversions/NumberBase10Format/';
|
16
|
+
const _TypeId = /*#__PURE__*/Symbol.for(moduleTag);
|
17
|
+
/**
|
18
|
+
* Possible sign display options
|
19
|
+
*
|
20
|
+
* @category Models
|
21
|
+
*/
|
22
|
+
export var SignDisplay;
|
23
|
+
(function (SignDisplay) {
|
24
|
+
/**
|
25
|
+
* Formatting: sign display for negative numbers only, including negative zero.
|
26
|
+
*
|
27
|
+
* Parsing: conversion will fail if a positive sign is used.
|
28
|
+
*/
|
29
|
+
SignDisplay[SignDisplay["Auto"] = 0] = "Auto";
|
30
|
+
/**
|
31
|
+
* Formatting: sign display for all numbers.
|
32
|
+
*
|
33
|
+
* Parsing: conversion will fail if no sign is present
|
34
|
+
*/
|
35
|
+
SignDisplay[SignDisplay["Always"] = 1] = "Always";
|
36
|
+
/**
|
37
|
+
* Formatting: sign display for positive and negative numbers, but not zero
|
38
|
+
*
|
39
|
+
* Parsing: conversion will fail if a sign is not present for a value other than 0 or if a sign is
|
40
|
+
* present for 0.
|
41
|
+
*/
|
42
|
+
SignDisplay[SignDisplay["ExceptZero"] = 2] = "ExceptZero";
|
43
|
+
/**
|
44
|
+
* Formatting: sign display for negative numbers only, excluding negative zero.
|
45
|
+
*
|
46
|
+
* Parsing: conversion will fail if a positive sign is used or if a negative sign is used for 0.
|
47
|
+
*/
|
48
|
+
SignDisplay[SignDisplay["Negative"] = 3] = "Negative";
|
49
|
+
/**
|
50
|
+
* Formatting: no sign display.
|
51
|
+
*
|
52
|
+
* Parsing: conversion will fail if any sign is present. The number will be treated as positive.
|
53
|
+
*/
|
54
|
+
SignDisplay[SignDisplay["Never"] = 4] = "Never";
|
55
|
+
})(SignDisplay || (SignDisplay = {}));
|
56
|
+
/**
|
57
|
+
* SignDisplay namespace
|
58
|
+
*
|
59
|
+
* @category Models
|
60
|
+
*/
|
61
|
+
(function (SignDisplay) {
|
62
|
+
const isPlusSign = /*#__PURE__*/MPredicate.strictEquals('+');
|
63
|
+
const isMinusSign = /*#__PURE__*/MPredicate.strictEquals('-');
|
64
|
+
const signStringToSignValue = /*#__PURE__*/flow(/*#__PURE__*/Option.liftPredicate(isMinusSign), /*#__PURE__*/Option.as(-1), /*#__PURE__*/Option.getOrElse(/*#__PURE__*/Function.constant(1)));
|
65
|
+
const hasASign = /*#__PURE__*/flow(/*#__PURE__*/Struct.get('sign'), /*#__PURE__*/Option.liftPredicate(String.isNonEmpty), /*#__PURE__*/Option.map(signStringToSignValue));
|
66
|
+
const hasNoSign = /*#__PURE__*/flow(/*#__PURE__*/Struct.get('sign'), /*#__PURE__*/Option.liftPredicate(String.isEmpty), /*#__PURE__*/Option.map(signStringToSignValue));
|
67
|
+
const hasNotPlusSign = /*#__PURE__*/flow(/*#__PURE__*/Struct.get('sign'), /*#__PURE__*/Option.liftPredicate(/*#__PURE__*/Predicate.not(isPlusSign)), /*#__PURE__*/Option.map(signStringToSignValue));
|
68
|
+
/**
|
69
|
+
* Builds a `Parser` implementing `self`
|
70
|
+
*
|
71
|
+
* @category Destructors
|
72
|
+
*/
|
73
|
+
SignDisplay.toParser = /*#__PURE__*/flow(MMatch.make, /*#__PURE__*/MMatch.whenIs(SignDisplay.Auto, /*#__PURE__*/Function.constant(hasNotPlusSign)), /*#__PURE__*/MMatch.whenIs(SignDisplay.Always, /*#__PURE__*/Function.constant(hasASign)), /*#__PURE__*/MMatch.whenIs(SignDisplay.ExceptZero, () => flow(MMatch.make, MMatch.when(MPredicate.struct({
|
74
|
+
isZero: Function.identity
|
75
|
+
}), hasNoSign), MMatch.orElse(hasASign))), /*#__PURE__*/MMatch.whenIs(SignDisplay.Negative, () => flow(MMatch.make, MMatch.when(MPredicate.struct({
|
76
|
+
isZero: Function.identity
|
77
|
+
}), hasNoSign), MMatch.orElse(hasNotPlusSign))), /*#__PURE__*/MMatch.whenIs(SignDisplay.Never, /*#__PURE__*/Function.constant(hasNoSign)), MMatch.exhaustive);
|
78
|
+
/**
|
79
|
+
* Builds a `Formatter` implementing `self`
|
80
|
+
*
|
81
|
+
* @category Destructors
|
82
|
+
*/
|
83
|
+
SignDisplay.toFormatter = /*#__PURE__*/flow(MMatch.make, /*#__PURE__*/MMatch.whenIs(SignDisplay.Auto, () => ({
|
84
|
+
sign
|
85
|
+
}) => sign === -1 ? '-' : ''), /*#__PURE__*/MMatch.whenIs(SignDisplay.Always, () => ({
|
86
|
+
sign
|
87
|
+
}) => sign === -1 ? '-' : '+'), /*#__PURE__*/MMatch.whenIs(SignDisplay.ExceptZero, () => ({
|
88
|
+
sign,
|
89
|
+
isZero
|
90
|
+
}) => isZero ? '' : sign === -1 ? '-' : '+'), /*#__PURE__*/MMatch.whenIs(SignDisplay.Negative, () => ({
|
91
|
+
sign,
|
92
|
+
isZero
|
93
|
+
}) => isZero || sign === 1 ? '' : '-'), /*#__PURE__*/MMatch.whenIs(SignDisplay.Never, () => MFunction.constEmptyString), MMatch.exhaustive);
|
94
|
+
})(SignDisplay || (SignDisplay = {}));
|
95
|
+
/**
|
96
|
+
* Possible scientific notation options
|
97
|
+
*
|
98
|
+
* @category Models
|
99
|
+
*/
|
100
|
+
export var ScientificNotation;
|
101
|
+
(function (ScientificNotation) {
|
102
|
+
/**
|
103
|
+
* Formatting: scientific notation is not used.
|
104
|
+
*
|
105
|
+
* Parsing: conversion will fail if a scientific notation is present.
|
106
|
+
*/
|
107
|
+
ScientificNotation[ScientificNotation["None"] = 0] = "None";
|
108
|
+
/**
|
109
|
+
* Formatting: scientific notation is not used.
|
110
|
+
*
|
111
|
+
* Parsing: scientific notation may be used but is not mandatory.
|
112
|
+
*/
|
113
|
+
ScientificNotation[ScientificNotation["Standard"] = 1] = "Standard";
|
114
|
+
/**
|
115
|
+
* Formatting: scientific notation is used so that the absolute value of the mantissa m fulfills 1
|
116
|
+
* ≤ |m| < 10. Number 0 will be displayed as `0e0`.
|
117
|
+
*
|
118
|
+
* Parsing: the conversion will fail if the mantissa is not null and its value m does not fulfill
|
119
|
+
* 1 ≤ |m| < 10. Scientific notation may be used but is not mandatory. A string that does not
|
120
|
+
* contain a scientific notation is deemed equivalent to a string with a null exponent.
|
121
|
+
*/
|
122
|
+
ScientificNotation[ScientificNotation["Normalized"] = 2] = "Normalized";
|
123
|
+
/**
|
124
|
+
* Formatting: scientific notation is used so that the mantissa m fulfills 1 ≤ |m| < 1000 and the
|
125
|
+
* exponent is a multiple of 3. Number 0 will be displayed as `0e0`.
|
126
|
+
*
|
127
|
+
* Parsing: the conversion will fail if the mantissa is not null and its value m does not fulfill
|
128
|
+
* 1 ≤ |m| < 1000 or if the exponent is not a multiple of 3. Scientific notation may be used but
|
129
|
+
* is not mandatory. A string that does not contain a scientific notation is deemed equivalent to
|
130
|
+
* a string with a null exponent.
|
131
|
+
*/
|
132
|
+
ScientificNotation[ScientificNotation["Engineering"] = 3] = "Engineering";
|
133
|
+
})(ScientificNotation || (ScientificNotation = {}));
|
134
|
+
/**
|
135
|
+
* Namespace for possible scientific notation options
|
136
|
+
*
|
137
|
+
* @category Models
|
138
|
+
*/
|
139
|
+
(function (ScientificNotation) {
|
140
|
+
const _stringToExponent = /*#__PURE__*/flow(/*#__PURE__*/Option.liftPredicate(String.isNonEmpty), /*#__PURE__*/Option.map(MNumber.unsafeFromString), /*#__PURE__*/Option.orElseSome(/*#__PURE__*/Function.constant(0)));
|
141
|
+
/**
|
142
|
+
* Builds a `Parser` implementing `self`
|
143
|
+
*
|
144
|
+
* @category Destructors
|
145
|
+
*/
|
146
|
+
ScientificNotation.toParser = /*#__PURE__*/flow(MMatch.make, /*#__PURE__*/MMatch.whenIs(ScientificNotation.None, () => flow(Option.liftPredicate(String.isEmpty), Option.as(0))), /*#__PURE__*/MMatch.whenIsOr(ScientificNotation.Standard, ScientificNotation.Normalized, /*#__PURE__*/Function.constant(_stringToExponent)), /*#__PURE__*/MMatch.whenIs(ScientificNotation.Engineering, () => flow(_stringToExponent, Option.filter(MNumber.isMultipleOf(3)))), MMatch.exhaustive);
|
147
|
+
const zeroOrinRange = rangeTop => Predicate.or(BigDecimal.isZero, Predicate.and(BigDecimal.greaterThanOrEqualTo(BigDecimal.unsafeFromNumber(1)), BigDecimal.lessThan(BigDecimal.unsafeFromNumber(rangeTop))));
|
148
|
+
const zeroOrinOneToTenRange = /*#__PURE__*/zeroOrinRange(10);
|
149
|
+
const zeroOrinOneToOneThousandRange = /*#__PURE__*/zeroOrinRange(1000);
|
150
|
+
/**
|
151
|
+
* Builds a `Parser` implementing `self`
|
152
|
+
*
|
153
|
+
* @category Destructors
|
154
|
+
*/
|
155
|
+
ScientificNotation.toMantissaChecker = /*#__PURE__*/flow(MMatch.make, /*#__PURE__*/MMatch.whenIsOr(ScientificNotation.None, ScientificNotation.Standard, () => Option.some), /*#__PURE__*/MMatch.whenIs(ScientificNotation.Normalized, () => Option.liftPredicate(zeroOrinOneToTenRange)), /*#__PURE__*/MMatch.whenIs(ScientificNotation.Engineering, () => Option.liftPredicate(zeroOrinOneToOneThousandRange)), MMatch.exhaustive);
|
156
|
+
/**
|
157
|
+
* Builds a `Parser` implementing `self`
|
158
|
+
*
|
159
|
+
* @category Destructors
|
160
|
+
*/
|
161
|
+
ScientificNotation.toMantissaAdjuster = /*#__PURE__*/flow(MMatch.make, /*#__PURE__*/MMatch.whenIsOr(ScientificNotation.None, ScientificNotation.Standard, () => flow(Tuple.make, Tuple.appendElement(Option.none()))), /*#__PURE__*/MMatch.whenIs(ScientificNotation.Normalized, () => b => {
|
162
|
+
if (BigDecimal.isZero(b)) return Tuple.make(b, Option.some(0));
|
163
|
+
const value = b.value;
|
164
|
+
const log10 = MBigInt.unsafeLog10(BigInt.abs(value));
|
165
|
+
return Tuple.make(BigDecimal.make(value, log10), Option.some(log10 - b.scale));
|
166
|
+
}), /*#__PURE__*/MMatch.whenIs(ScientificNotation.Engineering, () => b => {
|
167
|
+
if (BigDecimal.isZero(b)) return Tuple.make(b, Option.some(0));
|
168
|
+
const value = b.value;
|
169
|
+
const log10 = MBigInt.unsafeLog10(BigInt.abs(value)) - b.scale;
|
170
|
+
const correctedLog10 = log10 - MNumber.intModulo(3)(log10);
|
171
|
+
return Tuple.make(BigDecimal.make(value, correctedLog10 + b.scale), Option.some(correctedLog10));
|
172
|
+
}), MMatch.exhaustive);
|
173
|
+
})(ScientificNotation || (ScientificNotation = {}));
|
174
|
+
/**
|
175
|
+
* Type guard
|
176
|
+
*
|
177
|
+
* @category Guards
|
178
|
+
*/
|
179
|
+
export const has = u => Predicate.hasProperty(u, _TypeId);
|
180
|
+
/** Prototype */
|
181
|
+
const proto = {
|
182
|
+
[_TypeId]: _TypeId,
|
183
|
+
... /*#__PURE__*/MInspectable.BaseProto(moduleTag),
|
184
|
+
...MPipeable.BaseProto
|
185
|
+
};
|
186
|
+
/**
|
187
|
+
* Constructor
|
188
|
+
*
|
189
|
+
* @category Constructors
|
190
|
+
*/
|
191
|
+
export const make = params => MTypes.objectFromDataAndProto(proto, params);
|
192
|
+
/**
|
193
|
+
* Returns the `thousandSeparator` property of `self`
|
194
|
+
*
|
195
|
+
* @category Destructors
|
196
|
+
*/
|
197
|
+
export const thousandSeparator = /*#__PURE__*/Struct.get('thousandSeparator');
|
198
|
+
/**
|
199
|
+
* Returns the `fractionalSeparator` property of `self`
|
200
|
+
*
|
201
|
+
* @category Destructors
|
202
|
+
*/
|
203
|
+
export const fractionalSeparator = /*#__PURE__*/Struct.get('fractionalSeparator');
|
204
|
+
/**
|
205
|
+
* Returns the `showNullIntegerPart` property of `self`
|
206
|
+
*
|
207
|
+
* @category Destructors
|
208
|
+
*/
|
209
|
+
export const showNullIntegerPart = /*#__PURE__*/Struct.get('showNullIntegerPart');
|
210
|
+
/**
|
211
|
+
* Returns the `minimumFractionalDigits` property of `self`
|
212
|
+
*
|
213
|
+
* @category Destructors
|
214
|
+
*/
|
215
|
+
export const minimumFractionalDigits = /*#__PURE__*/Struct.get('minimumFractionalDigits');
|
216
|
+
/**
|
217
|
+
* Returns the `maximumFractionalDigits` property of `self`
|
218
|
+
*
|
219
|
+
* @category Destructors
|
220
|
+
*/
|
221
|
+
export const maximumFractionalDigits = /*#__PURE__*/Struct.get('maximumFractionalDigits');
|
222
|
+
/**
|
223
|
+
* Returns the `eNotationChar` property of `self`
|
224
|
+
*
|
225
|
+
* @category Destructors
|
226
|
+
*/
|
227
|
+
export const eNotationChars = /*#__PURE__*/Struct.get('eNotationChars');
|
228
|
+
/**
|
229
|
+
* Returns the `scientificNotation` property of `self`
|
230
|
+
*
|
231
|
+
* @category Destructors
|
232
|
+
*/
|
233
|
+
export const scientificNotation = /*#__PURE__*/Struct.get('scientificNotation');
|
234
|
+
/**
|
235
|
+
* Returns the `roundingMode` property of `self`
|
236
|
+
*
|
237
|
+
* @category Destructors
|
238
|
+
*/
|
239
|
+
export const roundingMode = /*#__PURE__*/Struct.get('roundingMode');
|
240
|
+
/**
|
241
|
+
* Returns the `signDisplay` property of `self`
|
242
|
+
*
|
243
|
+
* @category Destructors
|
244
|
+
*/
|
245
|
+
export const signDisplay = /*#__PURE__*/Struct.get('signDisplay');
|
246
|
+
/**
|
247
|
+
* Returns a short description of `self`
|
248
|
+
*
|
249
|
+
* @category Destructors
|
250
|
+
*/
|
251
|
+
export const toDescription = self => {
|
252
|
+
const {
|
253
|
+
thousandSeparator,
|
254
|
+
fractionalSeparator,
|
255
|
+
minimumFractionalDigits,
|
256
|
+
maximumFractionalDigits,
|
257
|
+
scientificNotation,
|
258
|
+
signDisplay
|
259
|
+
} = self;
|
260
|
+
const isInteger = maximumFractionalDigits <= 0;
|
261
|
+
const isUngrouped = thousandSeparator === '';
|
262
|
+
return pipe(signDisplay, MMatch.make, MMatch.whenIs(SignDisplay.Always, Function.constant('signed ')), MMatch.whenIs(SignDisplay.Never, Function.constant('unsigned ')), MMatch.orElse(Function.constant('potentially signed '))) + (isUngrouped && isInteger ? '' : (isUngrouped || thousandSeparator === ' ') && (fractionalSeparator === ',' || isInteger) ? 'French-style ' : thousandSeparator === '.' && (fractionalSeparator === ',' || isInteger) ? 'Dutch-style ' : (isUngrouped || thousandSeparator === ',') && (fractionalSeparator === '.' || isInteger) ? 'UK-style ' : '') + (isInteger ? 'integer' : minimumFractionalDigits === maximumFractionalDigits ? `${minimumFractionalDigits}-decimal number` : 'number') + pipe(scientificNotation, MMatch.make, MMatch.whenIs(ScientificNotation.None, MFunction.constEmptyString), MMatch.whenIs(ScientificNotation.Standard, Function.constant(' in standard scientific notation')), MMatch.whenIs(ScientificNotation.Normalized, Function.constant(' in normalized scientific notation')), MMatch.whenIs(ScientificNotation.Engineering, Function.constant(' in engineering notation')), MMatch.exhaustive);
|
263
|
+
};
|
264
|
+
const _toBigDecimalExtractor = (self, fillChar = '') => {
|
265
|
+
const removeThousandSeparator = MString.removeNCharsEveryMCharsFromRight({
|
266
|
+
m: MRegExpString.DIGIT_GROUP_SIZE,
|
267
|
+
n: self.thousandSeparator.length
|
268
|
+
});
|
269
|
+
const getParts = MString.matchAndGroups(pipe(self, MStruct.append({
|
270
|
+
fillChar
|
271
|
+
}), MRegExpString.base10Number, MRegExpString.atStart, RegExp), 5);
|
272
|
+
const signParser = SignDisplay.toParser(self.signDisplay);
|
273
|
+
const exponentParser = ScientificNotation.toParser(self.scientificNotation);
|
274
|
+
const mantissaChecker = ScientificNotation.toMantissaChecker(self.scientificNotation);
|
275
|
+
const fillCharIsZero = fillChar === '0';
|
276
|
+
return text => Option.gen(function* () {
|
277
|
+
const [match, [signPart, fillChars, mantissaIntegerPart, mantissaFractionalPart, exponentPart]] = yield* getParts(text);
|
278
|
+
const mantissaFractionalPartLength = yield* pipe(mantissaFractionalPart, String.length, Option.liftPredicate(Number.between({
|
279
|
+
minimum: self.minimumFractionalDigits,
|
280
|
+
maximum: self.maximumFractionalDigits
|
281
|
+
})));
|
282
|
+
const mantissa = yield* pipe(mantissaIntegerPart, Option.liftPredicate(String.isNonEmpty), Option.match({
|
283
|
+
// No integer part
|
284
|
+
onNone: () => !self.showNullIntegerPart && mantissaFractionalPartLength !== 0 || fillCharIsZero && fillChars.length !== 0 ? Option.some(MBigDecimal.zero) : Option.none(),
|
285
|
+
// With integer part
|
286
|
+
onSome: flow(self.showNullIntegerPart || mantissaFractionalPartLength === 0 ? Option.some : Option.liftPredicate(Predicate.not(MPredicate.strictEquals('0'))), Option.map(flow(removeThousandSeparator, MBigDecimal.fromPrimitiveOrThrow(0))))
|
287
|
+
}), Option.map(BigDecimal.sum(pipe(mantissaFractionalPart, Option.liftPredicate(String.isNonEmpty), Option.map(MBigDecimal.fromPrimitiveOrThrow(mantissaFractionalPartLength)), Option.getOrElse(Function.constant(MBigDecimal.zero))))));
|
288
|
+
const checkedMantissa = yield* mantissaChecker(mantissa);
|
289
|
+
const sign = yield* signParser({
|
290
|
+
isZero: BigDecimal.isZero(checkedMantissa),
|
291
|
+
sign: signPart
|
292
|
+
});
|
293
|
+
const exponent = yield* exponentParser(exponentPart);
|
294
|
+
return Tuple.make(BigDecimal.make(checkedMantissa.value, checkedMantissa.scale - exponent), match, sign);
|
295
|
+
});
|
296
|
+
};
|
297
|
+
/**
|
298
|
+
* Returns a function that tries to parse, from the start of a string `text`, a number respecting
|
299
|
+
* the options represented by `self` and an optional `fillChar` parameter. If successful, that
|
300
|
+
* function returns a `some` containing `parsedText` (the part of `text` that could be analyzed as
|
301
|
+
* representing a number) and `value` (`parsedText` converted to a BigDecimal value). Otherwise, it
|
302
|
+
* returns a `none`. As there is no way to distinguish `-0n` and `0n` in Javascript, parsing '-0',
|
303
|
+
* '0', '+0' will yield the same result.
|
304
|
+
*
|
305
|
+
* `fillChar` is a character that may be used as filler between the sign and the number (or at the
|
306
|
+
* start of the number if it is unsigned). It must be a one-character string (but no error is
|
307
|
+
* triggered if it's not). You can use '0' as `fillChar` but you shoud not use any other digit
|
308
|
+
* because the value of the number to parse would depend on the number of removed `fillChar`'s.
|
309
|
+
*
|
310
|
+
* @category Parsing
|
311
|
+
*/
|
312
|
+
export const toBigDecimalExtractor = /*#__PURE__*/flow(_toBigDecimalExtractor, /*#__PURE__*/Function.compose(/*#__PURE__*/Option.map(([value, parsedText, sign]) => Tuple.make(BigDecimal.multiply(value, BigDecimal.unsafeFromNumber(sign)), parsedText))));
|
313
|
+
/**
|
314
|
+
* Same as toBigDecimalExtractor but the returned parser throws in case of error
|
315
|
+
*
|
316
|
+
* @category Parsing
|
317
|
+
*/
|
318
|
+
export const toThrowingBigDecimalExtractor = (self, fillChar) => text => pipe(text, toBigDecimalExtractor(self, fillChar), Option.getOrThrowWith(() => new Error(`A BigDecimal could not be parsed from the start of '${text}'`)));
|
319
|
+
/**
|
320
|
+
* Same as `toBigDecimalExtractor` but returns a `Real` which is the most usual use case.
|
321
|
+
* Furthermore, this function will return -0 if your parse '-0' and 0 if you parse '0' or '+0'.
|
322
|
+
*
|
323
|
+
* @category Parsing
|
324
|
+
*/
|
325
|
+
export const toRealExtractor = /*#__PURE__*/flow(_toBigDecimalExtractor, /*#__PURE__*/Function.compose(/*#__PURE__*/Option.flatMap(([value, parsedText, sign]) => pipe(value, CVReal.fromBigDecimalOption, Option.map(flow(Number.multiply(sign), Tuple.make, Tuple.appendElement(parsedText)))))));
|
326
|
+
/**
|
327
|
+
* Same as toRealExtractor but the returned parser throws in case of error
|
328
|
+
*
|
329
|
+
* @category Parsing
|
330
|
+
*/
|
331
|
+
export const toThrowingRealExtractor = (self, fillChar) => text => pipe(text, toRealExtractor(self, fillChar), Option.getOrThrowWith(() => new Error(`A Real could not be parsed from the start of '${text}'`)));
|
332
|
+
/**
|
333
|
+
* Same as toBigDecimalExtractor but the whole of the input text must represent a number, not just
|
334
|
+
* its start
|
335
|
+
*
|
336
|
+
* @category Parsing
|
337
|
+
*/
|
338
|
+
export const toBigDecimalParser = (self, fillChar) => {
|
339
|
+
const extractor = toBigDecimalExtractor(self, fillChar);
|
340
|
+
return text => pipe(text, extractor, Option.flatMap(flow(Option.liftPredicate(flow(Tuple.getSecond, String.length, MPredicate.strictEquals(text.length))), Option.map(Tuple.getFirst))));
|
341
|
+
};
|
342
|
+
/**
|
343
|
+
* Same as toRealExtractor but the returned parser throws in case of error
|
344
|
+
*
|
345
|
+
* @category Parsing
|
346
|
+
*/
|
347
|
+
export const toThrowingBigDecimalParser = (self, fillChar) => text => pipe(text, toBigDecimalParser(self, fillChar), Option.getOrThrowWith(() => new Error(`A BigDecimal could not be parsed from '${text}'`)));
|
348
|
+
/**
|
349
|
+
* Same as `toRealExtractor` but the whole of the input text must represent a number, not just its
|
350
|
+
* start
|
351
|
+
*
|
352
|
+
* @category Parsing
|
353
|
+
*/
|
354
|
+
export const toRealParser = (self, fillChar) => {
|
355
|
+
const extractor = toRealExtractor(self, fillChar);
|
356
|
+
return text => pipe(text, extractor, Option.flatMap(flow(Option.liftPredicate(flow(Tuple.getSecond, String.length, MPredicate.strictEquals(text.length))), Option.map(Tuple.getFirst))));
|
357
|
+
};
|
358
|
+
/**
|
359
|
+
* Same as toRealParser but the returned parser throws in case of error
|
360
|
+
*
|
361
|
+
* @category Parsing
|
362
|
+
*/
|
363
|
+
export const toThrowingRealParser = (self, fillChar) => text => pipe(text, toRealParser(self, fillChar), Option.getOrThrowWith(() => new Error(`A Real could not be parsed from '${text}'`)));
|
364
|
+
/**
|
365
|
+
* Returns a function that tries to format a `number` respecting the options represented by
|
366
|
+
* `self`and an optional parameter `fillChars`. If successful, that function returns a `some` of the
|
367
|
+
* formatted number. Otherwise, it returns a `none`. `number` can be of type number or BigDecimal
|
368
|
+
* for better accuracy. There is a difference between number and BigDecimal (and bigint) regarding
|
369
|
+
* the sign of 0. In Javascript, Object.is(0,-0) is false whereas Object.is(0n,-0n) is true. So if
|
370
|
+
* the sign of zero is important to you, prefer passing a number to the function. `0` as a
|
371
|
+
* BigDecimal will always be interpreted as a positive `0` as we have no means of knowing if it is
|
372
|
+
* negative or positive.
|
373
|
+
*
|
374
|
+
* `fillChars` is a string whose first characters will be inserted between the sign and the number
|
375
|
+
* (or at the start of the number if it is unsigned) so that the formatted number has at least the
|
376
|
+
* same number of characters as fillChars (e.g. the result will be '-02' if you try to format the
|
377
|
+
* value -2 with fillChars = '000')
|
378
|
+
*
|
379
|
+
* @category Formatting
|
380
|
+
*/
|
381
|
+
export const toNumberFormatter = (self, fillChars = '') => {
|
382
|
+
const rounder = self.maximumFractionalDigits === +Infinity ? Function.identity : pipe({
|
383
|
+
precision: self.maximumFractionalDigits,
|
384
|
+
roundingMode: self.roundingMode
|
385
|
+
}, CVRoundingOption.make, CVRoundingOption.toBigDecimalRounder);
|
386
|
+
const signFormatter = SignDisplay.toFormatter(self.signDisplay);
|
387
|
+
const mantissaAdjuster = ScientificNotation.toMantissaAdjuster(self.scientificNotation);
|
388
|
+
const hasThousandSeparator = self.thousandSeparator !== '';
|
389
|
+
const eNotationChar = pipe(self.eNotationChars, Array.get(0), Option.getOrElse(MFunction.constEmptyString));
|
390
|
+
const takeNFirstCharsOfFillChars = MFunction.flipDual(String.takeLeft)(fillChars);
|
391
|
+
return number => {
|
392
|
+
const [sign, selfAsBigDecimal] = MTypes.isNumber(number) ? Tuple.make(number < 0 || Object.is(-0, number) ? -1 : 1, BigDecimal.unsafeFromNumber(number)) : Tuple.make(number.value < 0 ? -1 : 1, number);
|
393
|
+
const [adjusted, exponent] = mantissaAdjuster(selfAsBigDecimal);
|
394
|
+
const absRounded = pipe(adjusted, rounder, BigDecimal.abs);
|
395
|
+
const [integerPart, fractionalPart] = pipe(absRounded, MBigDecimal.truncatedAndFollowingParts());
|
396
|
+
const signString = signFormatter({
|
397
|
+
sign,
|
398
|
+
isZero: BigDecimal.isZero(absRounded)
|
399
|
+
});
|
400
|
+
const normalizedFractionalPart = BigDecimal.normalize(fractionalPart);
|
401
|
+
const fractionalPartString = pipe(normalizedFractionalPart.value, Option.liftPredicate(Predicate.not(MBigInt.isZero)), Option.map(MString.fromNonNullablePrimitive), Option.getOrElse(MFunction.constEmptyString), String.padStart(normalizedFractionalPart.scale, '0'), String.padEnd(self.minimumFractionalDigits, '0'), Option.liftPredicate(String.isNonEmpty), Option.map(MString.prepend(self.fractionalSeparator)), Option.getOrElse(MFunction.constEmptyString));
|
402
|
+
const integerPartString = pipe(integerPart.value.toString(), MFunction.fIfTrue({
|
403
|
+
condition: hasThousandSeparator,
|
404
|
+
f: flow(MString.splitEquallyRestAtStart(MRegExpString.DIGIT_GROUP_SIZE), Array.intersperse(self.thousandSeparator), Array.join(''))
|
405
|
+
}), Either.liftPredicate(Predicate.not(MPredicate.strictEquals('0')), MFunction.fIfTrue({
|
406
|
+
condition: !self.showNullIntegerPart && fractionalPartString.length !== 0,
|
407
|
+
f: MFunction.constEmptyString
|
408
|
+
})), Either.merge);
|
409
|
+
const exponentString = pipe(exponent, Option.map(flow(MString.fromNumber(10), MString.prepend(eNotationChar))), Option.getOrElse(MFunction.constEmptyString));
|
410
|
+
const numberString = integerPartString + fractionalPartString + exponentString;
|
411
|
+
const pad = pipe(fillChars.length, Number.subtract(signString.length), Number.subtract(numberString.length), Number.max(0), takeNFirstCharsOfFillChars);
|
412
|
+
return signString + pad + numberString;
|
413
|
+
};
|
414
|
+
};
|
415
|
+
/**
|
416
|
+
* Combinator that returns a copy of self with `minimumFractionalDigits` and
|
417
|
+
* `maximumFractionalDigits` set to `n`. `n` must be a finite positive integer.
|
418
|
+
*
|
419
|
+
* @category Modifiers
|
420
|
+
*/
|
421
|
+
export const withNDecimals = decimalNumber => flow(MStruct.append({
|
422
|
+
minimumFractionalDigits: decimalNumber,
|
423
|
+
maximumFractionalDigits: decimalNumber
|
424
|
+
}), make);
|
425
|
+
/**
|
426
|
+
* Combinator that returns a copy of self with `maximumFractionalDigits` set to `n`. `n` must be a
|
427
|
+
* positive integer. Pass 0 for an integer format.
|
428
|
+
*
|
429
|
+
* @category Modifiers
|
430
|
+
*/
|
431
|
+
export const withMaxNDecimals = maxDecimalNumber => self => pipe(self, MStruct.append({
|
432
|
+
minimumFractionalDigits: Math.min(self.minimumFractionalDigits, maxDecimalNumber),
|
433
|
+
maximumFractionalDigits: maxDecimalNumber
|
434
|
+
}), make);
|
435
|
+
/**
|
436
|
+
* Combinator that returns a copy of self with `minimumFractionalDigits` set to `n`. `n` must be a
|
437
|
+
* finite positive integer.
|
438
|
+
*
|
439
|
+
* @category Modifiers
|
440
|
+
*/
|
441
|
+
export const withMinNDecimals = minDecimalNumber => self => pipe(self, MStruct.append({
|
442
|
+
minimumFractionalDigits: minDecimalNumber,
|
443
|
+
maximumFractionalDigits: Math.max(self.maximumFractionalDigits, minDecimalNumber)
|
444
|
+
}), make);
|
445
|
+
/**
|
446
|
+
* Combinator that returns a copy of self with `scientificNotation` set to `None`.
|
447
|
+
*
|
448
|
+
* @category Modifiers
|
449
|
+
*/
|
450
|
+
export const withNoScientificNotation = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
451
|
+
scientificNotation: ScientificNotation.None
|
452
|
+
}), make);
|
453
|
+
/**
|
454
|
+
* Combinator that returns a copy of self with `scientificNotation` set to `Standard`.
|
455
|
+
*
|
456
|
+
* @category Modifiers
|
457
|
+
*/
|
458
|
+
export const withStandardScientificNotation = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
459
|
+
scientificNotation: ScientificNotation.Standard
|
460
|
+
}), make);
|
461
|
+
/**
|
462
|
+
* Combinator that returns a copy of self with `scientificNotation` set to `Normalized`.
|
463
|
+
*
|
464
|
+
* @category Modifiers
|
465
|
+
*/
|
466
|
+
export const withNormalizedScientificNotation = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
467
|
+
scientificNotation: ScientificNotation.Normalized
|
468
|
+
}), make);
|
469
|
+
/**
|
470
|
+
* Combinator that returns a copy of self with `scientificNotation` set to `Engineering`.
|
471
|
+
*
|
472
|
+
* @category Modifiers
|
473
|
+
*/
|
474
|
+
export const withEngineeringScientificNotation = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
475
|
+
scientificNotation: ScientificNotation.Engineering
|
476
|
+
}), make);
|
477
|
+
/**
|
478
|
+
* Combinator that returns a copy of self with `thousandSeparator` set to `thousandSeparator`.
|
479
|
+
*
|
480
|
+
* @category Modifiers
|
481
|
+
*/
|
482
|
+
export const withThousandSeparator = thousandSeparator => flow(MStruct.append({
|
483
|
+
thousandSeparator
|
484
|
+
}), make);
|
485
|
+
/**
|
486
|
+
* Combinator that returns a copy of self with `thousandSeparator` set to ''.
|
487
|
+
*
|
488
|
+
* @category Modifiers
|
489
|
+
*/
|
490
|
+
export const withoutThousandSeparator = /*#__PURE__*/withThousandSeparator('');
|
491
|
+
/**
|
492
|
+
* Combinator that returns a copy of self with `fractionalSeparator` set to `fractionalSeparator`.
|
493
|
+
*
|
494
|
+
* @category Modifiers
|
495
|
+
*/
|
496
|
+
export const withFractionalSeparator = fractionalSeparator => flow(MStruct.append({
|
497
|
+
fractionalSeparator: fractionalSeparator
|
498
|
+
}), make);
|
499
|
+
/**
|
500
|
+
* Combinator that returns a copy of self with `signDisplay` set to `Auto`.
|
501
|
+
*
|
502
|
+
* @category Modifiers
|
503
|
+
*/
|
504
|
+
export const withSignDisplayForNegative = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
505
|
+
signDisplay: SignDisplay.Auto
|
506
|
+
}), make);
|
507
|
+
/**
|
508
|
+
* Combinator that returns a copy of self with `signDisplay` set to `Always`.
|
509
|
+
*
|
510
|
+
* @category Modifiers
|
511
|
+
*/
|
512
|
+
export const withSignDisplay = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
513
|
+
signDisplay: SignDisplay.Always
|
514
|
+
}), make);
|
515
|
+
/**
|
516
|
+
* Combinator that returns a copy of self with `signDisplay` set to `ExceptZero`.
|
517
|
+
*
|
518
|
+
* @category Modifiers
|
519
|
+
*/
|
520
|
+
export const withSignDisplayExceptZero = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
521
|
+
signDisplay: SignDisplay.ExceptZero
|
522
|
+
}), make);
|
523
|
+
/**
|
524
|
+
* Combinator that returns a copy of self with `signDisplay` set to `Negative`.
|
525
|
+
*
|
526
|
+
* @category Modifiers
|
527
|
+
*/
|
528
|
+
export const withSignDisplayForNegativeExceptZero = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
529
|
+
signDisplay: SignDisplay.Negative
|
530
|
+
}), make);
|
531
|
+
/**
|
532
|
+
* Combinator that returns a copy of self with `signDisplay` set to `Never`.
|
533
|
+
*
|
534
|
+
* @category Modifiers
|
535
|
+
*/
|
536
|
+
export const withoutSignDisplay = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
537
|
+
signDisplay: SignDisplay.Never
|
538
|
+
}), make);
|
539
|
+
/**
|
540
|
+
* Combinator that returns a copy of self with `roundingMode` set to `Ceil`.
|
541
|
+
*
|
542
|
+
* @category Modifiers
|
543
|
+
*/
|
544
|
+
export const withCeilRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
545
|
+
roundingMode: CVRoundingMode.Type.Ceil
|
546
|
+
}), make);
|
547
|
+
/**
|
548
|
+
* Combinator that returns a copy of self with `roundingMode` set to `Floor`.
|
549
|
+
*
|
550
|
+
* @category Modifiers
|
551
|
+
*/
|
552
|
+
export const withFloorRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
553
|
+
roundingMode: CVRoundingMode.Type.Floor
|
554
|
+
}), make);
|
555
|
+
/**
|
556
|
+
* Combinator that returns a copy of self with `roundingMode` set to `Expand`.
|
557
|
+
*
|
558
|
+
* @category Modifiers
|
559
|
+
*/
|
560
|
+
export const withExpandRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
561
|
+
roundingMode: CVRoundingMode.Type.Expand
|
562
|
+
}), make);
|
563
|
+
/**
|
564
|
+
* Combinator that returns a copy of self with `roundingMode` set to `Trunc`.
|
565
|
+
*
|
566
|
+
* @category Modifiers
|
567
|
+
*/
|
568
|
+
export const withTruncRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
569
|
+
roundingMode: CVRoundingMode.Type.Trunc
|
570
|
+
}), make);
|
571
|
+
/**
|
572
|
+
* Combinator that returns a copy of self with `roundingMode` set to `HalfCeil`.
|
573
|
+
*
|
574
|
+
* @category Modifiers
|
575
|
+
*/
|
576
|
+
export const withHalfCeilRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
577
|
+
roundingMode: CVRoundingMode.Type.HalfCeil
|
578
|
+
}), make);
|
579
|
+
/**
|
580
|
+
* Combinator that returns a copy of self with `roundingMode` set to `HalfFloor`.
|
581
|
+
*
|
582
|
+
* @category Modifiers
|
583
|
+
*/
|
584
|
+
export const withHalfFloorRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
585
|
+
roundingMode: CVRoundingMode.Type.HalfFloor
|
586
|
+
}), make);
|
587
|
+
/**
|
588
|
+
* Combinator that returns a copy of self with `roundingMode` set to `HalfExpand`.
|
589
|
+
*
|
590
|
+
* @category Modifiers
|
591
|
+
*/
|
592
|
+
export const withHalfExpandRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
593
|
+
roundingMode: CVRoundingMode.Type.HalfExpand
|
594
|
+
}), make);
|
595
|
+
/**
|
596
|
+
* Combinator that returns a copy of self with `roundingMode` set to `HalfTrunc`.
|
597
|
+
*
|
598
|
+
* @category Modifiers
|
599
|
+
*/
|
600
|
+
export const withHalfTruncRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
601
|
+
roundingMode: CVRoundingMode.Type.HalfTrunc
|
602
|
+
}), make);
|
603
|
+
/**
|
604
|
+
* Combinator that returns a copy of self with `roundingMode` set to `HalfEven`.
|
605
|
+
*
|
606
|
+
* @category Modifiers
|
607
|
+
*/
|
608
|
+
export const withHalfEvenRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
609
|
+
roundingMode: CVRoundingMode.Type.HalfEven
|
610
|
+
}), make);
|
611
|
+
/**
|
612
|
+
* Combinator that returns a copy of self with `showNullIntegerPart` set to `false`.
|
613
|
+
*
|
614
|
+
* @category Modifiers
|
615
|
+
*/
|
616
|
+
export const withNullIntegerPartNotShowing = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
617
|
+
showNullIntegerPart: false
|
618
|
+
}), make);
|
619
|
+
/**
|
620
|
+
* Combinator that returns a copy of self with `showNullIntegerPart` set to `true`.
|
621
|
+
*
|
622
|
+
* @category Modifiers
|
623
|
+
*/
|
624
|
+
export const withNullIntegerPartShowing = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
625
|
+
showNullIntegerPart: true
|
626
|
+
}), make);
|
627
|
+
/**
|
628
|
+
* NumberBase10Format instance that uses a comma as fractional separator, a space as thousand
|
629
|
+
* separator and shows at most three fractional digits. Used in countries like France,
|
630
|
+
* French-speaking Canada, French-speaking Belgium, Denmark, Finland, Sweden...
|
631
|
+
*
|
632
|
+
* @category Instances
|
633
|
+
*/
|
634
|
+
export const frenchStyleNumber = /*#__PURE__*/make({
|
635
|
+
thousandSeparator: ' ',
|
636
|
+
fractionalSeparator: ',',
|
637
|
+
showNullIntegerPart: true,
|
638
|
+
minimumFractionalDigits: 0,
|
639
|
+
maximumFractionalDigits: 3,
|
640
|
+
eNotationChars: ['e', 'E'],
|
641
|
+
scientificNotation: ScientificNotation.None,
|
642
|
+
roundingMode: CVRoundingMode.Type.HalfExpand,
|
643
|
+
signDisplay: SignDisplay.Negative
|
644
|
+
});
|
645
|
+
/**
|
646
|
+
* NumberBase10Format instance that uses a comma as fractional separator, no thousand separator and
|
647
|
+
* shows at most three fractional digits. Used in countries like France, French-speaking Canada,
|
648
|
+
* French-speaking Belgium, Denmark, Finland, Sweden...
|
649
|
+
*
|
650
|
+
* @category Instances
|
651
|
+
*/
|
652
|
+
export const frenchStyleUngroupedNumber = /*#__PURE__*/pipe(frenchStyleNumber, withoutThousandSeparator);
|
653
|
+
/**
|
654
|
+
* French-style integer NumberBase10Format instance. Used in countries like France, French-speaking
|
655
|
+
* Canada, French-speaking Belgium, Denmark, Finland, Sweden...
|
656
|
+
*
|
657
|
+
* @category Instances
|
658
|
+
*/
|
659
|
+
export const frenchStyleInteger = /*#__PURE__*/pipe(frenchStyleNumber, /*#__PURE__*/withMaxNDecimals(0));
|
660
|
+
/**
|
661
|
+
* NumberBase10Format instance that uses a comma as fractional separator, a dot as thousand
|
662
|
+
* separator and shows at most three fractional digits. Used in countries like Dutch-speaking
|
663
|
+
* Belgium, the Netherlands, Germany, Italy, Norway, Croatia, Spain...
|
664
|
+
*
|
665
|
+
* @category Instances
|
666
|
+
*/
|
667
|
+
export const dutchStyleNumber = /*#__PURE__*/pipe(frenchStyleNumber, /*#__PURE__*/MStruct.append({
|
668
|
+
thousandSeparator: '.'
|
669
|
+
}), make);
|
670
|
+
/**
|
671
|
+
* NumberBase10Format instance that uses a comma as fractional separator, no thousand separator and
|
672
|
+
* shows at most three fractional digits. Used in countries like Dutch-speaking Belgium, the
|
673
|
+
* Netherlands, Germany, Italy, Norway, Croatia, Spain...
|
674
|
+
*
|
675
|
+
* @category Instances
|
676
|
+
*/
|
677
|
+
export const dutchStyleUngroupedNumber = /*#__PURE__*/pipe(dutchStyleNumber, withoutThousandSeparator);
|
678
|
+
/**
|
679
|
+
* Dutch-style integer NumberBase10Format instance. Used in countries like Dutch-speaking Belgium,
|
680
|
+
* the Netherlands, Germany, Italy, Norway, Croatia, Spain...
|
681
|
+
*
|
682
|
+
* @category Instances
|
683
|
+
*/
|
684
|
+
export const dutchStyleInteger = /*#__PURE__*/pipe(dutchStyleNumber, /*#__PURE__*/withMaxNDecimals(0));
|
685
|
+
/**
|
686
|
+
* NumberBase10Format instance that uses a dot as fractional separator, a comma as thousand
|
687
|
+
* separator and shows at most three fractional digits. Used in countries like the UK, the US,
|
688
|
+
* English-speaking Canada, Australia, Thaïland, Bosnia...
|
689
|
+
*
|
690
|
+
* @category Instances
|
691
|
+
*/
|
692
|
+
export const ukStyleNumber = /*#__PURE__*/pipe(frenchStyleNumber, /*#__PURE__*/MStruct.append({
|
693
|
+
fractionalSeparator: '.',
|
694
|
+
thousandSeparator: ','
|
695
|
+
}), make);
|
696
|
+
/**
|
697
|
+
* NumberBase10Format instance that uses a dot as fractional separator, no thousand separator and
|
698
|
+
* shows at most three fractional digits. Used in countries like the UK, the US, English-speaking
|
699
|
+
* Canada, Australia, Thaïland, Bosnia...
|
700
|
+
*
|
701
|
+
* @category Instances
|
702
|
+
*/
|
703
|
+
export const ukStyleUngroupedNumber = /*#__PURE__*/pipe(ukStyleNumber, withoutThousandSeparator);
|
704
|
+
/**
|
705
|
+
* Uk-style integer NumberBase10Format instance. Used in countries like the UK, the US,
|
706
|
+
* English-speaking Canada, Australia, Thaïland, Bosnia...
|
707
|
+
*
|
708
|
+
* @category Instances
|
709
|
+
*/
|
710
|
+
export const ukStyleInteger = /*#__PURE__*/pipe(ukStyleNumber, /*#__PURE__*/withMaxNDecimals(0));
|
711
|
+
/**
|
712
|
+
* Integer NumberBase10Format instance with no thousand separator
|
713
|
+
*
|
714
|
+
* @category Instances
|
715
|
+
*/
|
716
|
+
export const integer = /*#__PURE__*/pipe(frenchStyleInteger, withoutThousandSeparator);
|
717
|
+
//# sourceMappingURL=NumberBase10Format.js.map
|