@parischap/conversions 0.1.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.
- package/README.md +50 -49
- package/cjs/BigDecimal.js +2 -2
- package/cjs/BigInt.js +7 -5
- package/cjs/BigInt.js.map +1 -1
- package/cjs/DateTime.js +144 -136
- package/cjs/DateTime.js.map +1 -1
- package/cjs/DateTimeFormat.js +7 -2
- package/cjs/DateTimeFormat.js.map +1 -1
- package/cjs/DateTimeFormatContext.js +11 -6
- package/cjs/DateTimeFormatContext.js.map +1 -1
- package/cjs/Email.js +11 -15
- package/cjs/Email.js.map +1 -1
- package/cjs/Integer.js +33 -23
- package/cjs/Integer.js.map +1 -1
- package/cjs/NumberBase10Format.js +65 -65
- package/cjs/PositiveInteger.js +44 -29
- package/cjs/PositiveInteger.js.map +1 -1
- package/cjs/PositiveReal.js +34 -24
- package/cjs/PositiveReal.js.map +1 -1
- package/cjs/Real.js +29 -18
- package/cjs/Real.js.map +1 -1
- package/cjs/RoundingMode.js +7 -4
- package/cjs/RoundingMode.js.map +1 -1
- package/cjs/RoundingOption.js +6 -6
- package/cjs/RoundingOption.js.map +1 -1
- package/cjs/Schema.js +29 -28
- package/cjs/Schema.js.map +1 -1
- package/cjs/SemVer.js +19 -20
- package/cjs/SemVer.js.map +1 -1
- package/cjs/Template.js +36 -31
- package/cjs/Template.js.map +1 -1
- package/cjs/TemplatePart.js +4 -4
- package/cjs/TemplateParts.js +3 -2
- package/cjs/TemplateParts.js.map +1 -1
- package/cjs/TemplatePlaceholder.js +56 -45
- package/cjs/TemplatePlaceholder.js.map +1 -1
- package/cjs/TemplateSeparator.js +17 -24
- package/cjs/TemplateSeparator.js.map +1 -1
- package/cjs/internal/Int.js +5 -8
- package/cjs/internal/Int.js.map +1 -1
- package/cjs/internal/Positive.js +5 -8
- package/cjs/internal/Positive.js.map +1 -1
- package/dts/BigDecimal.d.ts +2 -2
- package/dts/BigDecimal.d.ts.map +1 -1
- package/dts/BigInt.d.ts +7 -5
- package/dts/BigInt.d.ts.map +1 -1
- package/dts/DateTime.d.ts +145 -137
- package/dts/DateTime.d.ts.map +1 -1
- package/dts/DateTimeFormat.d.ts +7 -2
- package/dts/DateTimeFormat.d.ts.map +1 -1
- package/dts/DateTimeFormatContext.d.ts +17 -12
- package/dts/DateTimeFormatContext.d.ts.map +1 -1
- package/dts/Email.d.ts +16 -13
- package/dts/Email.d.ts.map +1 -1
- package/dts/Integer.d.ts +43 -21
- package/dts/Integer.d.ts.map +1 -1
- package/dts/NumberBase10Format.d.ts +68 -68
- package/dts/PositiveInteger.d.ts +54 -27
- package/dts/PositiveInteger.d.ts.map +1 -1
- package/dts/PositiveReal.d.ts +44 -22
- package/dts/PositiveReal.d.ts.map +1 -1
- package/dts/Real.d.ts +39 -16
- package/dts/Real.d.ts.map +1 -1
- package/dts/RoundingMode.d.ts +6 -3
- package/dts/RoundingMode.d.ts.map +1 -1
- package/dts/RoundingOption.d.ts +6 -6
- package/dts/Schema.d.ts +32 -33
- package/dts/Schema.d.ts.map +1 -1
- package/dts/SemVer.d.ts +25 -13
- package/dts/SemVer.d.ts.map +1 -1
- package/dts/Template.d.ts +30 -29
- package/dts/Template.d.ts.map +1 -1
- package/dts/TemplatePart.d.ts +4 -4
- package/dts/TemplateParts.d.ts +4 -3
- package/dts/TemplateParts.d.ts.map +1 -1
- package/dts/TemplatePlaceholder.d.ts +56 -44
- package/dts/TemplatePlaceholder.d.ts.map +1 -1
- package/dts/TemplateSeparator.d.ts +9 -51
- package/dts/TemplateSeparator.d.ts.map +1 -1
- package/dts/internal/Int.d.ts +0 -4
- package/dts/internal/Int.d.ts.map +1 -1
- package/dts/internal/Positive.d.ts +0 -4
- package/dts/internal/Positive.d.ts.map +1 -1
- package/esm/BigDecimal.js +2 -2
- package/esm/BigInt.js +7 -5
- package/esm/BigInt.js.map +1 -1
- package/esm/DateTime.js +144 -136
- package/esm/DateTime.js.map +1 -1
- package/esm/DateTimeFormat.js +7 -2
- package/esm/DateTimeFormat.js.map +1 -1
- package/esm/DateTimeFormatContext.js +11 -6
- package/esm/DateTimeFormatContext.js.map +1 -1
- package/esm/Email.js +10 -13
- package/esm/Email.js.map +1 -1
- package/esm/Integer.js +33 -23
- package/esm/Integer.js.map +1 -1
- package/esm/NumberBase10Format.js +65 -65
- package/esm/PositiveInteger.js +44 -29
- package/esm/PositiveInteger.js.map +1 -1
- package/esm/PositiveReal.js +34 -24
- package/esm/PositiveReal.js.map +1 -1
- package/esm/Real.js +29 -18
- package/esm/Real.js.map +1 -1
- package/esm/RoundingMode.js +6 -3
- package/esm/RoundingMode.js.map +1 -1
- package/esm/RoundingOption.js +6 -6
- package/esm/RoundingOption.js.map +1 -1
- package/esm/Schema.js +33 -34
- package/esm/Schema.js.map +1 -1
- package/esm/SemVer.js +18 -18
- package/esm/SemVer.js.map +1 -1
- package/esm/Template.js +36 -31
- package/esm/Template.js.map +1 -1
- package/esm/TemplatePart.js +4 -4
- package/esm/TemplateParts.js +3 -2
- package/esm/TemplateParts.js.map +1 -1
- package/esm/TemplatePlaceholder.js +55 -44
- package/esm/TemplatePlaceholder.js.map +1 -1
- package/esm/TemplateSeparator.js +16 -24
- package/esm/TemplateSeparator.js.map +1 -1
- package/esm/internal/Int.js +5 -7
- package/esm/internal/Int.js.map +1 -1
- package/esm/internal/Positive.js +5 -7
- package/esm/internal/Positive.js.map +1 -1
- package/package.json +2 -2
package/esm/Integer.js
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
/**
|
2
|
-
* This module implements a
|
3
|
-
* disallowed)
|
2
|
+
* This module implements a CVInteger brand, i.e. a number that represents an integer (Infinity, NaN
|
3
|
+
* disallowed). Can be used to represent a floor in a lift, a signed quantity... See the `Effect`
|
4
|
+
* documentation about Branding (https://effect.website/docs/code-style/branded-types/) if you are
|
5
|
+
* not familiar with this concept.
|
4
6
|
*/
|
5
7
|
import { Brand, Either, flow, Function, Option, Schema } from 'effect';
|
6
8
|
import * as CVInt from './internal/Int.js';
|
@@ -14,115 +16,123 @@ export const moduleTag = '@parischap/conversions/Integer/';
|
|
14
16
|
/**
|
15
17
|
* Brand constructor. Should not be used directly
|
16
18
|
*
|
17
|
-
* @
|
19
|
+
* @ignore
|
18
20
|
*/
|
19
21
|
export const constructor = /*#__PURE__*/Brand.all(CVReal.constructor, CVInt.constructor);
|
20
22
|
/**
|
21
|
-
* Constructs
|
23
|
+
* Constructs a `CVInteger` from a number without any verifications
|
22
24
|
*
|
23
25
|
* @category Constructors
|
24
26
|
*/
|
25
27
|
export const unsafeFromNumber = /*#__PURE__*/Brand.nominal();
|
26
28
|
/**
|
27
|
-
*
|
29
|
+
* Tries to construct a `CVInteger` from a number. Returns a `Some` if the conversion can be
|
30
|
+
* performed, a `None` otherwise
|
28
31
|
*
|
29
32
|
* @category Constructors
|
30
33
|
*/
|
31
34
|
export const fromNumberOption = /*#__PURE__*/constructor.option.bind(constructor);
|
32
35
|
/**
|
33
|
-
*
|
36
|
+
* Tries to construct a `CVnteger` from a number. Returns a `Right` if the conversion can be
|
37
|
+
* performed, a `Left` otherwise
|
34
38
|
*
|
35
39
|
* @category Constructors
|
36
40
|
*/
|
37
41
|
export const fromNumber = /*#__PURE__*/constructor.either.bind(constructor);
|
38
42
|
/**
|
39
|
-
* Constructs
|
43
|
+
* Constructs a `CVInteger` from a number if possible. Throws otherwise
|
40
44
|
*
|
41
45
|
* @category Constructors
|
42
46
|
*/
|
43
47
|
export const fromNumberOrThrow = constructor;
|
44
48
|
/**
|
45
|
-
* Constructs
|
49
|
+
* Constructs a `CVInteger` from a `BigDecimal` without any checks
|
46
50
|
*
|
47
51
|
* @category Constructors
|
48
52
|
*/
|
49
53
|
export const unsafeFromBigDecimal = CVReal.unsafeFromBigDecimal;
|
50
54
|
/**
|
51
|
-
*
|
55
|
+
* Tries to construct a `CVInteger` from a `BigDecimal`. Returns a `Some` if the conversion can be
|
56
|
+
* performed, a `None` otherwise
|
52
57
|
*
|
53
58
|
* @category Constructors
|
54
59
|
*/
|
55
60
|
export const fromBigDecimalOption = /*#__PURE__*/flow(CVReal.fromBigDecimalOption, /*#__PURE__*/Option.flatMap(CVInt.fromNumberOption));
|
56
61
|
/**
|
57
|
-
*
|
62
|
+
* Tries to construct a `CVInteger` from a `BigDecimal`. Returns a `Right` if the conversion can be
|
63
|
+
* performed, a `Left` otherwise
|
58
64
|
*
|
59
65
|
* @category Constructors
|
60
66
|
*/
|
61
67
|
export const fromBigDecimal = /*#__PURE__*/flow(CVReal.fromBigDecimal, /*#__PURE__*/Either.flatMap(CVInt.fromNumber));
|
62
68
|
/**
|
63
|
-
* Constructs
|
69
|
+
* Constructs a `CVInteger` from a `BigDecimal` if possible. Throws otherwise
|
64
70
|
*
|
65
71
|
* @category Constructors
|
66
72
|
*/
|
67
73
|
export const fromBigDecimalOrThrow = /*#__PURE__*/flow(CVReal.fromBigDecimalOrThrow, CVInt.fromNumberOrThrow);
|
68
74
|
/**
|
69
|
-
* Constructs
|
75
|
+
* Constructs a `CVInteger` from a `BigInt` without any checks
|
70
76
|
*
|
71
77
|
* @category Constructors
|
72
78
|
*/
|
73
79
|
export const unsafeFromBigInt = CVReal.unsafeFromBigInt;
|
74
80
|
/**
|
75
|
-
*
|
81
|
+
* Tries to construct a `CVInteger` from a `BigInt`. Returns a `Some` if the conversion can be
|
82
|
+
* performed, a `None` otherwise
|
76
83
|
*
|
77
84
|
* @category Constructors
|
78
85
|
*/
|
79
86
|
export const fromBigIntOption = /*#__PURE__*/flow(CVReal.fromBigIntOption);
|
80
87
|
/**
|
81
|
-
*
|
88
|
+
* Tries to construct a `CVInteger` from a `BigInt`. Returns a `Right` if the conversion can be
|
89
|
+
* performed, a `Left` otherwise
|
82
90
|
*
|
83
91
|
* @category Constructors
|
84
92
|
*/
|
85
93
|
export const fromBigInt = /*#__PURE__*/flow(CVReal.fromBigInt, /*#__PURE__*/Either.flatMap(CVInt.fromNumber));
|
86
94
|
/**
|
87
|
-
* Constructs
|
95
|
+
* Constructs a `CVInteger` from a `BigInt` if possible. Throws otherwise
|
88
96
|
*
|
89
97
|
* @category Constructors
|
90
98
|
*/
|
91
99
|
export const fromBigIntOrThrow = /*#__PURE__*/flow(CVReal.fromBigIntOrThrow);
|
92
100
|
/**
|
93
|
-
* Constructs
|
101
|
+
* Constructs a `CVInteger` from a `CVReal` without any checks
|
94
102
|
*
|
95
103
|
* @category Constructors
|
96
104
|
*/
|
97
105
|
export const unsafeFromReal = Function.identity;
|
98
106
|
/**
|
99
|
-
*
|
107
|
+
* Tries to construct a `CVInteger` from a `CVReal`. Returns a `Some` if the conversion can be
|
108
|
+
* performed, a `None` otherwise
|
100
109
|
*
|
101
110
|
* @category Constructors
|
102
111
|
*/
|
103
112
|
export const fromRealOption = CVInt.fromNumberOption;
|
104
113
|
/**
|
105
|
-
*
|
114
|
+
* Tries to construct a `CVInteger` from a `CVReal`. Returns a `Right` if the conversion can be
|
115
|
+
* performed, a `Left` otherwise
|
106
116
|
*
|
107
117
|
* @category Constructors
|
108
118
|
*/
|
109
119
|
export const fromReal = CVInt.fromNumber;
|
110
120
|
/**
|
111
|
-
* Constructs
|
121
|
+
* Constructs a `CVInteger` from a `CVReal` if possible. Throws otherwise
|
112
122
|
*
|
113
123
|
* @category Constructors
|
114
124
|
*/
|
115
125
|
export const fromRealOrThrow = CVInt.fromNumberOrThrow;
|
116
126
|
/**
|
117
|
-
* A Schema that transforms a number into a CVInteger
|
127
|
+
* A `Schema` that transforms a number into a `CVInteger`
|
118
128
|
*
|
119
|
-
* @
|
129
|
+
* @ignore
|
120
130
|
*/
|
121
131
|
export const SchemaFromNumber = /*#__PURE__*/Schema.Number.pipe(/*#__PURE__*/Schema.fromBrand(constructor));
|
122
132
|
/**
|
123
|
-
* A Schema that represents a CVInteger
|
133
|
+
* A `Schema` that represents a `CVInteger`
|
124
134
|
*
|
125
|
-
* @
|
135
|
+
* @ignore
|
126
136
|
*/
|
127
137
|
export const SchemaFromSelf = /*#__PURE__*/Schema.typeSchema(SchemaFromNumber);
|
128
138
|
//# sourceMappingURL=Integer.js.map
|
package/esm/Integer.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Integer.js","names":["Brand","Either","flow","Function","Option","Schema","CVInt","CVReal","moduleTag","constructor","all","unsafeFromNumber","nominal","fromNumberOption","option","bind","fromNumber","either","fromNumberOrThrow","unsafeFromBigDecimal","fromBigDecimalOption","flatMap","fromBigDecimal","fromBigDecimalOrThrow","unsafeFromBigInt","fromBigIntOption","fromBigInt","fromBigIntOrThrow","unsafeFromReal","identity","fromRealOption","fromReal","fromRealOrThrow","SchemaFromNumber","Number","pipe","fromBrand","SchemaFromSelf","typeSchema"],"sources":["../../esm/Integer.ts"],"sourcesContent":[null],"mappings":"AAAA
|
1
|
+
{"version":3,"file":"Integer.js","names":["Brand","Either","flow","Function","Option","Schema","CVInt","CVReal","moduleTag","constructor","all","unsafeFromNumber","nominal","fromNumberOption","option","bind","fromNumber","either","fromNumberOrThrow","unsafeFromBigDecimal","fromBigDecimalOption","flatMap","fromBigDecimal","fromBigDecimalOrThrow","unsafeFromBigInt","fromBigIntOption","fromBigInt","fromBigIntOrThrow","unsafeFromReal","identity","fromRealOption","fromReal","fromRealOrThrow","SchemaFromNumber","Number","pipe","fromBrand","SchemaFromSelf","typeSchema"],"sources":["../../esm/Integer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AAQA,SAAqBA,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,MAAM,QAAQ,QAAQ;AAClF,OAAO,KAAKC,KAAK,MAAM,mBAAmB;AAC1C,OAAO,KAAKC,MAAM,MAAM,WAAW;AAEnC;;;;;AAKA,OAAO,MAAMC,SAAS,GAAG,iCAAiC;AAE1D;;;;;AAKA,OAAO,MAAMC,WAAW,gBAAGT,KAAK,CAACU,GAAG,CAACH,MAAM,CAACE,WAAW,EAAEH,KAAK,CAACG,WAAW,CAAC;AAS3E;;;;;AAKA,OAAO,MAAME,gBAAgB,gBAAGX,KAAK,CAACY,OAAO,EAAQ;AAErD;;;;;;AAMA,OAAO,MAAMC,gBAAgB,gBAGzBJ,WAAW,CAACK,MAAM,CAACC,IAAI,CAACN,WAAW,CAAC;AAExC;;;;;;AAMA,OAAO,MAAMO,UAAU,gBAGnBP,WAAW,CAACQ,MAAM,CAACF,IAAI,CAACN,WAAW,CAAC;AAExC;;;;;AAKA,OAAO,MAAMS,iBAAiB,GAAwCT,WAAW;AAEjF;;;;;AAKA,OAAO,MAAMU,oBAAoB,GAChCZ,MAAM,CAACY,oBAA6B;AAErC;;;;;;AAMA,OAAO,MAAMC,oBAAoB,gBAG7BlB,IAAI,CAACK,MAAM,CAACa,oBAAoB,eAAEhB,MAAM,CAACiB,OAAO,CAACf,KAAK,CAACO,gBAAgB,CAAC,CAAU;AAEtF;;;;;;AAMA,OAAO,MAAMS,cAAc,gBAGvBpB,IAAI,CAACK,MAAM,CAACe,cAAc,eAAErB,MAAM,CAACoB,OAAO,CAACf,KAAK,CAACU,UAAU,CAAC,CAAU;AAE1E;;;;;AAKA,OAAO,MAAMO,qBAAqB,gBAAuDrB,IAAI,CAC5FK,MAAM,CAACgB,qBAAqB,EAC5BjB,KAAK,CAACY,iBAAiB,CACd;AAEV;;;;;AAKA,OAAO,MAAMM,gBAAgB,GAC5BjB,MAAM,CAACiB,gBAAyB;AAEjC;;;;;;AAMA,OAAO,MAAMC,gBAAgB,gBAAuDvB,IAAI,CACvFK,MAAM,CAACkB,gBAAgB,CACd;AAEV;;;;;;AAMA,OAAO,MAAMC,UAAU,gBAGnBxB,IAAI,CAACK,MAAM,CAACmB,UAAU,eAAEzB,MAAM,CAACoB,OAAO,CAACf,KAAK,CAACU,UAAU,CAAC,CAAU;AAEtE;;;;;AAKA,OAAO,MAAMW,iBAAiB,gBAAwCzB,IAAI,CACzEK,MAAM,CAACoB,iBAAiB,CACf;AAEV;;;;;AAKA,OAAO,MAAMC,cAAc,GAA6CzB,QAAQ,CAAC0B,QAAiB;AAElG;;;;;;AAMA,OAAO,MAAMC,cAAc,GAGvBxB,KAAK,CAACO,gBAAyB;AAEnC;;;;;;AAMA,OAAO,MAAMkB,QAAQ,GAGjBzB,KAAK,CAACU,UAAmB;AAE7B;;;;;AAKA,OAAO,MAAMgB,eAAe,GAC3B1B,KAAK,CAACY,iBAA0B;AAEjC;;;;;AAKA,OAAO,MAAMe,gBAAgB,gBAAgC5B,MAAM,CAAC6B,MAAM,CAACC,IAAI,cAC9E9B,MAAM,CAAC+B,SAAS,CAAC3B,WAAW,CAAC,CAC7B;AAED;;;;;AAKA,OAAO,MAAM4B,cAAc,gBAAwBhC,MAAM,CAACiC,UAAU,CAACL,gBAAgB,CAAC","ignoreList":[]}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
|
-
* This module implements
|
3
|
-
*
|
2
|
+
* This module implements a `CVNumberBase10Format` which describes the possible options to
|
3
|
+
* format/parse a base-10 number or `BigDecimal` and implements the formatting/parsing algortithms
|
4
4
|
*/
|
5
5
|
import { MBigDecimal, MBigInt, MFunction, MInspectable, MMatch, MNumber, MPipeable, MPredicate, MRegExpString, MString, MStruct, MTypes } from '@parischap/effect-lib';
|
6
6
|
import { Array, BigDecimal, BigInt, Either, flow, Function, Number, Option, pipe, Predicate, String, Struct, Tuple } from 'effect';
|
@@ -15,7 +15,7 @@ import * as CVRoundingOption from './RoundingOption.js';
|
|
15
15
|
export const moduleTag = '@parischap/conversions/NumberBase10Format/';
|
16
16
|
const _TypeId = /*#__PURE__*/Symbol.for(moduleTag);
|
17
17
|
/**
|
18
|
-
*
|
18
|
+
* Type that represents the possible sign display options
|
19
19
|
*
|
20
20
|
* @category Models
|
21
21
|
*/
|
@@ -93,7 +93,7 @@ export var SignDisplay;
|
|
93
93
|
}) => isZero || sign === 1 ? '' : '-'), /*#__PURE__*/MMatch.whenIs(SignDisplay.Never, () => MFunction.constEmptyString), MMatch.exhaustive);
|
94
94
|
})(SignDisplay || (SignDisplay = {}));
|
95
95
|
/**
|
96
|
-
*
|
96
|
+
* Type that represents the possible scientific notation options
|
97
97
|
*
|
98
98
|
* @category Models
|
99
99
|
*/
|
@@ -132,7 +132,7 @@ export var ScientificNotation;
|
|
132
132
|
ScientificNotation[ScientificNotation["Engineering"] = 3] = "Engineering";
|
133
133
|
})(ScientificNotation || (ScientificNotation = {}));
|
134
134
|
/**
|
135
|
-
*
|
135
|
+
* ScientificNotation namespace
|
136
136
|
*
|
137
137
|
* @category Models
|
138
138
|
*/
|
@@ -244,7 +244,7 @@ export const roundingMode = /*#__PURE__*/Struct.get('roundingMode');
|
|
244
244
|
*/
|
245
245
|
export const signDisplay = /*#__PURE__*/Struct.get('signDisplay');
|
246
246
|
/**
|
247
|
-
* Returns a short description of `self
|
247
|
+
* Returns a short description of `self`, e.g. 'signed integer'
|
248
248
|
*
|
249
249
|
* @category Destructors
|
250
250
|
*/
|
@@ -297,40 +297,40 @@ const _toBigDecimalExtractor = (self, fillChar = '') => {
|
|
297
297
|
/**
|
298
298
|
* Returns a function that tries to parse, from the start of a string `text`, a number respecting
|
299
299
|
* the options represented by `self` and an optional `fillChar` parameter. If successful, that
|
300
|
-
* function returns a `
|
300
|
+
* function returns a `Some` containing `parsedText` (the part of `text` that could be analyzed as
|
301
301
|
* representing a number) and `value` (`parsedText` converted to a BigDecimal value). Otherwise, it
|
302
|
-
* returns a `
|
303
|
-
* '0', '+0' will yield the same result.
|
302
|
+
* returns a `None`. As `BigDecimal`'s provide no possibility to distinguish `-0n` and `0n`, parsing
|
303
|
+
* '-0', '0', '+0' will yield the same result.
|
304
304
|
*
|
305
305
|
* `fillChar` is a character that may be used as filler between the sign and the number (or at the
|
306
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
|
307
|
+
* triggered if it's not). You can use '0' as `fillChar` but you should not use any other digit
|
308
308
|
* because the value of the number to parse would depend on the number of removed `fillChar`'s.
|
309
309
|
*
|
310
310
|
* @category Parsing
|
311
311
|
*/
|
312
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
313
|
/**
|
314
|
-
* Same as toBigDecimalExtractor but the returned parser throws in case of
|
314
|
+
* Same as `toBigDecimalExtractor` but the returned parser throws in case of failure
|
315
315
|
*
|
316
316
|
* @category Parsing
|
317
317
|
*/
|
318
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
319
|
/**
|
320
|
-
* Same as `toBigDecimalExtractor` but returns a `
|
321
|
-
* Furthermore, this function will return
|
320
|
+
* Same as `toBigDecimalExtractor` but returns a `CVReal`. This 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
322
|
*
|
323
323
|
* @category Parsing
|
324
324
|
*/
|
325
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
326
|
/**
|
327
|
-
* Same as toRealExtractor but the returned parser throws in case of
|
327
|
+
* Same as `toRealExtractor` but the returned parser throws in case of failure
|
328
328
|
*
|
329
329
|
* @category Parsing
|
330
330
|
*/
|
331
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
332
|
/**
|
333
|
-
* Same as toBigDecimalExtractor but the whole of the input text must represent a number, not just
|
333
|
+
* Same as `toBigDecimalExtractor` but the whole of the input text must represent a number, not just
|
334
334
|
* its start
|
335
335
|
*
|
336
336
|
* @category Parsing
|
@@ -340,7 +340,7 @@ export const toBigDecimalParser = (self, fillChar) => {
|
|
340
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
341
|
};
|
342
342
|
/**
|
343
|
-
* Same as
|
343
|
+
* Same as `toBigDecimalParser` but the returned parser throws in case of failure
|
344
344
|
*
|
345
345
|
* @category Parsing
|
346
346
|
*/
|
@@ -356,16 +356,16 @@ export const toRealParser = (self, fillChar) => {
|
|
356
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
357
|
};
|
358
358
|
/**
|
359
|
-
* Same as toRealParser but the returned parser throws in case of
|
359
|
+
* Same as `toRealParser` but the returned parser throws in case of failure
|
360
360
|
*
|
361
361
|
* @category Parsing
|
362
362
|
*/
|
363
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
364
|
/**
|
365
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 `
|
367
|
-
* formatted number. Otherwise, it returns a `
|
368
|
-
* for better accuracy. There is a difference between number and BigDecimal (and bigint) regarding
|
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
369
|
* the sign of 0. In Javascript, Object.is(0,-0) is false whereas Object.is(0n,-0n) is true. So if
|
370
370
|
* the sign of zero is important to you, prefer passing a number to the function. `0` as a
|
371
371
|
* BigDecimal will always be interpreted as a positive `0` as we have no means of knowing if it is
|
@@ -413,8 +413,8 @@ export const toNumberFormatter = (self, fillChars = '') => {
|
|
413
413
|
};
|
414
414
|
};
|
415
415
|
/**
|
416
|
-
*
|
417
|
-
* `
|
416
|
+
* Returns a copy of `self` with `minimumFractionalDigits` and `maximumFractionalDigits` set to `n`.
|
417
|
+
* `n` must be a finite positive integer
|
418
418
|
*
|
419
419
|
* @category Modifiers
|
420
420
|
*/
|
@@ -423,8 +423,8 @@ export const withNDecimals = decimalNumber => flow(MStruct.append({
|
|
423
423
|
maximumFractionalDigits: decimalNumber
|
424
424
|
}), make);
|
425
425
|
/**
|
426
|
-
*
|
427
|
-
*
|
426
|
+
* Returns a copy of `self` with `maximumFractionalDigits` set to `n`. `n` must be a positive
|
427
|
+
* integer (`+Infinity` allowed). Pass 0 for an integer format
|
428
428
|
*
|
429
429
|
* @category Modifiers
|
430
430
|
*/
|
@@ -433,8 +433,8 @@ export const withMaxNDecimals = maxDecimalNumber => self => pipe(self, MStruct.a
|
|
433
433
|
maximumFractionalDigits: maxDecimalNumber
|
434
434
|
}), make);
|
435
435
|
/**
|
436
|
-
*
|
437
|
-
*
|
436
|
+
* Returns a copy of `self` with `minimumFractionalDigits` set to `n`. `n` must be a finite positive
|
437
|
+
* integer
|
438
438
|
*
|
439
439
|
* @category Modifiers
|
440
440
|
*/
|
@@ -443,7 +443,7 @@ export const withMinNDecimals = minDecimalNumber => self => pipe(self, MStruct.a
|
|
443
443
|
maximumFractionalDigits: Math.max(self.maximumFractionalDigits, minDecimalNumber)
|
444
444
|
}), make);
|
445
445
|
/**
|
446
|
-
*
|
446
|
+
* Returns a copy of `self` with `scientificNotation` set to `None`
|
447
447
|
*
|
448
448
|
* @category Modifiers
|
449
449
|
*/
|
@@ -451,7 +451,7 @@ export const withNoScientificNotation = /*#__PURE__*/flow(/*#__PURE__*/MStruct.a
|
|
451
451
|
scientificNotation: ScientificNotation.None
|
452
452
|
}), make);
|
453
453
|
/**
|
454
|
-
*
|
454
|
+
* Returns a copy of `self` with `scientificNotation` set to `Standard`
|
455
455
|
*
|
456
456
|
* @category Modifiers
|
457
457
|
*/
|
@@ -459,7 +459,7 @@ export const withStandardScientificNotation = /*#__PURE__*/flow(/*#__PURE__*/MSt
|
|
459
459
|
scientificNotation: ScientificNotation.Standard
|
460
460
|
}), make);
|
461
461
|
/**
|
462
|
-
*
|
462
|
+
* Returns a copy of `self` with `scientificNotation` set to `Normalized`
|
463
463
|
*
|
464
464
|
* @category Modifiers
|
465
465
|
*/
|
@@ -467,7 +467,7 @@ export const withNormalizedScientificNotation = /*#__PURE__*/flow(/*#__PURE__*/M
|
|
467
467
|
scientificNotation: ScientificNotation.Normalized
|
468
468
|
}), make);
|
469
469
|
/**
|
470
|
-
*
|
470
|
+
* Returns a copy of `self` with `scientificNotation` set to `Engineering`
|
471
471
|
*
|
472
472
|
* @category Modifiers
|
473
473
|
*/
|
@@ -475,7 +475,7 @@ export const withEngineeringScientificNotation = /*#__PURE__*/flow(/*#__PURE__*/
|
|
475
475
|
scientificNotation: ScientificNotation.Engineering
|
476
476
|
}), make);
|
477
477
|
/**
|
478
|
-
*
|
478
|
+
* Returns a copy of `self` with `thousandSeparator` set to `thousandSeparator`
|
479
479
|
*
|
480
480
|
* @category Modifiers
|
481
481
|
*/
|
@@ -483,13 +483,13 @@ export const withThousandSeparator = thousandSeparator => flow(MStruct.append({
|
|
483
483
|
thousandSeparator
|
484
484
|
}), make);
|
485
485
|
/**
|
486
|
-
*
|
486
|
+
* Returns a copy of `self` with `thousandSeparator` set to ''
|
487
487
|
*
|
488
488
|
* @category Modifiers
|
489
489
|
*/
|
490
490
|
export const withoutThousandSeparator = /*#__PURE__*/withThousandSeparator('');
|
491
491
|
/**
|
492
|
-
*
|
492
|
+
* Returns a copy of `self` with `fractionalSeparator` set to `fractionalSeparator`
|
493
493
|
*
|
494
494
|
* @category Modifiers
|
495
495
|
*/
|
@@ -497,7 +497,7 @@ export const withFractionalSeparator = fractionalSeparator => flow(MStruct.appen
|
|
497
497
|
fractionalSeparator: fractionalSeparator
|
498
498
|
}), make);
|
499
499
|
/**
|
500
|
-
*
|
500
|
+
* Returns a copy of `self` with `signDisplay` set to `Auto`
|
501
501
|
*
|
502
502
|
* @category Modifiers
|
503
503
|
*/
|
@@ -505,7 +505,7 @@ export const withSignDisplayForNegative = /*#__PURE__*/flow(/*#__PURE__*/MStruct
|
|
505
505
|
signDisplay: SignDisplay.Auto
|
506
506
|
}), make);
|
507
507
|
/**
|
508
|
-
*
|
508
|
+
* Returns a copy of `self` with `signDisplay` set to `Always`
|
509
509
|
*
|
510
510
|
* @category Modifiers
|
511
511
|
*/
|
@@ -513,7 +513,7 @@ export const withSignDisplay = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append({
|
|
513
513
|
signDisplay: SignDisplay.Always
|
514
514
|
}), make);
|
515
515
|
/**
|
516
|
-
*
|
516
|
+
* Returns a copy of `self` with `signDisplay` set to `ExceptZero`
|
517
517
|
*
|
518
518
|
* @category Modifiers
|
519
519
|
*/
|
@@ -521,7 +521,7 @@ export const withSignDisplayExceptZero = /*#__PURE__*/flow(/*#__PURE__*/MStruct.
|
|
521
521
|
signDisplay: SignDisplay.ExceptZero
|
522
522
|
}), make);
|
523
523
|
/**
|
524
|
-
*
|
524
|
+
* Returns a copy of `self` with `signDisplay` set to `Negative`
|
525
525
|
*
|
526
526
|
* @category Modifiers
|
527
527
|
*/
|
@@ -529,7 +529,7 @@ export const withSignDisplayForNegativeExceptZero = /*#__PURE__*/flow(/*#__PURE_
|
|
529
529
|
signDisplay: SignDisplay.Negative
|
530
530
|
}), make);
|
531
531
|
/**
|
532
|
-
*
|
532
|
+
* Returns a copy of `self` with `signDisplay` set to `Never`
|
533
533
|
*
|
534
534
|
* @category Modifiers
|
535
535
|
*/
|
@@ -537,7 +537,7 @@ export const withoutSignDisplay = /*#__PURE__*/flow(/*#__PURE__*/MStruct.append(
|
|
537
537
|
signDisplay: SignDisplay.Never
|
538
538
|
}), make);
|
539
539
|
/**
|
540
|
-
*
|
540
|
+
* Returns a copy of `self` with `roundingMode` set to `Ceil`
|
541
541
|
*
|
542
542
|
* @category Modifiers
|
543
543
|
*/
|
@@ -545,7 +545,7 @@ export const withCeilRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.appen
|
|
545
545
|
roundingMode: CVRoundingMode.Type.Ceil
|
546
546
|
}), make);
|
547
547
|
/**
|
548
|
-
*
|
548
|
+
* Returns a copy of `self` with `roundingMode` set to `Floor`
|
549
549
|
*
|
550
550
|
* @category Modifiers
|
551
551
|
*/
|
@@ -553,7 +553,7 @@ export const withFloorRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.appe
|
|
553
553
|
roundingMode: CVRoundingMode.Type.Floor
|
554
554
|
}), make);
|
555
555
|
/**
|
556
|
-
*
|
556
|
+
* Returns a copy of `self` with `roundingMode` set to `Expand`
|
557
557
|
*
|
558
558
|
* @category Modifiers
|
559
559
|
*/
|
@@ -561,7 +561,7 @@ export const withExpandRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.app
|
|
561
561
|
roundingMode: CVRoundingMode.Type.Expand
|
562
562
|
}), make);
|
563
563
|
/**
|
564
|
-
*
|
564
|
+
* Returns a copy of `self` with `roundingMode` set to `Trunc`
|
565
565
|
*
|
566
566
|
* @category Modifiers
|
567
567
|
*/
|
@@ -569,7 +569,7 @@ export const withTruncRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.appe
|
|
569
569
|
roundingMode: CVRoundingMode.Type.Trunc
|
570
570
|
}), make);
|
571
571
|
/**
|
572
|
-
*
|
572
|
+
* Returns a copy of `self` with `roundingMode` set to `HalfCeil`
|
573
573
|
*
|
574
574
|
* @category Modifiers
|
575
575
|
*/
|
@@ -577,7 +577,7 @@ export const withHalfCeilRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.a
|
|
577
577
|
roundingMode: CVRoundingMode.Type.HalfCeil
|
578
578
|
}), make);
|
579
579
|
/**
|
580
|
-
*
|
580
|
+
* Returns a copy of `self` with `roundingMode` set to `HalfFloor`
|
581
581
|
*
|
582
582
|
* @category Modifiers
|
583
583
|
*/
|
@@ -585,7 +585,7 @@ export const withHalfFloorRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.
|
|
585
585
|
roundingMode: CVRoundingMode.Type.HalfFloor
|
586
586
|
}), make);
|
587
587
|
/**
|
588
|
-
*
|
588
|
+
* Returns a copy of `self` with `roundingMode` set to `HalfExpand`
|
589
589
|
*
|
590
590
|
* @category Modifiers
|
591
591
|
*/
|
@@ -593,7 +593,7 @@ export const withHalfExpandRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct
|
|
593
593
|
roundingMode: CVRoundingMode.Type.HalfExpand
|
594
594
|
}), make);
|
595
595
|
/**
|
596
|
-
*
|
596
|
+
* Returns a copy of `self` with `roundingMode` set to `HalfTrunc`
|
597
597
|
*
|
598
598
|
* @category Modifiers
|
599
599
|
*/
|
@@ -601,7 +601,7 @@ export const withHalfTruncRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.
|
|
601
601
|
roundingMode: CVRoundingMode.Type.HalfTrunc
|
602
602
|
}), make);
|
603
603
|
/**
|
604
|
-
*
|
604
|
+
* Returns a copy of `self` with `roundingMode` set to `HalfEven`
|
605
605
|
*
|
606
606
|
* @category Modifiers
|
607
607
|
*/
|
@@ -609,7 +609,7 @@ export const withHalfEvenRoundingMode = /*#__PURE__*/flow(/*#__PURE__*/MStruct.a
|
|
609
609
|
roundingMode: CVRoundingMode.Type.HalfEven
|
610
610
|
}), make);
|
611
611
|
/**
|
612
|
-
*
|
612
|
+
* Returns a copy of `self` with `showNullIntegerPart` set to `false`
|
613
613
|
*
|
614
614
|
* @category Modifiers
|
615
615
|
*/
|
@@ -617,7 +617,7 @@ export const withNullIntegerPartNotShowing = /*#__PURE__*/flow(/*#__PURE__*/MStr
|
|
617
617
|
showNullIntegerPart: false
|
618
618
|
}), make);
|
619
619
|
/**
|
620
|
-
*
|
620
|
+
* Returns a copy of `self` with `showNullIntegerPart` set to `true`
|
621
621
|
*
|
622
622
|
* @category Modifiers
|
623
623
|
*/
|
@@ -625,7 +625,7 @@ export const withNullIntegerPartShowing = /*#__PURE__*/flow(/*#__PURE__*/MStruct
|
|
625
625
|
showNullIntegerPart: true
|
626
626
|
}), make);
|
627
627
|
/**
|
628
|
-
*
|
628
|
+
* `CVNumberBase10Format` instance that uses a comma as fractional separator, a space as thousand
|
629
629
|
* separator and shows at most three fractional digits. Used in countries like France,
|
630
630
|
* French-speaking Canada, French-speaking Belgium, Denmark, Finland, Sweden...
|
631
631
|
*
|
@@ -643,22 +643,22 @@ export const frenchStyleNumber = /*#__PURE__*/make({
|
|
643
643
|
signDisplay: SignDisplay.Negative
|
644
644
|
});
|
645
645
|
/**
|
646
|
-
*
|
647
|
-
* shows at most three fractional digits. Used in countries like France, French-speaking Canada,
|
646
|
+
* `CVNumberBase10Format` instance that uses a comma as fractional separator, no thousand separator
|
647
|
+
* and shows at most three fractional digits. Used in countries like France, French-speaking Canada,
|
648
648
|
* French-speaking Belgium, Denmark, Finland, Sweden...
|
649
649
|
*
|
650
650
|
* @category Instances
|
651
651
|
*/
|
652
652
|
export const frenchStyleUngroupedNumber = /*#__PURE__*/pipe(frenchStyleNumber, withoutThousandSeparator);
|
653
653
|
/**
|
654
|
-
* French-style integer
|
655
|
-
* Canada, French-speaking Belgium, Denmark, Finland, Sweden...
|
654
|
+
* French-style integer `CVNumberBase10Format` instance. Used in countries like France,
|
655
|
+
* French-speaking Canada, French-speaking Belgium, Denmark, Finland, Sweden...
|
656
656
|
*
|
657
657
|
* @category Instances
|
658
658
|
*/
|
659
659
|
export const frenchStyleInteger = /*#__PURE__*/pipe(frenchStyleNumber, /*#__PURE__*/withMaxNDecimals(0));
|
660
660
|
/**
|
661
|
-
*
|
661
|
+
* `CVNumberBase10Format` instance that uses a comma as fractional separator, a dot as thousand
|
662
662
|
* separator and shows at most three fractional digits. Used in countries like Dutch-speaking
|
663
663
|
* Belgium, the Netherlands, Germany, Italy, Norway, Croatia, Spain...
|
664
664
|
*
|
@@ -668,22 +668,22 @@ export const dutchStyleNumber = /*#__PURE__*/pipe(frenchStyleNumber, /*#__PURE__
|
|
668
668
|
thousandSeparator: '.'
|
669
669
|
}), make);
|
670
670
|
/**
|
671
|
-
*
|
672
|
-
* shows at most three fractional digits. Used in countries like Dutch-speaking Belgium, the
|
671
|
+
* `CVNumberBase10Format` instance that uses a comma as fractional separator, no thousand separator
|
672
|
+
* and shows at most three fractional digits. Used in countries like Dutch-speaking Belgium, the
|
673
673
|
* Netherlands, Germany, Italy, Norway, Croatia, Spain...
|
674
674
|
*
|
675
675
|
* @category Instances
|
676
676
|
*/
|
677
677
|
export const dutchStyleUngroupedNumber = /*#__PURE__*/pipe(dutchStyleNumber, withoutThousandSeparator);
|
678
678
|
/**
|
679
|
-
* Dutch-style integer
|
680
|
-
* the Netherlands, Germany, Italy, Norway, Croatia, Spain...
|
679
|
+
* Dutch-style integer `CVNumberBase10Format` instance. Used in countries like Dutch-speaking
|
680
|
+
* Belgium, the Netherlands, Germany, Italy, Norway, Croatia, Spain...
|
681
681
|
*
|
682
682
|
* @category Instances
|
683
683
|
*/
|
684
684
|
export const dutchStyleInteger = /*#__PURE__*/pipe(dutchStyleNumber, /*#__PURE__*/withMaxNDecimals(0));
|
685
685
|
/**
|
686
|
-
*
|
686
|
+
* `CVNumberBase10Format` instance that uses a dot as fractional separator, a comma as thousand
|
687
687
|
* separator and shows at most three fractional digits. Used in countries like the UK, the US,
|
688
688
|
* English-speaking Canada, Australia, Thaïland, Bosnia...
|
689
689
|
*
|
@@ -694,22 +694,22 @@ export const ukStyleNumber = /*#__PURE__*/pipe(frenchStyleNumber, /*#__PURE__*/M
|
|
694
694
|
thousandSeparator: ','
|
695
695
|
}), make);
|
696
696
|
/**
|
697
|
-
*
|
698
|
-
* shows at most three fractional digits. Used in countries like the UK, the US,
|
699
|
-
* Canada, Australia, Thaïland, Bosnia...
|
697
|
+
* `CVNumberBase10Format` instance that uses a dot as fractional separator, no thousand separator
|
698
|
+
* and shows at most three fractional digits. Used in countries like the UK, the US,
|
699
|
+
* English-speaking Canada, Australia, Thaïland, Bosnia...
|
700
700
|
*
|
701
701
|
* @category Instances
|
702
702
|
*/
|
703
703
|
export const ukStyleUngroupedNumber = /*#__PURE__*/pipe(ukStyleNumber, withoutThousandSeparator);
|
704
704
|
/**
|
705
|
-
* Uk-style integer
|
705
|
+
* Uk-style integer `CVNumberBase10Format` instance. Used in countries like the UK, the US,
|
706
706
|
* English-speaking Canada, Australia, Thaïland, Bosnia...
|
707
707
|
*
|
708
708
|
* @category Instances
|
709
709
|
*/
|
710
710
|
export const ukStyleInteger = /*#__PURE__*/pipe(ukStyleNumber, /*#__PURE__*/withMaxNDecimals(0));
|
711
711
|
/**
|
712
|
-
* Integer
|
712
|
+
* Integer `CVNumberBase10Format` instance with no thousand separator
|
713
713
|
*
|
714
714
|
* @category Instances
|
715
715
|
*/
|