@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,120 @@
|
|
1
|
+
/**
|
2
|
+
* This module allows you to round numbers and BigDecimal's according to diverse RoundingMode's with
|
3
|
+
* a given precision
|
4
|
+
*/
|
5
|
+
import { MBigDecimal, MBigInt, MInspectable, MNumber, MPipeable, MTypes } from '@parischap/effect-lib';
|
6
|
+
import { BigDecimal, Equal, Hash, pipe, Predicate, Struct } from 'effect';
|
7
|
+
import * as CVRoundingMode from './RoundingMode.js';
|
8
|
+
/**
|
9
|
+
* Module tag
|
10
|
+
*
|
11
|
+
* @category Module markers
|
12
|
+
*/
|
13
|
+
export const moduleTag = '@parischap/conversions/RoundingOption/';
|
14
|
+
const _TypeId = /*#__PURE__*/Symbol.for(moduleTag);
|
15
|
+
const _bigDecimal10 = /*#__PURE__*/BigDecimal.make(10n, 0);
|
16
|
+
/**
|
17
|
+
* Type guard
|
18
|
+
*
|
19
|
+
* @category Guards
|
20
|
+
*/
|
21
|
+
export const has = u => Predicate.hasProperty(u, _TypeId);
|
22
|
+
/**
|
23
|
+
* Equivalence
|
24
|
+
*
|
25
|
+
* @category Equivalences
|
26
|
+
*/
|
27
|
+
export const equivalence = (self, that) => self.precision === that.precision && self.roundingMode === that.roundingMode;
|
28
|
+
/** Prototype */
|
29
|
+
const proto = {
|
30
|
+
[_TypeId]: _TypeId,
|
31
|
+
[Equal.symbol](that) {
|
32
|
+
return has(that) && equivalence(this, that);
|
33
|
+
},
|
34
|
+
[Hash.symbol]() {
|
35
|
+
return pipe(this.precision, Hash.hash, Hash.combine(Hash.hash(this.roundingMode)), Hash.cached(this));
|
36
|
+
},
|
37
|
+
[MInspectable.IdSymbol]() {
|
38
|
+
return `${CVRoundingMode.toName(this.roundingMode)}RounderWith${this.precision}Precision`;
|
39
|
+
},
|
40
|
+
... /*#__PURE__*/MInspectable.BaseProto(moduleTag),
|
41
|
+
...MPipeable.BaseProto
|
42
|
+
};
|
43
|
+
/** Constructor */
|
44
|
+
const _make = params => MTypes.objectFromDataAndProto(proto, params);
|
45
|
+
/**
|
46
|
+
* Constructor
|
47
|
+
*
|
48
|
+
* @category Constructors
|
49
|
+
*/
|
50
|
+
export const make = ({
|
51
|
+
precision = 0,
|
52
|
+
roundingMode = CVRoundingMode.Type.HalfExpand
|
53
|
+
} = {}) => _make({
|
54
|
+
precision,
|
55
|
+
roundingMode
|
56
|
+
});
|
57
|
+
/**
|
58
|
+
* RoundingOption instance that uses the HalfExpand Rounding mode and precision=2. Can be used in
|
59
|
+
* accounting apps of most countries.
|
60
|
+
*
|
61
|
+
* @category Instances
|
62
|
+
*/
|
63
|
+
export const halfExpand2 = /*#__PURE__*/make({
|
64
|
+
precision: 2,
|
65
|
+
roundingMode: CVRoundingMode.Type.HalfExpand
|
66
|
+
});
|
67
|
+
/**
|
68
|
+
* Returns the `precision` property of `self`
|
69
|
+
*
|
70
|
+
* @category Destructors
|
71
|
+
*/
|
72
|
+
export const precision = /*#__PURE__*/Struct.get('precision');
|
73
|
+
/**
|
74
|
+
* Returns the `roundingMode` property of `self`
|
75
|
+
*
|
76
|
+
* @category Destructors
|
77
|
+
*/
|
78
|
+
export const roundingMode = /*#__PURE__*/Struct.get('roundingMode');
|
79
|
+
/**
|
80
|
+
* Builds a number Rounder implementing `self`, i.e a function that rounds a number as specified by
|
81
|
+
* `self`
|
82
|
+
*
|
83
|
+
* @category Destructors
|
84
|
+
*/
|
85
|
+
export const toNumberRounder = self => {
|
86
|
+
const shiftMultiplicand = pipe(1, MNumber.shift(self.precision));
|
87
|
+
const unshiftMultiplicand = 1.0 / shiftMultiplicand;
|
88
|
+
const correcter = CVRoundingMode.toCorrecter(self.roundingMode);
|
89
|
+
return n => {
|
90
|
+
const shiftedSelf = shiftMultiplicand * n;
|
91
|
+
const truncatedShiftedSelf = Math.trunc(shiftedSelf);
|
92
|
+
const firstFollowingDigit = Math.trunc((shiftedSelf - truncatedShiftedSelf) * 10);
|
93
|
+
return unshiftMultiplicand * (truncatedShiftedSelf + correcter({
|
94
|
+
firstFollowingDigit,
|
95
|
+
isEven: truncatedShiftedSelf % 2 == 0
|
96
|
+
}));
|
97
|
+
};
|
98
|
+
};
|
99
|
+
/**
|
100
|
+
* Builds a BigDecimal Rounder implementing `self`, i.e a function that rounds a BigDecimal as
|
101
|
+
* specified by `self`
|
102
|
+
*
|
103
|
+
* @category Destructors
|
104
|
+
*/
|
105
|
+
export const toBigDecimalRounder = self => {
|
106
|
+
const shiftValue = BigDecimal.make(1n, -self.precision);
|
107
|
+
const shift = BigDecimal.multiply(shiftValue);
|
108
|
+
const unshift = BigDecimal.unsafeDivide(shiftValue);
|
109
|
+
const correcter = CVRoundingMode.toCorrecter(self.roundingMode);
|
110
|
+
return n => {
|
111
|
+
const shiftedSelf = shift(n);
|
112
|
+
const truncatedShiftedSelf = pipe(shiftedSelf, MBigDecimal.trunc());
|
113
|
+
const firstFollowingDigit = pipe(shiftedSelf, BigDecimal.subtract(truncatedShiftedSelf), BigDecimal.multiply(_bigDecimal10), MBigDecimal.trunc(), BigDecimal.unsafeToNumber);
|
114
|
+
return pipe(truncatedShiftedSelf, BigDecimal.sum(pipe({
|
115
|
+
firstFollowingDigit,
|
116
|
+
isEven: MBigInt.isEven(truncatedShiftedSelf.value)
|
117
|
+
}, correcter, BigDecimal.unsafeFromNumber)), unshift);
|
118
|
+
};
|
119
|
+
};
|
120
|
+
//# sourceMappingURL=RoundingOption.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"RoundingOption.js","names":["MBigDecimal","MBigInt","MInspectable","MNumber","MPipeable","MTypes","BigDecimal","Equal","Hash","pipe","Predicate","Struct","CVRoundingMode","moduleTag","_TypeId","Symbol","for","_bigDecimal10","make","has","u","hasProperty","equivalence","self","that","precision","roundingMode","proto","symbol","hash","combine","cached","IdSymbol","toName","BaseProto","_make","params","objectFromDataAndProto","Type","HalfExpand","halfExpand2","get","toNumberRounder","shiftMultiplicand","shift","unshiftMultiplicand","correcter","toCorrecter","n","shiftedSelf","truncatedShiftedSelf","Math","trunc","firstFollowingDigit","isEven","toBigDecimalRounder","shiftValue","multiply","unshift","unsafeDivide","subtract","unsafeToNumber","sum","value","unsafeFromNumber"],"sources":["../../esm/RoundingOption.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;AAKA,SACCA,WAAW,EACXC,OAAO,EACPC,YAAY,EACZC,OAAO,EACPC,SAAS,EACTC,MAAM,QACA,uBAAuB;AAC9B,SAASC,UAAU,EAAEC,KAAK,EAAeC,IAAI,EAAEC,IAAI,EAAYC,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AAChG,OAAO,KAAKC,cAAc,MAAM,mBAAmB;AAEnD;;;;;AAKA,OAAO,MAAMC,SAAS,GAAG,wCAAwC;AACjE,MAAMC,OAAO,gBAAkBC,MAAM,CAACC,GAAG,CAACH,SAAS,CAAY;AAG/D,MAAMI,aAAa,gBAAGX,UAAU,CAACY,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;AAkB7C;;;;;AAKA,OAAO,MAAMC,GAAG,GAAIC,CAAU,IAAgBV,SAAS,CAACW,WAAW,CAACD,CAAC,EAAEN,OAAO,CAAC;AAE/E;;;;;AAKA,OAAO,MAAMQ,WAAW,GAAkCA,CAACC,IAAI,EAAEC,IAAI,KACpED,IAAI,CAACE,SAAS,KAAKD,IAAI,CAACC,SAAS,IAAIF,IAAI,CAACG,YAAY,KAAKF,IAAI,CAACE,YAAY;AAE7E;AAEA,MAAMC,KAAK,GAAuB;EACjC,CAACb,OAAO,GAAGA,OAAO;EAClB,CAACP,KAAK,CAACqB,MAAM,EAAcJ,IAAa;IACvC,OAAOL,GAAG,CAACK,IAAI,CAAC,IAAIF,WAAW,CAAC,IAAI,EAAEE,IAAI,CAAC;EAC5C,CAAC;EACD,CAAChB,IAAI,CAACoB,MAAM,IAAC;IACZ,OAAOnB,IAAI,CACV,IAAI,CAACgB,SAAS,EACdjB,IAAI,CAACqB,IAAI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zB;IACD,OAAOpD,IAAI,CACVyC,oBAAoB,EACpB5C,UAAU,CAACwD,GAAG,CACbrD,IAAI,CACH;MAAE4C,mBAAmB;MAAEC,MAAM,EAAErD,OAAO,CAACqD,MAAM,CAACJ,oBAAoB,CAACa,KAAK;IAAC,CAAE,EAC3EjB,SAAS,EACTxC,UAAU,CAAC0D,gBAAgB,CAC3B,CACD,EACDN,OAAO,CACP;EACF,CAAC;AACF,CAAC","ignoreList":[]}
|
package/esm/Schema.js
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
/**
|
2
|
+
* An extension to the Effect Schema module that adds Schema instances for data conversion like
|
3
|
+
* number and date formatting and parsing
|
4
|
+
*/
|
5
|
+
import { MMatch, MTuple } from '@parischap/effect-lib';
|
6
|
+
import { Array, Either, flow, Option, ParseResult, pipe, Record, Schema } from 'effect';
|
7
|
+
import * as CVDateTime from './DateTime.js';
|
8
|
+
import * as CVDateTimeFormat from './DateTimeFormat.js';
|
9
|
+
import * as CVEmail from './Email.js';
|
10
|
+
import * as CVInteger from './Integer.js';
|
11
|
+
import * as CVNumberBase10Format from './NumberBase10Format.js';
|
12
|
+
import * as CVPositiveInteger from './PositiveInteger.js';
|
13
|
+
import * as CVPositiveReal from './PositiveReal.js';
|
14
|
+
import * as CVReal from './Real.js';
|
15
|
+
import * as CVSemVer from './SemVer.js';
|
16
|
+
import * as CVTemplate from './Template.js';
|
17
|
+
import * as CVTemplatePart from './TemplatePart.js';
|
18
|
+
import * as CVTemplatePlaceholder from './TemplatePlaceholder.js';
|
19
|
+
/**
|
20
|
+
* A Schema that transforms a string into a CVBrand.Email.Type
|
21
|
+
*
|
22
|
+
* @category Schema transformations
|
23
|
+
*/
|
24
|
+
export const Email = CVEmail.SchemaFromString;
|
25
|
+
/**
|
26
|
+
* A Schema that represents a CVBrand.Email.Type
|
27
|
+
*
|
28
|
+
* @category Schema instances
|
29
|
+
*/
|
30
|
+
export const EmailFromSelf = CVEmail.SchemaFromSelf;
|
31
|
+
/**
|
32
|
+
* A Schema that transforms a string into an CVBrand.SemVer.Type
|
33
|
+
*
|
34
|
+
* @category Schema transformations
|
35
|
+
*/
|
36
|
+
export const SemVer = CVSemVer.SchemaFromString;
|
37
|
+
/**
|
38
|
+
* A Schema that represents a CVBrand.SemVer.Type
|
39
|
+
*
|
40
|
+
* @category Schema instances
|
41
|
+
*/
|
42
|
+
export const SemVerFromSelf = CVSemVer.SchemaFromSelf;
|
43
|
+
/**
|
44
|
+
* A Schema that transforms a number into an CVReal.Type
|
45
|
+
*
|
46
|
+
* @category Schema transformations
|
47
|
+
*/
|
48
|
+
export const RealFromNumber = CVReal.SchemaFromNumber;
|
49
|
+
/**
|
50
|
+
* A Schema that represents a CVReal.Type
|
51
|
+
*
|
52
|
+
* @category Schema instances
|
53
|
+
*/
|
54
|
+
export const RealFromSelf = CVReal.SchemaFromSelf;
|
55
|
+
/**
|
56
|
+
* A Schema that transforms a string into a Real according to the CVNumberBase10Format `format`.
|
57
|
+
* Read documentation of CVNumberBase10Format.toRealParser and
|
58
|
+
* CVNumberBase10Format.toNumberFormatter for more details
|
59
|
+
*
|
60
|
+
* @category Schema transformations
|
61
|
+
*/
|
62
|
+
export const Real = format => {
|
63
|
+
const parser = CVNumberBase10Format.toRealParser(format);
|
64
|
+
const formatter = CVNumberBase10Format.toNumberFormatter(format);
|
65
|
+
return Schema.transformOrFail(Schema.String, RealFromSelf, {
|
66
|
+
strict: true,
|
67
|
+
decode: (input, _options, ast) => pipe(input, parser, Either.fromOption(() => new ParseResult.Type(ast, input, 'Failed to convert string to a(n) ' + CVNumberBase10Format.toDescription(format)))),
|
68
|
+
encode: flow(formatter, ParseResult.succeed)
|
69
|
+
});
|
70
|
+
};
|
71
|
+
/**
|
72
|
+
* A Schema that transforms a number into a CVInteger.Type
|
73
|
+
*
|
74
|
+
* @category Schema transformations
|
75
|
+
*/
|
76
|
+
export const IntegerFromNumber = CVInteger.SchemaFromNumber;
|
77
|
+
/**
|
78
|
+
* A Schema that represents a CVInteger.Type
|
79
|
+
*
|
80
|
+
* @category Schema instances
|
81
|
+
*/
|
82
|
+
export const IntegerFromSelf = CVInteger.SchemaFromSelf;
|
83
|
+
/**
|
84
|
+
* A Schema that transforms a number into a CVPositiveInteger.Type
|
85
|
+
*
|
86
|
+
* @category Schema transformations
|
87
|
+
*/
|
88
|
+
export const PositiveIntegerFromNumber = CVPositiveInteger.SchemaFromNumber;
|
89
|
+
/**
|
90
|
+
* A Schema that represents a CVPositiveInteger.Type
|
91
|
+
*
|
92
|
+
* @category Schema instances
|
93
|
+
*/
|
94
|
+
export const PositiveIntegerFromSelf = CVPositiveInteger.SchemaFromSelf;
|
95
|
+
/**
|
96
|
+
* A Schema that transforms a number into a CVPositiveReal.Type
|
97
|
+
*
|
98
|
+
* @category Schema transformations
|
99
|
+
*/
|
100
|
+
export const PositiveRealFromNumber = CVPositiveReal.SchemaFromNumber;
|
101
|
+
/**
|
102
|
+
* A Schema that represents a CVPositiveReal.Type
|
103
|
+
*
|
104
|
+
* @category Schema instances
|
105
|
+
*/
|
106
|
+
export const PositiveRealFromSelf = CVPositiveReal.SchemaFromSelf;
|
107
|
+
const BigDecimalFromString = format => {
|
108
|
+
const parser = CVNumberBase10Format.toBigDecimalParser(format);
|
109
|
+
const formatter = CVNumberBase10Format.toNumberFormatter(format);
|
110
|
+
return Schema.transformOrFail(Schema.String, Schema.BigDecimalFromSelf, {
|
111
|
+
strict: true,
|
112
|
+
decode: (input, _options, ast) => pipe(input, parser, Option.map(ParseResult.succeed), Option.getOrElse(() => ParseResult.fail(new ParseResult.Type(ast, input, 'Failed to convert string to a(n) ' + CVNumberBase10Format.toDescription(format))))),
|
113
|
+
encode: flow(formatter, ParseResult.succeed)
|
114
|
+
});
|
115
|
+
};
|
116
|
+
export {
|
117
|
+
/**
|
118
|
+
* A Schema that transforms a string into a BigDecimal according to the CVNumberBase10Format
|
119
|
+
* `format`. Read documentation of CVNumberBase10Format.toBigDecimalParser and
|
120
|
+
* CVNumberBase10Format.toNumberFormatter for more details
|
121
|
+
*
|
122
|
+
* @category Schema transformations
|
123
|
+
*/
|
124
|
+
BigDecimalFromString as BigDecimal };
|
125
|
+
/**
|
126
|
+
* A Schema that represents a CVDateTime
|
127
|
+
*
|
128
|
+
* @category Schema instances
|
129
|
+
*/
|
130
|
+
export const DateTimeFromSelf = /*#__PURE__*/Schema.declare(input => CVDateTime.has(input));
|
131
|
+
/**
|
132
|
+
* A Schema that transforms a CVDateTime into a Date. The CVDateTime object is created with the
|
133
|
+
* default timeZoneOffset of the machine this code is running on
|
134
|
+
*
|
135
|
+
* @category Schema instances
|
136
|
+
*/
|
137
|
+
export const DateFromDateTime = /*#__PURE__*/Schema.transform(DateTimeFromSelf, Schema.DateFromSelf, {
|
138
|
+
strict: true,
|
139
|
+
decode: CVDateTime.toDate,
|
140
|
+
encode: CVDateTime.fromDate
|
141
|
+
});
|
142
|
+
/**
|
143
|
+
* A Schema that transforms a CVDateTime into an Effect DateTime.Zoned. Both objects share the same
|
144
|
+
* time zone offset.
|
145
|
+
*
|
146
|
+
* @category Schema instances
|
147
|
+
*/
|
148
|
+
export const DateTimeZonedFromDateTime = /*#__PURE__*/Schema.transform(DateTimeFromSelf, Schema.DateTimeZonedFromSelf, {
|
149
|
+
strict: true,
|
150
|
+
decode: CVDateTime.toEffectDateTime,
|
151
|
+
encode: CVDateTime.fromEffectDateTime
|
152
|
+
});
|
153
|
+
const DateTimeFromString = format => {
|
154
|
+
const parser = CVDateTimeFormat.toParser(format);
|
155
|
+
const formatter = CVDateTimeFormat.toFormatter(format);
|
156
|
+
return Schema.transformOrFail(Schema.String, DateTimeFromSelf, {
|
157
|
+
strict: true,
|
158
|
+
decode: (input, _options, ast) => pipe(input, parser, Either.mapLeft(inputError => new ParseResult.Type(ast, input, inputError.message))),
|
159
|
+
encode: (input, _options, ast) => pipe(input, formatter, Either.mapLeft(inputError => new ParseResult.Type(ast, input, inputError.message)))
|
160
|
+
});
|
161
|
+
};
|
162
|
+
export {
|
163
|
+
/**
|
164
|
+
* A Schema that transforms a string into a CVDateTime according to the CVDateTimeFormat `format`.
|
165
|
+
* Read documentation of CVDateTimeFormat.toParser and CVDateTimeFormat.toFormatter for more
|
166
|
+
* details
|
167
|
+
*
|
168
|
+
* @category Schema transformations
|
169
|
+
*/
|
170
|
+
DateTimeFromString as DateTime };
|
171
|
+
/**
|
172
|
+
* A Schema that transforms a string into a Date according to the CVDateTimeFormat `format`. Read
|
173
|
+
* documentation of CVDateTimeFormat.toParser and CVDateTimeFormat.toFormatter for more details
|
174
|
+
*
|
175
|
+
* @category Schema transformations
|
176
|
+
*/
|
177
|
+
export const Date = format => Schema.compose(DateTimeFromString(format), DateFromDateTime);
|
178
|
+
/**
|
179
|
+
* A Schema that transforms a string into a Date according to the CVDateTimeFormat `format`. Read
|
180
|
+
* documentation of CVDateTimeFormat.toParser and CVDateTimeFormat.toFormatter for more details
|
181
|
+
*
|
182
|
+
* @category Schema transformations
|
183
|
+
*/
|
184
|
+
export const DateTimeZoned = format => Schema.compose(DateTimeFromString(format), DateTimeZonedFromDateTime);
|
185
|
+
/**
|
186
|
+
* A Schema that transforms a string into an object according to a CVTemplate (see Template.ts)
|
187
|
+
*
|
188
|
+
* @category Schema transformations
|
189
|
+
*/
|
190
|
+
export const Template = template => {
|
191
|
+
const parser = CVTemplate.toParser(template);
|
192
|
+
const formatter = CVTemplate.toFormatter(template);
|
193
|
+
const schemaOutput = pipe(template.templateParts, Array.filterMap(flow(MMatch.make, MMatch.when(CVTemplatePart.isSeparator, () => Option.none()), MMatch.when(CVTemplatePart.isPlaceholder, flow(MTuple.makeBothBy({
|
194
|
+
toFirst: CVTemplatePlaceholder.name,
|
195
|
+
toSecond: CVTemplatePlaceholder.schemaInstance
|
196
|
+
}), Option.some)), MMatch.exhaustive)), Record.fromEntries, Schema.Struct);
|
197
|
+
return Schema.transformOrFail(Schema.String, schemaOutput, {
|
198
|
+
strict: true,
|
199
|
+
decode: (input, _options, ast) => pipe(input, parser, Either.mapLeft(inputError => new ParseResult.Type(ast, input, inputError.message))),
|
200
|
+
encode: (input, _options, ast) => pipe(input, formatter, Either.mapLeft(inputError => new ParseResult.Type(ast, input, inputError.message)))
|
201
|
+
});
|
202
|
+
};
|
203
|
+
//# sourceMappingURL=Schema.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Schema.js","names":["MMatch","MTuple","Array","Either","flow","Option","ParseResult","pipe","Record","Schema","CVDateTime","CVDateTimeFormat","CVEmail","CVInteger","CVNumberBase10Format","CVPositiveInteger","CVPositiveReal","CVReal","CVSemVer","CVTemplate","CVTemplatePart","CVTemplatePlaceholder","Email","SchemaFromString","EmailFromSelf","SchemaFromSelf","SemVer","SemVerFromSelf","RealFromNumber","SchemaFromNumber","RealFromSelf","Real","format","parser","toRealParser","formatter","toNumberFormatter","transformOrFail","String","strict","decode","input","_options","ast","fromOption","Type","toDescription","encode","succeed","IntegerFromNumber","IntegerFromSelf","PositiveIntegerFromNumber","PositiveIntegerFromSelf","PositiveRealFromNumber","PositiveRealFromSelf","BigDecimalFromString","toBigDecimalParser","BigDecimalFromSelf","map","getOrElse","fail","BigDecimal","DateTimeFromSelf","declare","has","DateFromDateTime","transform","DateFromSelf","toDate","fromDate","DateTimeZonedFromDateTime","DateTimeZonedFromSelf","toEffectDateTime","fromEffectDateTime","DateTimeFromString","toParser","toFormatter","mapLeft","inputError","message","DateTime","Date","compose","DateTimeZoned","Template","template","schemaOutput","templateParts","filterMap","make","when","isSeparator","none","isPlaceholder","makeBothBy","toFirst","name","toSecond","schemaInstance","some","exhaustive","fromEntries","Struct"],"sources":["../../esm/Schema.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;AAKA,SAASA,MAAM,EAAEC,MAAM,QAAgB,uBAAuB;AAC9D,SACCC,KAAK,EAGLC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,WAAW,EACXC,IAAI,EACJC,MAAM,EACNC,MAAM,QACA,QAAQ;AACf,OAAO,KAAKC,UAAU,MA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F,IAAI,CACVtE,cAAc,CAACyE,aAAa,EAC5BzF,IAAI,CACHH,MAAM,CAAC6F,UAAU,CAAC;IACjBC,OAAO,EAAE1E,qBAAqB,CAAC2E,IAAI;IACnCC,QAAQ,EAAE5E,qBAAqB,CAAC6E;GAChC,CAAC,EACF7F,MAAM,CAAC8F,IAAI,CACX,CACD,EACDnG,MAAM,CAACoG,UAAU,CACjB,CACD,EACD5F,MAAM,CAAC6F,WAAW,EAClB5F,MAAM,CAAC6F,MAAM,CACb;EAED,OAAO7F,MAAM,CAAC4B,eAAe,CAAC5B,MAAM,CAAC6B,MAAM,EAAEgD,YAAY,EAAE;IAC1D/C,MAAM,EAAE,IAAI;IACZC,MAAM,EAAEA,CAACC,KAAK,EAAEC,QAAQ,EAAEC,GAAG,KAC5BpC,IAAI,CACHkC,KAAK,EACLR,MAAM,EACN9B,MAAM,CAAC0E,OAAO,CAAEC,UAAU,IAAK,IAAIxE,WAAW,CAACuC,IAAI,CAACF,GAAG,EAAEF,KAAK,EAAEqC,UAAU,CAACC,OAAO,CAAC,CAAC,CAC3E;IACXhC,MAAM,EAAEA,CAACN,KAAK,EAAEC,QAAQ,EAAEC,GAAG,KAC5BpC,IAAI,CACHkC,KAAc,EACdN,SAAS,EACThC,MAAM,CAAC0E,OAAO,CAAEC,UAAU,IAAK,IAAIxE,WAAW,CAACuC,IAAI,CAACF,GAAG,EAAEF,KAAK,EAAEqC,UAAU,CAACC,OAAO,CAAC,CAAC;GAEtF,CAAU;AACZ,CAAC","ignoreList":[]}
|
package/esm/SemVer.js
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
/** A module that implements a SemVer brand */
|
2
|
+
import { MString } from '@parischap/effect-lib';
|
3
|
+
import { Brand, Schema } from 'effect';
|
4
|
+
/**
|
5
|
+
* Module tag
|
6
|
+
*
|
7
|
+
* @category Module markers
|
8
|
+
*/
|
9
|
+
export const moduleTag = '@parischap/conversions/SemVer/';
|
10
|
+
/**
|
11
|
+
* Module TypeId
|
12
|
+
*
|
13
|
+
* @category Module markers
|
14
|
+
*/
|
15
|
+
export const TypeId = /*#__PURE__*/Symbol.for(moduleTag);
|
16
|
+
/**
|
17
|
+
* Constructs a SemVer without any verifications
|
18
|
+
*
|
19
|
+
* @category Constructors
|
20
|
+
*/
|
21
|
+
export const unsafeFromString = /*#__PURE__*/Brand.nominal();
|
22
|
+
/**
|
23
|
+
* Constructs a SemVer from a string. Throws an error if the provided string does not represent a
|
24
|
+
* SemVer
|
25
|
+
*
|
26
|
+
* @category Constructors
|
27
|
+
*/
|
28
|
+
export const constructor = /*#__PURE__*/Brand.refined(MString.isSemVer, s => Brand.error(`'${s}' does not represent a semver`));
|
29
|
+
/**
|
30
|
+
* Constructs an Option of a SemVer from a string.
|
31
|
+
*
|
32
|
+
* @category Constructors
|
33
|
+
*/
|
34
|
+
export const fromStringOption = /*#__PURE__*/constructor.option.bind(constructor);
|
35
|
+
/**
|
36
|
+
* Constructs an Either of a SemVer from a string.
|
37
|
+
*
|
38
|
+
* @category Constructors
|
39
|
+
*/
|
40
|
+
export const fromString = /*#__PURE__*/constructor.either.bind(constructor);
|
41
|
+
/**
|
42
|
+
* Constructs a SemVer or throws.
|
43
|
+
*
|
44
|
+
* @category Constructors
|
45
|
+
*/
|
46
|
+
export const fromStringOrThrow = constructor;
|
47
|
+
/**
|
48
|
+
* Checks if a string is a semver
|
49
|
+
*
|
50
|
+
* @category Refinement
|
51
|
+
*/
|
52
|
+
export const has = input => MString.isSemVer(input);
|
53
|
+
/**
|
54
|
+
* A Schema that transforms a string into an CVBrand.SemVer.Type
|
55
|
+
*
|
56
|
+
* @internal
|
57
|
+
*/
|
58
|
+
export const SchemaFromString = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.fromBrand(constructor));
|
59
|
+
/**
|
60
|
+
* A Schema that represents a CVBrand.SemVer.Type
|
61
|
+
*
|
62
|
+
* @internal
|
63
|
+
*/
|
64
|
+
export const SchemaFromSelf = /*#__PURE__*/Schema.typeSchema(SchemaFromString);
|
65
|
+
//# sourceMappingURL=SemVer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SemVer.js","names":["MString","Brand","Schema","moduleTag","TypeId","Symbol","for","unsafeFromString","nominal","constructor","refined","isSemVer","s","error","fromStringOption","option","bind","fromString","either","fromStringOrThrow","has","input","SchemaFromString","String","pipe","fromBrand","SchemaFromSelf","typeSchema"],"sources":["../../esm/SemVer.ts"],"sourcesContent":[null],"mappings":"AAAA;AAEA,SAASA,OAAO,QAAgB,uBAAuB;AACvD,SAASC,KAAK,EAAkBC,MAAM,QAAQ,QAAQ;AAEtD;;;;;AAKA,OAAO,MAAMC,SAAS,GAAG,gCAAgC;AAEzD;;;;;AAKA,OAAO,MAAMC,MAAM,gBAAkBC,MAAM,CAACC,GAAG,CAACH,SAAS,CAAY;AAUrE;;;;;AAKA,OAAO,MAAMI,gBAAgB,gBAAGN,KAAK,CAACO,OAAO,EAAQ;AAErD;;;;;;AAMA,OAAO,MAAMC,WAAW,gBAAGR,KAAK,CAACS,OAAO,CAAOV,OAAO,CAACW,QAAQ,EAAGC,CAAC,IAClEX,KAAK,CAACY,KAAK,CAAC,IAAID,CAAC,+BAA+B,CAAC,CACjD;AAED;;;;;AAKA,OAAO,MAAME,gBAAgB,gBAGzBL,WAAW,CAACM,MAAM,CAACC,IAAI,CAACP,WAAW,CAAC;AAExC;;;;;AAKA,OAAO,MAAMQ,UAAU,gBAGnBR,WAAW,CAACS,MAAM,CAACF,IAAI,CAACP,WAAW,CAAC;AAExC;;;;;AAKA,OAAO,MAAMU,iBAAiB,GAAwCV,WAAW;AAEjF;;;;;AAKA,OAAO,MAAMW,GAAG,GAAIC,KAAa,IAAoBrB,OAAO,CAACW,QAAQ,CAACU,KAAK,CAAC;AAE5E;;;;;AAKA,OAAO,MAAMC,gBAAgB,gBAAgCpB,MAAM,CAACqB,MAAM,CAACC,IAAI,cAC9EtB,MAAM,CAACuB,SAAS,CAAChB,WAAW,CAAC,CAC7B;AAED;;;;;AAKA,OAAO,MAAMiB,cAAc,gBAAwBxB,MAAM,CAACyB,UAAU,CAACL,gBAAgB,CAAC","ignoreList":[]}
|
package/esm/Template.js
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
/**
|
2
|
+
* A template is a model of a text that has always the same structure. In such a text, there are
|
3
|
+
* immutable and mutable parts. Let's take the following two texts as an example:
|
4
|
+
*
|
5
|
+
* - Text1 = "John is a 47-year old man."
|
6
|
+
* - Text2 = "Jehnny is a 5-year old girl."
|
7
|
+
*
|
8
|
+
* These two texts obviously share the same structure which is the template:
|
9
|
+
*
|
10
|
+
* Placeholder1 is a Placeholder2-year old Placeholder3.
|
11
|
+
*
|
12
|
+
* Placeholder1, Placeholder2 and Placeholder3 are the mutable parts of the template. They contain
|
13
|
+
* valuable information. We call them `TemplatePlaceholder`'s.
|
14
|
+
*
|
15
|
+
* " is a " and "-year old " are the immutable parts of the template. We call them
|
16
|
+
* `TemplateSeperator`'s.
|
17
|
+
*
|
18
|
+
* From a text with the above structure, we can extract the values of Placeholder1, Placeholder2,
|
19
|
+
* and Placeholder3. In the present case:
|
20
|
+
*
|
21
|
+
* - For text1: Placeholder1 = 'John', Placeholder2 = '47', Placeholder3 = 'man'
|
22
|
+
* - For text2: Placeholder1 = 'Jehnny', Placeholder2 = '5', Placeholder3 = 'girl'
|
23
|
+
*
|
24
|
+
* Extracting the values of placeholders from a text according to a template is called parsing.
|
25
|
+
*
|
26
|
+
* Inversely, given a template and the values of the placeholders that compose it, we can generate a
|
27
|
+
* text. This is called formatting. In the present case, with:
|
28
|
+
*
|
29
|
+
* Placeholder1 = 'Tom', Placeholder2 = '15', Placeholder3 = 'boy'
|
30
|
+
*
|
31
|
+
* We will obtain the text: "Tom is a 15-year old boy."
|
32
|
+
*
|
33
|
+
* A TemplatePart is either a TemplateSeparator or a TemplatePlaceholder. This module implements a
|
34
|
+
* Template which is composed of a series of TemplatePart's. Note that Effect does provide the
|
35
|
+
* Schema.TemplateLiteralParser API which partly addresses the same problem. But there are some
|
36
|
+
* limitations to that API. For instance, template literal types cannot represent a fixed-length
|
37
|
+
* string or a string composed only of capital letters... It is for instance impossible to represent
|
38
|
+
* a date in the form YYYYMMDD with the TemplateLiteralParser. A schema in the form:
|
39
|
+
*
|
40
|
+
* `const schema = Schema.TemplateLiteralParser(Schema.NumberFromString,Schema.NumberFromString,
|
41
|
+
* Schema.NumberFromString)`
|
42
|
+
*
|
43
|
+
* Would not work as the first NumberFromString combinator would read the whole date.
|
44
|
+
*/
|
45
|
+
import { MInputError, MInspectable, MPipeable, MString, MTuple, MTypes } from '@parischap/effect-lib';
|
46
|
+
import { Array, Either, Equal, flow, Function, Option, pipe, Predicate, Record, Struct } from 'effect';
|
47
|
+
import * as CVTemplatePart from './TemplatePart.js';
|
48
|
+
import * as CVTemplateParts from './TemplateParts.js';
|
49
|
+
/**
|
50
|
+
* Module tag
|
51
|
+
*
|
52
|
+
* @category Module markers
|
53
|
+
*/
|
54
|
+
export const moduleTag = '@parischap/conversions/Template/';
|
55
|
+
const _TypeId = /*#__PURE__*/Symbol.for(moduleTag);
|
56
|
+
/**
|
57
|
+
* Type guard
|
58
|
+
*
|
59
|
+
* @category Guards
|
60
|
+
*/
|
61
|
+
export const has = u => Predicate.hasProperty(u, _TypeId);
|
62
|
+
/** Prototype */
|
63
|
+
const proto = {
|
64
|
+
[_TypeId]: {
|
65
|
+
_P: MTypes.covariantValue
|
66
|
+
},
|
67
|
+
[MInspectable.IdSymbol]() {
|
68
|
+
return pipe(this.templateParts, MTuple.makeBothBy({
|
69
|
+
toFirst: CVTemplateParts.getSyntheticDescription,
|
70
|
+
toSecond: CVTemplateParts.getPlaceholderDescription
|
71
|
+
}), Array.join('\n\n'));
|
72
|
+
},
|
73
|
+
... /*#__PURE__*/MInspectable.BaseProto(moduleTag),
|
74
|
+
...MPipeable.BaseProto
|
75
|
+
};
|
76
|
+
const _make = params => MTypes.objectFromDataAndProto(proto, params);
|
77
|
+
/**
|
78
|
+
* Constructor
|
79
|
+
*
|
80
|
+
* @category Constructors
|
81
|
+
*/
|
82
|
+
export const make = (...templateParts) => _make({
|
83
|
+
templateParts
|
84
|
+
});
|
85
|
+
/**
|
86
|
+
* Returns the `templateParts` property of `self`
|
87
|
+
*
|
88
|
+
* @category Destructors
|
89
|
+
*/
|
90
|
+
export const templateParts = /*#__PURE__*/Struct.get('templateParts');
|
91
|
+
/**
|
92
|
+
* Returns a function that parses a text into a record according to 'self' .
|
93
|
+
*
|
94
|
+
* @category Parsing
|
95
|
+
*/
|
96
|
+
export const toParser = self => text => Either.gen(function* () {
|
97
|
+
let consumed;
|
98
|
+
const result = Record.empty();
|
99
|
+
const templateParts = self.templateParts;
|
100
|
+
for (let pos = 0; pos < templateParts.length; pos++) {
|
101
|
+
const templatePart = templateParts[pos];
|
102
|
+
if (CVTemplatePart.isPlaceholder(templatePart)) {
|
103
|
+
/* eslint-disable-next-line functional/no-expression-statements */
|
104
|
+
[consumed, text] = yield* templatePart.parser(text);
|
105
|
+
const name = templatePart.name;
|
106
|
+
if (!(name in result)) /* eslint-disable-next-line functional/immutable-data, functional/no-expression-statements, */
|
107
|
+
result[name] = consumed;else {
|
108
|
+
const oldValue = result[name];
|
109
|
+
if (!Equal.equals(oldValue, consumed)) yield* Either.left(new MInputError.Type({
|
110
|
+
message: `${templatePart.label} is present more than once in template and receives differing values '${MString.fromUnknown(oldValue)}' and '${MString.fromUnknown(consumed)}'`
|
111
|
+
}));
|
112
|
+
}
|
113
|
+
} else /* eslint-disable-next-line functional/no-expression-statements */
|
114
|
+
text = yield* templatePart.parser(pos + 1)(text);
|
115
|
+
}
|
116
|
+
yield* pipe(text, MInputError.assertEmpty({
|
117
|
+
name: 'text not consumed by template'
|
118
|
+
}));
|
119
|
+
return result;
|
120
|
+
});
|
121
|
+
/**
|
122
|
+
* Same as toParser but the returned parser throws in case of error
|
123
|
+
*
|
124
|
+
* @category Parsing
|
125
|
+
*/
|
126
|
+
export const toThrowingParser = /*#__PURE__*/flow(toParser, /*#__PURE__*/Function.compose(/*#__PURE__*/Either.getOrThrowWith(Function.identity)));
|
127
|
+
/**
|
128
|
+
* Returns a function that formats an object into the template represented by 'self' . When
|
129
|
+
* strictMode is false, the formatter function of the templatepart's is replaced by the Either.right
|
130
|
+
* function, i.e. no checks are carried out when encoding
|
131
|
+
*
|
132
|
+
* @category Formatting
|
133
|
+
*/
|
134
|
+
export const toFormatter = self => {
|
135
|
+
return record => Either.gen(function* () {
|
136
|
+
let result = '';
|
137
|
+
for (const templatePart of self.templateParts) {
|
138
|
+
if (CVTemplatePart.isSeparator(templatePart)) {
|
139
|
+
/* eslint-disable-next-line functional/no-expression-statements */
|
140
|
+
result += templatePart.formatter();
|
141
|
+
} else {
|
142
|
+
const value = pipe(record, Record.get(templatePart.name),
|
143
|
+
// This error should not happen due to typing
|
144
|
+
Option.getOrThrowWith(() => new Error(`Abnormal error: no value passed for ${templatePart.label} templatepart`)));
|
145
|
+
/* eslint-disable-next-line functional/no-expression-statements */
|
146
|
+
result += yield* templatePart.formatter(value);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
return result;
|
150
|
+
});
|
151
|
+
};
|
152
|
+
/**
|
153
|
+
* Same as toFormatter but the returned formatter throws in case of error
|
154
|
+
*
|
155
|
+
* @category Formatting
|
156
|
+
*/
|
157
|
+
export const toThrowingFormatter = /*#__PURE__*/flow(toFormatter, /*#__PURE__*/Function.compose(/*#__PURE__*/Either.getOrThrowWith(Function.identity)));
|
158
|
+
//# sourceMappingURL=Template.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Template.js","names":["MInputError","MInspectable","MPipeable","MString","MTuple","MTypes","Array","Either","Equal","flow","Function","Option","pipe","Predicate","Record","Struct","CVTemplatePart","CVTemplateParts","moduleTag","_TypeId","Symbol","for","has","u","hasProperty","proto","_P","covariantValue","IdSymbol","templateParts","makeBothBy","toFirst","getSyntheticDescription","toSecond","getPlaceholderDescription","join","BaseProto","_make","params","objectFromDataAndProto","make","get","toParser","self","text","gen","consumed","result","empty","pos","length","templatePart","isPlaceholder","parser","name","oldValue","equals","left","Type","message","label","fromUnknown","assertEmpty","toThrowingParser","compose","getOrThrowWith","identity","toFormatter","record","isSeparator","formatter","value","Error","toThrowingFormatter"],"sources":["../../esm/Template.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SACCA,WAAW,EACXC,YAAY,EACZC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,MAAM,QACA,uBAAuB;AAC9B,SACCC,KAAK,EACLC,MAAM,EACNC,KAAK,EACLC,IAAI,EACJC,QAAQ,EACRC,MAAM,EACNC,IAAI,EAEJC,SAAS,EACTC,MAAM,EACNC,MAAM,QAEA,QAAQ;AACf,OAAO,KAAKC,cAAc,MAAM,mBAAmB;AACnD,OAAO,KAAKC,eAAe,MAAM,oBAAoB;AAGrD;;;;;AAKA,OAAO,MAAMC,SAAS,GAAG,kCAAkC;AAC3D,MAAMC,OAAO,gBAAkBC,MAAM,CAACC,GAAG,CAACH,SAAS,CAAY;AAqB/D;;;;;AAKA,OAAO,MAAMI,GAAG,GAAIC,CAAU,IAC7BV,SAAS,CAACW,WAAW,CAACD,CAAC,EAAEJ,OAAO,CAAC;AAElC;AACA,MAAMM,KAAK,GAA8B;EACxC,CAACN,OAAO,GAAG;IAAEO,EAAE,EAAErB,MAAM,CAACsB;EAAc,CAAE;EACxC,CAAC1B,YAAY,CAAC2B,QAAQ,IAAC;IACtB,OAAOhB,IAAI,CACV,IAAI,CAACiB,aAAa,EAClBzB,MAAM,CAAC0B,UAAU,CAAC;MACjBC,OAAO,EAAEd,eAAe,CAACe,uBAAuB;MAChDC,QAAQ,EAAEhB,eAAe,CAACiB;KAC1B,CAAC,EACF5B,KAAK,CAAC6B,IAAI,CAAC,MAAM,CAAC,CAClB;EACF,CAAC;EACD,iBAAGlC,YAAY,CAACmC,SAAS,CAAClB,SAAS,CAA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B,MAAM;EACd,CAAC,CAAC;AACJ,CAAC;AAED;;;;;AAMA,OAAO,MAAM0B,mBAAmB,gBAU5BhE,IAAI,CAAC0D,WAAW,eAAEzD,QAAQ,CAACsD,OAAO,cAACzD,MAAM,CAAC0D,cAAc,CAACvD,QAAQ,CAACwD,QAAQ,CAAC,CAAC,CAAU","ignoreList":[]}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/**
|
2
|
+
* This module implements a TemplatePart type. TemplatePart's are the constituents of Template's
|
3
|
+
* (see Template.ts).
|
4
|
+
*
|
5
|
+
* There are two kinds of TemplateParts: TemplateSeparator's (see TemplateSeparator.ts) and
|
6
|
+
* TemplatePlaceholder's (see TemplatePlaceholder.ts)
|
7
|
+
*/
|
8
|
+
import * as CVTemplatePlaceholder from './TemplatePlaceholder.js';
|
9
|
+
import * as CVTemplateSeparator from './TemplateSeparator.js';
|
10
|
+
/**
|
11
|
+
* Type guard
|
12
|
+
*
|
13
|
+
* @category Guards
|
14
|
+
*/
|
15
|
+
export const isPlaceholder = u => CVTemplatePlaceholder.has(u);
|
16
|
+
/**
|
17
|
+
* Type guard
|
18
|
+
*
|
19
|
+
* @category Guards
|
20
|
+
*/
|
21
|
+
export const isSeparator = u => CVTemplateSeparator.has(u);
|
22
|
+
//# sourceMappingURL=TemplatePart.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TemplatePart.js","names":["CVTemplatePlaceholder","CVTemplateSeparator","isPlaceholder","u","has","isSeparator"],"sources":["../../esm/TemplatePart.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;AAQA,OAAO,KAAKA,qBAAqB,MAAM,0BAA0B;AACjE,OAAO,KAAKC,mBAAmB,MAAM,wBAAwB;AAS7D;;;;;AAKA,OAAO,MAAMC,aAAa,GACzBC,CAAa,IAC8BH,qBAAqB,CAACI,GAAG,CAACD,CAAC,CAAC;AAExE;;;;;AAKA,OAAO,MAAME,WAAW,GACvBF,CAAa,IACsBF,mBAAmB,CAACG,GAAG,CAACD,CAAC,CAAC","ignoreList":[]}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/** This module implements an array of TemplatePart's (see TemplatePart.ts) */
|
2
|
+
import { MMatch } from '@parischap/effect-lib';
|
3
|
+
import { Array, flow, Function, Option } from 'effect';
|
4
|
+
import * as CVTemplatePart from './TemplatePart.js';
|
5
|
+
import * as CVTemplatePlaceholder from './TemplatePlaceholder.js';
|
6
|
+
import * as CVTemplateSeparator from './TemplateSeparator.js';
|
7
|
+
/**
|
8
|
+
* Shows a synthetic description of `self`, e.g.' #name is a #age-year-old #kind.'
|
9
|
+
*
|
10
|
+
* @category Destructors
|
11
|
+
*/
|
12
|
+
export const getSyntheticDescription = /*#__PURE__*/flow(/*#__PURE__*/Array.map(/*#__PURE__*/flow(MMatch.make, /*#__PURE__*/MMatch.when(CVTemplatePart.isPlaceholder, CVTemplatePlaceholder.label), /*#__PURE__*/MMatch.when(CVTemplatePart.isSeparator, CVTemplateSeparator.value), MMatch.exhaustive)), /*#__PURE__*/Array.join(''));
|
13
|
+
/**
|
14
|
+
* Shows a description of the placeholders of `self`, e.g.' #name is a #age-year-old #kind.'
|
15
|
+
*
|
16
|
+
* @category Destructors
|
17
|
+
*/
|
18
|
+
export const getPlaceholderDescription = /*#__PURE__*/flow(/*#__PURE__*/Array.filterMap(/*#__PURE__*/flow(MMatch.make, /*#__PURE__*/MMatch.when(CVTemplatePart.isPlaceholder, /*#__PURE__*/flow(CVTemplatePlaceholder.getLabelledDescription, Option.some)), /*#__PURE__*/MMatch.when(CVTemplatePart.isSeparator, /*#__PURE__*/Function.constant(/*#__PURE__*/Option.none())), MMatch.exhaustive)), /*#__PURE__*/Array.join('.\n'));
|
19
|
+
//# sourceMappingURL=TemplateParts.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TemplateParts.js","names":["MMatch","Array","flow","Function","Option","CVTemplatePart","CVTemplatePlaceholder","CVTemplateSeparator","getSyntheticDescription","map","make","when","isPlaceholder","label","isSeparator","value","exhaustive","join","getPlaceholderDescription","filterMap","getLabelledDescription","some","constant","none"],"sources":["../../esm/TemplateParts.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA,SAASA,MAAM,QAAgB,uBAAuB;AACtD,SAASC,KAAK,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,MAAM,QAAQ,QAAQ;AACtD,OAAO,KAAKC,cAAc,MAAM,mBAAmB;AACnD,OAAO,KAAKC,qBAAqB,MAAM,0BAA0B;AACjE,OAAO,KAAKC,mBAAmB,MAAM,wBAAwB;AAU7D;;;;;AAKA,OAAO,MAAMC,uBAAuB,gBAAwCN,IAAI,cAC/ED,KAAK,CAACQ,GAAG,cACRP,IAAI,CACHF,MAAM,CAACU,IAAI,eACXV,MAAM,CAACW,IAAI,CAACN,cAAc,CAACO,aAAa,EAAEN,qBAAqB,CAACO,KAAK,CAAC,eACtEb,MAAM,CAACW,IAAI,CAACN,cAAc,CAACS,WAAW,EAAEP,mBAAmB,CAACQ,KAAK,CAAC,EAClEf,MAAM,CAACgB,UAAU,CACjB,CACD,eACDf,KAAK,CAACgB,IAAI,CAAC,EAAE,CAAC,CACd;AAED;;;;;AAKA,OAAO,MAAMC,yBAAyB,gBAAwChB,IAAI,cACjFD,KAAK,CAACkB,SAAS,cACdjB,IAAI,CACHF,MAAM,CAACU,IAAI,eACXV,MAAM,CAACW,IAAI,CACVN,cAAc,CAACO,aAAa,eAC5BV,IAAI,CAACI,qBAAqB,CAACc,sBAAsB,EAAEhB,MAAM,CAACiB,IAAI,CAAC,CAC/D,eACDrB,MAAM,CAACW,IAAI,CAACN,cAAc,CAACS,WAAW,eAAEX,QAAQ,CAACmB,QAAQ,cAAClB,MAAM,CAACmB,IAAI,EAAE,CAAC,CAAC,EACzEvB,MAAM,CAACgB,UAAU,CACjB,CACD,eACDf,KAAK,CAACgB,IAAI,CAAC,KAAK,CAAC,CACjB","ignoreList":[]}
|