@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
@@ -1 +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","
|
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","getName","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,OAA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B,GAAG5C,IAAI,CAC/BwC,WAAW,EACX3C,UAAU,CAACsD,QAAQ,CAACV,oBAAoB,CAAC,EACzC5C,UAAU,CAACmD,QAAQ,CAACxC,aAAa,CAAC,EAClCjB,WAAW,CAACoD,KAAK,EAAE,EACnB9C,UAAU,CAACuD,cAAc,CACzB;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
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
|
-
* An extension to the Effect
|
3
|
-
*
|
2
|
+
* An extension to the `Effect.Schema` module that adds Schema instances for number and date
|
3
|
+
* formatting and parsing and implements new brands
|
4
4
|
*/
|
5
5
|
import { MMatch, MTuple } from '@parischap/effect-lib';
|
6
6
|
import { Array, Either, flow, Option, ParseResult, pipe, Record, Schema } from 'effect';
|
@@ -17,45 +17,44 @@ import * as CVTemplate from './Template.js';
|
|
17
17
|
import * as CVTemplatePart from './TemplatePart.js';
|
18
18
|
import * as CVTemplatePlaceholder from './TemplatePlaceholder.js';
|
19
19
|
/**
|
20
|
-
* A Schema that transforms a string into a
|
20
|
+
* A `Schema` that transforms a string into a `CVEmail`
|
21
21
|
*
|
22
22
|
* @category Schema transformations
|
23
23
|
*/
|
24
24
|
export const Email = CVEmail.SchemaFromString;
|
25
25
|
/**
|
26
|
-
* A Schema that represents a
|
26
|
+
* A `Schema` that represents a `CVEmail`
|
27
27
|
*
|
28
28
|
* @category Schema instances
|
29
29
|
*/
|
30
30
|
export const EmailFromSelf = CVEmail.SchemaFromSelf;
|
31
31
|
/**
|
32
|
-
* A Schema that transforms a string into
|
32
|
+
* A `Schema` that transforms a string into a `CVSemVer`
|
33
33
|
*
|
34
34
|
* @category Schema transformations
|
35
35
|
*/
|
36
36
|
export const SemVer = CVSemVer.SchemaFromString;
|
37
37
|
/**
|
38
|
-
* A Schema that represents a
|
38
|
+
* A `Schema` that represents a `CVSemVer`
|
39
39
|
*
|
40
40
|
* @category Schema instances
|
41
41
|
*/
|
42
42
|
export const SemVerFromSelf = CVSemVer.SchemaFromSelf;
|
43
43
|
/**
|
44
|
-
* A Schema that transforms a number into
|
44
|
+
* A `Schema` that transforms a number into a `CVReal`
|
45
45
|
*
|
46
46
|
* @category Schema transformations
|
47
47
|
*/
|
48
48
|
export const RealFromNumber = CVReal.SchemaFromNumber;
|
49
49
|
/**
|
50
|
-
* A Schema that represents
|
50
|
+
* A `Schema` that represents `CVReal`
|
51
51
|
*
|
52
52
|
* @category Schema instances
|
53
53
|
*/
|
54
54
|
export const RealFromSelf = CVReal.SchemaFromSelf;
|
55
55
|
/**
|
56
|
-
* A Schema that transforms a string into a
|
57
|
-
*
|
58
|
-
* CVNumberBase10Format.toNumberFormatter for more details
|
56
|
+
* A `Schema` that transforms a string into a `CVReal` according to the `format`. Read documentation
|
57
|
+
* of module NumberBase10Format.ts for more details
|
59
58
|
*
|
60
59
|
* @category Schema transformations
|
61
60
|
*/
|
@@ -69,37 +68,37 @@ export const Real = format => {
|
|
69
68
|
});
|
70
69
|
};
|
71
70
|
/**
|
72
|
-
* A Schema that transforms a number into a CVInteger
|
71
|
+
* A `Schema` that transforms a number into a `CVInteger`
|
73
72
|
*
|
74
73
|
* @category Schema transformations
|
75
74
|
*/
|
76
75
|
export const IntegerFromNumber = CVInteger.SchemaFromNumber;
|
77
76
|
/**
|
78
|
-
* A Schema that represents a CVInteger
|
77
|
+
* A `Schema` that represents a `CVInteger`
|
79
78
|
*
|
80
79
|
* @category Schema instances
|
81
80
|
*/
|
82
81
|
export const IntegerFromSelf = CVInteger.SchemaFromSelf;
|
83
82
|
/**
|
84
|
-
* A Schema that transforms a number into a CVPositiveInteger
|
83
|
+
* A `Schema` that transforms a number into a `CVPositiveInteger`
|
85
84
|
*
|
86
85
|
* @category Schema transformations
|
87
86
|
*/
|
88
87
|
export const PositiveIntegerFromNumber = CVPositiveInteger.SchemaFromNumber;
|
89
88
|
/**
|
90
|
-
* A Schema that represents a CVPositiveInteger
|
89
|
+
* A `Schema` that represents a `CVPositiveInteger`
|
91
90
|
*
|
92
91
|
* @category Schema instances
|
93
92
|
*/
|
94
93
|
export const PositiveIntegerFromSelf = CVPositiveInteger.SchemaFromSelf;
|
95
94
|
/**
|
96
|
-
* A Schema that transforms a number into a CVPositiveReal
|
95
|
+
* A `Schema` that transforms a number into a `CVPositiveReal`
|
97
96
|
*
|
98
97
|
* @category Schema transformations
|
99
98
|
*/
|
100
99
|
export const PositiveRealFromNumber = CVPositiveReal.SchemaFromNumber;
|
101
100
|
/**
|
102
|
-
* A Schema that represents a CVPositiveReal
|
101
|
+
* A `Schema` that represents a `CVPositiveReal`
|
103
102
|
*
|
104
103
|
* @category Schema instances
|
105
104
|
*/
|
@@ -115,22 +114,22 @@ const BigDecimalFromString = format => {
|
|
115
114
|
};
|
116
115
|
export {
|
117
116
|
/**
|
118
|
-
* A Schema that transforms a string into a BigDecimal according to
|
119
|
-
*
|
120
|
-
* CVNumberBase10Format.toNumberFormatter for more details
|
117
|
+
* A `Schema` that transforms a string into a `BigDecimal` according to `format`. Read
|
118
|
+
* documentation of module NumberBase10Format.ts for more details
|
121
119
|
*
|
122
120
|
* @category Schema transformations
|
123
121
|
*/
|
124
122
|
BigDecimalFromString as BigDecimal };
|
125
123
|
/**
|
126
|
-
* A Schema that represents a CVDateTime
|
124
|
+
* A `Schema` that represents a `CVDateTime`
|
127
125
|
*
|
128
126
|
* @category Schema instances
|
129
127
|
*/
|
130
128
|
export const DateTimeFromSelf = /*#__PURE__*/Schema.declare(input => CVDateTime.has(input));
|
131
129
|
/**
|
132
|
-
* A Schema that transforms a CVDateTime into a Date
|
133
|
-
* default timeZoneOffset of the machine this code is
|
130
|
+
* A `Schema` that transforms a `CVDateTime` into a Javascript `Date`. Upon encoding, the
|
131
|
+
* `CVDateTime` object is created with the default timeZoneOffset of the machine this code is
|
132
|
+
* running on
|
134
133
|
*
|
135
134
|
* @category Schema instances
|
136
135
|
*/
|
@@ -140,8 +139,8 @@ export const DateFromDateTime = /*#__PURE__*/Schema.transform(DateTimeFromSelf,
|
|
140
139
|
encode: CVDateTime.fromDate
|
141
140
|
});
|
142
141
|
/**
|
143
|
-
* A Schema that transforms a CVDateTime into an Effect
|
144
|
-
* time zone offset
|
142
|
+
* A `Schema` that transforms a `CVDateTime` into an `Effect.DateTime.Zoned`. Both objects share the
|
143
|
+
* same time zone offset
|
145
144
|
*
|
146
145
|
* @category Schema instances
|
147
146
|
*/
|
@@ -161,29 +160,29 @@ const DateTimeFromString = format => {
|
|
161
160
|
};
|
162
161
|
export {
|
163
162
|
/**
|
164
|
-
* A Schema that transforms a string into a CVDateTime according to
|
165
|
-
*
|
166
|
-
* details
|
163
|
+
* A `Schema` that transforms a string into a `CVDateTime` according to `format`. Read
|
164
|
+
* documentation of module DateTimeFormat.ts for more details
|
167
165
|
*
|
168
166
|
* @category Schema transformations
|
169
167
|
*/
|
170
168
|
DateTimeFromString as DateTime };
|
171
169
|
/**
|
172
|
-
* A Schema that transforms a string into a Date according to
|
173
|
-
* documentation of
|
170
|
+
* A `Schema` that transforms a string into a Javascript `Date` according to `format`. Read
|
171
|
+
* documentation of module DateTimeFormat.ts for more details
|
174
172
|
*
|
175
173
|
* @category Schema transformations
|
176
174
|
*/
|
177
175
|
export const Date = format => Schema.compose(DateTimeFromString(format), DateFromDateTime);
|
178
176
|
/**
|
179
|
-
* A Schema that transforms a string into
|
180
|
-
* documentation of
|
177
|
+
* A `Schema` that transforms a string into an `Effect.DateTime.Zoned` according to `format`. Read
|
178
|
+
* documentation of module DateTimeFormat.ts for more details
|
181
179
|
*
|
182
180
|
* @category Schema transformations
|
183
181
|
*/
|
184
182
|
export const DateTimeZoned = format => Schema.compose(DateTimeFromString(format), DateTimeZonedFromDateTime);
|
185
183
|
/**
|
186
|
-
* A Schema that transforms a string into an object according to
|
184
|
+
* A `Schema` that transforms a string into an object according to template. Read documentation of
|
185
|
+
* module Template.ts for more details
|
187
186
|
*
|
188
187
|
* @category Schema transformations
|
189
188
|
*/
|
@@ -192,7 +191,7 @@ export const Template = template => {
|
|
192
191
|
const formatter = CVTemplate.toFormatter(template);
|
193
192
|
const schemaOutput = pipe(template.templateParts, Array.filterMap(flow(MMatch.make, MMatch.when(CVTemplatePart.isSeparator, () => Option.none()), MMatch.when(CVTemplatePart.isPlaceholder, flow(MTuple.makeBothBy({
|
194
193
|
toFirst: CVTemplatePlaceholder.name,
|
195
|
-
toSecond: CVTemplatePlaceholder.
|
194
|
+
toSecond: CVTemplatePlaceholder.tSchemaInstance
|
196
195
|
}), Option.some)), MMatch.exhaustive)), Record.fromEntries, Schema.Struct);
|
197
196
|
return Schema.transformOrFail(Schema.String, schemaOutput, {
|
198
197
|
strict: true,
|
package/esm/Schema.js.map
CHANGED
@@ -1 +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","
|
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","tSchemaInstance","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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ACuF,IAAI,EAAE,CAAC,EAC5D5F,MAAM,CAAC0F,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
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
/**
|
1
|
+
/**
|
2
|
+
* A module that implements a `CVSemVer` brand, i.e. a string that represents a valid semantic
|
3
|
+
* version. See the `Effect` documentation about Branding
|
4
|
+
* (https://effect.website/docs/code-style/branded-types/) if you are not familiar with this
|
5
|
+
* concept.
|
6
|
+
*/
|
2
7
|
import { MString } from '@parischap/effect-lib';
|
3
8
|
import { Brand, Schema } from 'effect';
|
4
9
|
/**
|
@@ -14,52 +19,47 @@ export const moduleTag = '@parischap/conversions/SemVer/';
|
|
14
19
|
*/
|
15
20
|
export const TypeId = /*#__PURE__*/Symbol.for(moduleTag);
|
16
21
|
/**
|
17
|
-
* Constructs a
|
22
|
+
* Constructs a `CVSemVer` without any verifications
|
18
23
|
*
|
19
24
|
* @category Constructors
|
20
25
|
*/
|
21
26
|
export const unsafeFromString = /*#__PURE__*/Brand.nominal();
|
22
27
|
/**
|
23
|
-
*
|
24
|
-
* SemVer
|
28
|
+
* Brand constructor. Should not be used directly
|
25
29
|
*
|
26
|
-
* @
|
30
|
+
* @ignore
|
27
31
|
*/
|
28
32
|
export const constructor = /*#__PURE__*/Brand.refined(MString.isSemVer, s => Brand.error(`'${s}' does not represent a semver`));
|
29
33
|
/**
|
30
|
-
*
|
34
|
+
* Tries to construct a `CVSemVer` from a string. Returns a `Some` if the conversion can be
|
35
|
+
* performed, a `None` otherwise
|
31
36
|
*
|
32
37
|
* @category Constructors
|
33
38
|
*/
|
34
39
|
export const fromStringOption = /*#__PURE__*/constructor.option.bind(constructor);
|
35
40
|
/**
|
36
|
-
*
|
41
|
+
* Tries to construct a `CVSemVer` from a string. Returns a `Right` if the conversion can be
|
42
|
+
* performed, a `Left` otherwise
|
37
43
|
*
|
38
44
|
* @category Constructors
|
39
45
|
*/
|
40
46
|
export const fromString = /*#__PURE__*/constructor.either.bind(constructor);
|
41
47
|
/**
|
42
|
-
* Constructs a
|
48
|
+
* Constructs a `CVSemVer` if possible. Throws otherwise.
|
43
49
|
*
|
44
50
|
* @category Constructors
|
45
51
|
*/
|
46
52
|
export const fromStringOrThrow = constructor;
|
47
53
|
/**
|
48
|
-
*
|
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
|
54
|
+
* A `Schema` that transforms a string into a `CVSemVer`
|
55
55
|
*
|
56
|
-
* @
|
56
|
+
* @ignore
|
57
57
|
*/
|
58
58
|
export const SchemaFromString = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.fromBrand(constructor));
|
59
59
|
/**
|
60
|
-
* A Schema that represents a
|
60
|
+
* A `Schema` that represents a `CVSemVer`
|
61
61
|
*
|
62
|
-
* @
|
62
|
+
* @ignore
|
63
63
|
*/
|
64
64
|
export const SchemaFromSelf = /*#__PURE__*/Schema.typeSchema(SchemaFromString);
|
65
65
|
//# sourceMappingURL=SemVer.js.map
|
package/esm/SemVer.js.map
CHANGED
@@ -1 +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","
|
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","SchemaFromString","String","pipe","fromBrand","SchemaFromSelf","typeSchema"],"sources":["../../esm/SemVer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AAOA,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;;;;;AAKA,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;;;;;;AAMA,OAAO,MAAME,gBAAgB,gBAGzBL,WAAW,CAACM,MAAM,CAACC,IAAI,CAACP,WAAW,CAAC;AAExC;;;;;;AAMA,OAAO,MAAMQ,UAAU,gBAGnBR,WAAW,CAACS,MAAM,CAACF,IAAI,CAACP,WAAW,CAAC;AAExC;;;;;AAKA,OAAO,MAAMU,iBAAiB,GAAwCV,WAAW;AAEjF;;;;;AAKA,OAAO,MAAMW,gBAAgB,gBAAgClB,MAAM,CAACmB,MAAM,CAACC,IAAI,cAC9EpB,MAAM,CAACqB,SAAS,CAACd,WAAW,CAAC,CAC7B;AAED;;;;;AAKA,OAAO,MAAMe,cAAc,gBAAwBtB,MAAM,CAACuB,UAAU,CAACL,gBAAgB,CAAC","ignoreList":[]}
|
package/esm/Template.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
|
-
*
|
3
|
-
* immutable and mutable parts. Let's take the following two
|
2
|
+
* This module implements a `CVTemplate` which is a model of a text that has always the same
|
3
|
+
* structure. In such a text, there are immutable and mutable parts. Let's take the following two
|
4
|
+
* texts as an example:
|
4
5
|
*
|
5
6
|
* - Text1 = "John is a 47-year old man."
|
6
7
|
* - Text2 = "Jehnny is a 5-year old girl."
|
@@ -10,42 +11,43 @@
|
|
10
11
|
* Placeholder1 is a Placeholder2-year old Placeholder3.
|
11
12
|
*
|
12
13
|
* Placeholder1, Placeholder2 and Placeholder3 are the mutable parts of the template. They contain
|
13
|
-
* valuable information. We call them `
|
14
|
+
* valuable information. We call them `CVTemplatePlaceholder`'s.
|
14
15
|
*
|
15
|
-
* " is a "
|
16
|
-
* `
|
16
|
+
* " is a ", "-year old " and "." are the immutable parts of the template. We call them
|
17
|
+
* `CVTemplateSeperator`'s.
|
17
18
|
*
|
18
19
|
* From a text with the above structure, we can extract the values of Placeholder1, Placeholder2,
|
19
20
|
* and Placeholder3. In the present case:
|
20
21
|
*
|
21
|
-
* - For text1: Placeholder1
|
22
|
-
* - For text2: Placeholder1
|
22
|
+
* - For text1: { Placeholder1 : 'John', Placeholder2 : '47', Placeholder3 : 'man' }
|
23
|
+
* - For text2: { Placeholder1 : 'Jehnny', Placeholder2 : '5', Placeholder3 : 'girl'}
|
23
24
|
*
|
24
|
-
* Extracting the values of placeholders from a text according to a template is called parsing.
|
25
|
+
* Extracting the values of placeholders from a text according to a template is called parsing. The
|
26
|
+
* result of parsing is an object whose properties are named after the name of the placeholders they
|
27
|
+
* represent.
|
25
28
|
*
|
26
|
-
* Inversely, given a template and the values of the placeholders that compose it
|
27
|
-
* text. This is called formatting. In the present case,
|
29
|
+
* Inversely, given a template and the values of the placeholders that compose it (provided as the
|
30
|
+
* properties of an object), we can generate a text. This is called formatting. In the present case,
|
31
|
+
* with the object:
|
28
32
|
*
|
29
|
-
* Placeholder1
|
33
|
+
* { Placeholder1 : 'Tom', Placeholder2 : '15', Placeholder3 : 'boy' }
|
30
34
|
*
|
31
35
|
* We will obtain the text: "Tom is a 15-year old boy."
|
32
36
|
*
|
33
|
-
*
|
34
|
-
*
|
35
|
-
*
|
36
|
-
*
|
37
|
-
*
|
38
|
-
*
|
39
|
-
*
|
40
|
-
*
|
41
|
-
* Schema.NumberFromString)`
|
42
|
-
*
|
43
|
-
* Would not work as the first NumberFromString combinator would read the whole date.
|
37
|
+
* Note that `Effect` does provide the `Schema.TemplateLiteralParser` API which partly addresses the
|
38
|
+
* same problem. But there are some limitations to that API. For instance, template literal types
|
39
|
+
* cannot represent a fixed-length string or a string composed only of capital letters... It is for
|
40
|
+
* instance impossible to represent a date in the form YYYYMMDD with the
|
41
|
+
* `Schema.TemplateLiteralParser`. A schema in the form `const schema =
|
42
|
+
* Schema.TemplateLiteralParser(Schema.NumberFromString,Schema.NumberFromString,
|
43
|
+
* Schema.NumberFromString)` does not work as the first NumberFromString combinator reads the whole
|
44
|
+
* date
|
44
45
|
*/
|
45
46
|
import { MInputError, MInspectable, MPipeable, MString, MTuple, MTypes } from '@parischap/effect-lib';
|
46
47
|
import { Array, Either, Equal, flow, Function, Option, pipe, Predicate, Record, Struct } from 'effect';
|
47
48
|
import * as CVTemplatePart from './TemplatePart.js';
|
48
49
|
import * as CVTemplateParts from './TemplateParts.js';
|
50
|
+
import * as CVTemplateSeparator from './TemplateSeparator.js';
|
49
51
|
/**
|
50
52
|
* Module tag
|
51
53
|
*
|
@@ -89,7 +91,8 @@ export const make = (...templateParts) => _make({
|
|
89
91
|
*/
|
90
92
|
export const templateParts = /*#__PURE__*/Struct.get('templateParts');
|
91
93
|
/**
|
92
|
-
* Returns a function that
|
94
|
+
* Returns a function that tries to parse a text into an object according to 'self'. The generated
|
95
|
+
* parser returns a `Right` of an object upon success, a `Left` otherwise.
|
93
96
|
*
|
94
97
|
* @category Parsing
|
95
98
|
*/
|
@@ -110,8 +113,11 @@ export const toParser = self => text => Either.gen(function* () {
|
|
110
113
|
message: `${templatePart.label} is present more than once in template and receives differing values '${MString.fromUnknown(oldValue)}' and '${MString.fromUnknown(consumed)}'`
|
111
114
|
}));
|
112
115
|
}
|
113
|
-
} else
|
114
|
-
|
116
|
+
} else {
|
117
|
+
const parser = CVTemplateSeparator.toParser(templatePart);
|
118
|
+
/* eslint-disable-next-line functional/no-expression-statements */
|
119
|
+
text = yield* parser(pos + 1, text);
|
120
|
+
}
|
115
121
|
}
|
116
122
|
yield* pipe(text, MInputError.assertEmpty({
|
117
123
|
name: 'text not consumed by template'
|
@@ -119,15 +125,14 @@ export const toParser = self => text => Either.gen(function* () {
|
|
119
125
|
return result;
|
120
126
|
});
|
121
127
|
/**
|
122
|
-
* Same as toParser but the
|
128
|
+
* Same as `toParser` but the generated parser throws in case of failure
|
123
129
|
*
|
124
130
|
* @category Parsing
|
125
131
|
*/
|
126
132
|
export const toThrowingParser = /*#__PURE__*/flow(toParser, /*#__PURE__*/Function.compose(/*#__PURE__*/Either.getOrThrowWith(Function.identity)));
|
127
133
|
/**
|
128
|
-
* Returns a function that
|
129
|
-
*
|
130
|
-
* function, i.e. no checks are carried out when encoding
|
134
|
+
* Returns a function that tries to format an object into a string according to 'self'. The
|
135
|
+
* generated formatter returns a `Right` of a string upon success, a `Left` otherwise.
|
131
136
|
*
|
132
137
|
* @category Formatting
|
133
138
|
*/
|
@@ -137,7 +142,7 @@ export const toFormatter = self => {
|
|
137
142
|
for (const templatePart of self.templateParts) {
|
138
143
|
if (CVTemplatePart.isSeparator(templatePart)) {
|
139
144
|
/* eslint-disable-next-line functional/no-expression-statements */
|
140
|
-
result += templatePart.
|
145
|
+
result += templatePart.value;
|
141
146
|
} else {
|
142
147
|
const value = pipe(record, Record.get(templatePart.name),
|
143
148
|
// This error should not happen due to typing
|
@@ -150,7 +155,7 @@ export const toFormatter = self => {
|
|
150
155
|
});
|
151
156
|
};
|
152
157
|
/**
|
153
|
-
* Same as toFormatter but the
|
158
|
+
* Same as `toFormatter` but the generated formatter throws in case of failure
|
154
159
|
*
|
155
160
|
* @category Formatting
|
156
161
|
*/
|
package/esm/Template.js.map
CHANGED
@@ -1 +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","
|
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","CVTemplateSeparator","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","value","Error","formatter","toThrowingFormatter"],"sources":["../../esm/Template.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,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;AAErD,OAAO,KAAKC,mBAAmB,MAAM,wBAAwB;AAE7D;;;;;AAKA,OAAO,MAAMC,SAAS,GAAG,kCAAkC;AAC3D,MAAMC,OAAO,gBAAkBC,MAAM,CAACC,GAAG,CAACH,SAAS,CAAY;AAqB/D;;;;;AAKA,OAAO,MAAMI,GAAG,GAAIC,CAAU,IAC7BX,SAAS,CAACY,WAAW,CAACD,CAAC,EAAEJ,OAAO,CAAC;AAElC;AACA,MAAMM,KAAK,GAA8B;EACxC,CAACN,OAAO,GAAG;IAAEO,EAAE,EAAEtB,MAAM,CAACuB;EAAc,CAAE;EACxC,CAAC3B,YAAY,CAAC4B,QAAQ,IAAC;IACtB,OAAOjB,IAAI,CACV,IAAI,CAACkB,aAAa,EAClB1B,MAAM,CAAC2B,UAAU,CAAC;MACjBC,OAAO,EAAEf,eAAe,CAACgB,uBAAuB;MAChDC,QAAQ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AC7B;QACA5C,MAAM,CAACuD,cAAc,CACpB,MACC,IAAIM,KAAK,CAAC,uCAAuCpB,YAAY,CAACS,KAAK,eAAe,CAAC,CACpF,CACD;QACD;QACAb,MAAM,IAAI,OAAOI,YAAY,CAACqB,SAAS,CAACF,KAAK,CAAC;MAC/C;IACD;IAEA,OAAOvB,MAAM;EACd,CAAC,CAAC;AACJ,CAAC;AAED;;;;;AAMA,OAAO,MAAM0B,mBAAmB,gBAU5BjE,IAAI,CAAC2D,WAAW,eAAE1D,QAAQ,CAACuD,OAAO,cAAC1D,MAAM,CAAC2D,cAAc,CAACxD,QAAQ,CAACyD,QAAQ,CAAC,CAAC,CAAU","ignoreList":[]}
|
package/esm/TemplatePart.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
/**
|
2
|
-
* This module implements
|
3
|
-
*
|
2
|
+
* This module implements `CVTemplatePart`'s which are the constituents of `CVTemplate`'s (see
|
3
|
+
* Template.ts).
|
4
4
|
*
|
5
|
-
* There are two kinds of
|
6
|
-
*
|
5
|
+
* There are two kinds of `CVTemplatePart`'s: `CVTemplateSeparator`'s (see TemplateSeparator.ts) and
|
6
|
+
* `CVTemplatePlaceholder`'s (see TemplatePlaceholder.ts)
|
7
7
|
*/
|
8
8
|
import * as CVTemplatePlaceholder from './TemplatePlaceholder.js';
|
9
9
|
import * as CVTemplateSeparator from './TemplateSeparator.js';
|
package/esm/TemplateParts.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/** This module implements an array of
|
1
|
+
/** This module implements an array of `CVTemplatePart`'s (see TemplatePart.ts) */
|
2
2
|
import { MMatch } from '@parischap/effect-lib';
|
3
3
|
import { Array, flow, Function, Option } from 'effect';
|
4
4
|
import * as CVTemplatePart from './TemplatePart.js';
|
@@ -11,7 +11,8 @@ import * as CVTemplateSeparator from './TemplateSeparator.js';
|
|
11
11
|
*/
|
12
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
13
|
/**
|
14
|
-
* Shows a description of the
|
14
|
+
* Shows a description of the `CVTemplatePlaceholder`'s of `self` (see description of
|
15
|
+
* `CVTemplatePlaceholder.getLabelledDescription`)
|
15
16
|
*
|
16
17
|
* @category Destructors
|
17
18
|
*/
|
package/esm/TemplateParts.js.map
CHANGED
@@ -1 +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
|
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;;;;;;AAMA,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":[]}
|