@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,342 @@
|
|
1
|
+
/**
|
2
|
+
* This module implements a TemplatePlaceholder type which is a sub-type of the TemplatePart type
|
3
|
+
* (see TemplatePart.ts)
|
4
|
+
*
|
5
|
+
* A TemplatePlaceholder represents the mutable part of a template. Each Placeholder defines a
|
6
|
+
* parser and a formatter:
|
7
|
+
*
|
8
|
+
* - The parser takes a string, consumes a part of that string, optionnally converts the consumed part
|
9
|
+
* to a value of type T and, if successful, returns a right of that value and of what has not been
|
10
|
+
* consumed. In case of an error, it returns a left.
|
11
|
+
* - The formatter takes a value of type T, converts it to a string (if T is not string), checks that
|
12
|
+
* the result is coherent and, if so, returns a right of that string. Otherwise, it returns a
|
13
|
+
* left.
|
14
|
+
*/
|
15
|
+
import { MInputError, MInspectable, MPipeable, MRegExp, MRegExpString, MString, MStruct, MTuple, MTypes } from '@parischap/effect-lib';
|
16
|
+
import { Array, Either, flow, Function, HashMap, pipe, Predicate, Schema, String, Struct, Tuple } from 'effect';
|
17
|
+
import * as CVNumberBase10Format from './NumberBase10Format.js';
|
18
|
+
import * as CVReal from './Real.js';
|
19
|
+
/**
|
20
|
+
* Module tag
|
21
|
+
*
|
22
|
+
* @category Module markers
|
23
|
+
*/
|
24
|
+
export const moduleTag = '@parischap/conversions/TemplatePlaceholder/';
|
25
|
+
const _TypeId = /*#__PURE__*/Symbol.for(moduleTag);
|
26
|
+
/**
|
27
|
+
* Type guard
|
28
|
+
*
|
29
|
+
* @category Guards
|
30
|
+
*/
|
31
|
+
export const has = u => Predicate.hasProperty(u, _TypeId);
|
32
|
+
/** Proto */
|
33
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
34
|
+
const proto = {
|
35
|
+
[_TypeId]: {
|
36
|
+
_N: MTypes.covariantValue,
|
37
|
+
_T: MTypes.invariantValue
|
38
|
+
},
|
39
|
+
[MInspectable.IdSymbol]() {
|
40
|
+
return getLabelledDescription(this);
|
41
|
+
},
|
42
|
+
... /*#__PURE__*/MInspectable.BaseProto(moduleTag),
|
43
|
+
...MPipeable.BaseProto
|
44
|
+
};
|
45
|
+
const _make = params => MTypes.objectFromDataAndProto(proto, params);
|
46
|
+
/**
|
47
|
+
* Constructor
|
48
|
+
*
|
49
|
+
* @category Constructors
|
50
|
+
*/
|
51
|
+
export const make = /*#__PURE__*/flow(/*#__PURE__*/MStruct.enrichWith({
|
52
|
+
label: ({
|
53
|
+
name
|
54
|
+
}) => MString.prepend('#')(name)
|
55
|
+
}), _make);
|
56
|
+
/**
|
57
|
+
* Returns the `name` property of `self`
|
58
|
+
*
|
59
|
+
* @category Destructors
|
60
|
+
*/
|
61
|
+
export const name = /*#__PURE__*/Struct.get('name');
|
62
|
+
/**
|
63
|
+
* Returns the `label` property of `self`
|
64
|
+
*
|
65
|
+
* @category Destructors
|
66
|
+
*/
|
67
|
+
export const label = /*#__PURE__*/Struct.get('label');
|
68
|
+
/**
|
69
|
+
* Returns the `description` property of `self`
|
70
|
+
*
|
71
|
+
* @category Destructors
|
72
|
+
*/
|
73
|
+
export const description = /*#__PURE__*/Struct.get('description');
|
74
|
+
/**
|
75
|
+
* Returns the `parser` property of `self`
|
76
|
+
*
|
77
|
+
* @category Destructors
|
78
|
+
*/
|
79
|
+
export const parser = /*#__PURE__*/Struct.get('parser');
|
80
|
+
/**
|
81
|
+
* Returns the `formatter` property of `self`
|
82
|
+
*
|
83
|
+
* @category Destructors
|
84
|
+
*/
|
85
|
+
export const formatter = /*#__PURE__*/Struct.get('formatter');
|
86
|
+
/**
|
87
|
+
* Returns the `schemaInstance` property of `self`
|
88
|
+
*
|
89
|
+
* @category Destructors
|
90
|
+
*/
|
91
|
+
export const schemaInstance = /*#__PURE__*/Struct.get('schemaInstance');
|
92
|
+
/**
|
93
|
+
* Returns the description of `self`
|
94
|
+
*
|
95
|
+
* @category Destructors
|
96
|
+
*/
|
97
|
+
export const getLabelledDescription = self => `${self.label}: ${self.description}`;
|
98
|
+
/**
|
99
|
+
* Returns a modified copy of `self` where a postParser function is executed after the parser of
|
100
|
+
* `self` and a preFormatter function is executed before the formatter of `self`
|
101
|
+
*
|
102
|
+
* @category Destructors
|
103
|
+
*/
|
104
|
+
export const modify = ({
|
105
|
+
descriptorMapper,
|
106
|
+
postParser,
|
107
|
+
preFormatter,
|
108
|
+
t1SchemaInstance
|
109
|
+
}) => self => make({
|
110
|
+
name: self.name,
|
111
|
+
description: descriptorMapper(self.description),
|
112
|
+
parser: function (text) {
|
113
|
+
return Either.flatMap(self.parser.call(this, text), flow(Tuple.mapBoth({
|
114
|
+
onFirst: t => postParser.call(this, t),
|
115
|
+
onSecond: Either.right
|
116
|
+
}), Either.all));
|
117
|
+
},
|
118
|
+
formatter: function (t1) {
|
119
|
+
return pipe(preFormatter.call(this, t1), Either.flatMap(t => self.formatter.call(this, t)));
|
120
|
+
},
|
121
|
+
schemaInstance: t1SchemaInstance === undefined ? self.schemaInstance : t1SchemaInstance
|
122
|
+
});
|
123
|
+
/**
|
124
|
+
* Builds a TemplatePlaceholder instance that parses/formats exactly `length` characters from a
|
125
|
+
* string. `length` must be a strictly positive integer.
|
126
|
+
*
|
127
|
+
* @category Constructors
|
128
|
+
*/
|
129
|
+
export const fixedLength = ({
|
130
|
+
name,
|
131
|
+
length
|
132
|
+
}) => {
|
133
|
+
return make({
|
134
|
+
name,
|
135
|
+
description: `${length}-character string`,
|
136
|
+
parser: function (text) {
|
137
|
+
return pipe(text, MString.splitAt(length), Tuple.mapBoth({
|
138
|
+
onFirst: MInputError.assertLength({
|
139
|
+
expected: length,
|
140
|
+
name: this.label
|
141
|
+
}),
|
142
|
+
onSecond: Either.right
|
143
|
+
}), Either.all);
|
144
|
+
},
|
145
|
+
formatter: function (value) {
|
146
|
+
return MInputError.assertLength({
|
147
|
+
expected: length,
|
148
|
+
name: this.label
|
149
|
+
})(value);
|
150
|
+
},
|
151
|
+
schemaInstance: Schema.String
|
152
|
+
});
|
153
|
+
};
|
154
|
+
/**
|
155
|
+
* Builds a TemplatePlaceholder instance that parses/formats exactly `length` characters from a
|
156
|
+
* string and trims/pads the result at `padPosition` with `fillChar`. `fillChar` should be a
|
157
|
+
* one-character string. `length` must be a strictly positive integer. See the meaning of
|
158
|
+
* `disallowEmptyString` in String.trim.
|
159
|
+
*
|
160
|
+
* @category Constructors
|
161
|
+
*/
|
162
|
+
export const paddedFixedLength = params => {
|
163
|
+
const trimmer = flow(MString.trim(params), Either.right);
|
164
|
+
const padder = flow(MString.pad(params), Either.right);
|
165
|
+
return pipe(fixedLength(params), modify({
|
166
|
+
descriptorMapper: MString.append(` ${MString.PadPosition.toId(params.padPosition)}-padded with '${params.fillChar}'`),
|
167
|
+
postParser: trimmer,
|
168
|
+
preFormatter: padder
|
169
|
+
}));
|
170
|
+
};
|
171
|
+
/**
|
172
|
+
* Builds a TemplatePlaceholder instance that parses/formats a Real in the given
|
173
|
+
* `numberBase10Format`. If the number to parse/format is less than `length` characters, `fillChar`
|
174
|
+
* is trimmed/padded between the sign and the number so that the length condition is respected.
|
175
|
+
* fillChar must be a one-character string (but no error is triggered if you do not respect that
|
176
|
+
* condition)
|
177
|
+
*
|
178
|
+
* @category Constructors
|
179
|
+
*/
|
180
|
+
export const fixedLengthToReal = params => {
|
181
|
+
const {
|
182
|
+
numberBase10Format,
|
183
|
+
fillChar
|
184
|
+
} = params;
|
185
|
+
const numberParser = function (input) {
|
186
|
+
return pipe(input, CVNumberBase10Format.toRealParser(numberBase10Format, fillChar), Either.fromOption(() => new MInputError.Type({
|
187
|
+
message: `${this.label}: value '${input}' cannot be converted to a(n) ${CVNumberBase10Format.toDescription(numberBase10Format)}`
|
188
|
+
})));
|
189
|
+
};
|
190
|
+
const numberFormatter = flow(CVNumberBase10Format.toNumberFormatter(numberBase10Format, pipe(fillChar, String.repeat(params.length))), Either.right);
|
191
|
+
return pipe(fixedLength(params), modify({
|
192
|
+
descriptorMapper: MString.append(` left-padded with '${fillChar}' to ${CVNumberBase10Format.toDescription(numberBase10Format)}`),
|
193
|
+
postParser: numberParser,
|
194
|
+
preFormatter: numberFormatter,
|
195
|
+
t1SchemaInstance: CVReal.SchemaFromSelf
|
196
|
+
}));
|
197
|
+
};
|
198
|
+
/**
|
199
|
+
* Builds a TemplatePlaceholder instance that parses/formats a Real provided in
|
200
|
+
* `numberBase10Format`.
|
201
|
+
*
|
202
|
+
* @category Constructors
|
203
|
+
*/
|
204
|
+
export const real = ({
|
205
|
+
name,
|
206
|
+
numberBase10Format
|
207
|
+
}) => {
|
208
|
+
const numberParser = CVNumberBase10Format.toRealExtractor(numberBase10Format);
|
209
|
+
const numberFormatter = CVNumberBase10Format.toNumberFormatter(numberBase10Format);
|
210
|
+
const flippedTakeRightBut = Function.flip(MString.takeRightBut);
|
211
|
+
return make({
|
212
|
+
name,
|
213
|
+
description: `${CVNumberBase10Format.toDescription(numberBase10Format)}`,
|
214
|
+
parser: function (text) {
|
215
|
+
return pipe(text, numberParser, Either.fromOption(() => new MInputError.Type({
|
216
|
+
message: `${this.label} contains '${text}' from the start of which a(n) ${CVNumberBase10Format.toDescription(numberBase10Format)} could not be extracted`
|
217
|
+
})), Either.map(Tuple.mapSecond(flow(String.length, flippedTakeRightBut(text)))));
|
218
|
+
},
|
219
|
+
formatter: flow(numberFormatter, Either.right),
|
220
|
+
schemaInstance: CVReal.SchemaFromSelf
|
221
|
+
});
|
222
|
+
};
|
223
|
+
/**
|
224
|
+
* Builds a TemplatePlaceholder instance that works as a map:
|
225
|
+
*
|
226
|
+
* The parser expects one of the keys of `keyValuePairs` and will return the associated value. The
|
227
|
+
* formatter expects one of the values of `keyValuePairs` and will return the associated key.
|
228
|
+
*
|
229
|
+
* `keyValuePairs` should define a bijection (each key and each value must be present only once). It
|
230
|
+
* is best if the type of the values defines a toString method. Value equality is checked with The
|
231
|
+
* Effect Equal.equals function.
|
232
|
+
*
|
233
|
+
* `schemaInstance` is a Schema instance that transforms a value of type T into a value of type T.
|
234
|
+
* It is an optional parameter. You need only provide it if you intend to use a CVTemplate built
|
235
|
+
* from it within the Effect Schema module. In that case, you can build such a Schema with the
|
236
|
+
* Schema.declare function. If you don't provide it and use a CVTemplate built from it within the
|
237
|
+
* Effect Schema module, it will not work.
|
238
|
+
*
|
239
|
+
* @category Constructors
|
240
|
+
*/
|
241
|
+
export const mappedLiterals = ({
|
242
|
+
name,
|
243
|
+
keyValuePairs,
|
244
|
+
schemaInstance = Schema.declare(_input => false)
|
245
|
+
}) => {
|
246
|
+
const keys = pipe(keyValuePairs, Array.map(Tuple.getFirst), Array.join(', '), MString.prepend('['), MString.append(']'));
|
247
|
+
const values = pipe(keyValuePairs, Array.map(flow(Tuple.getSecond, MString.fromUnknown)), Array.join(', '), MString.prepend('['), MString.append(']'));
|
248
|
+
const valueNameMap = pipe(keyValuePairs, Array.map(Tuple.swap), HashMap.fromIterable);
|
249
|
+
const isTheStartOf = Function.flip(String.startsWith);
|
250
|
+
const flippedTakeRightBut = Function.flip(MString.takeRightBut);
|
251
|
+
return make({
|
252
|
+
name,
|
253
|
+
description: `from ${keys} to ${values}`,
|
254
|
+
parser: function (text) {
|
255
|
+
return pipe(keyValuePairs, Array.findFirst(flow(Tuple.getFirst, isTheStartOf(text))), Either.fromOption(() => new MInputError.Type({
|
256
|
+
message: `Expected remaining text for ${this.label} to start with one of ${keys}. Actual: '${text}'`
|
257
|
+
})), Either.map(MTuple.makeBothBy({
|
258
|
+
toFirst: Tuple.getSecond,
|
259
|
+
toSecond: flow(Tuple.getFirst, String.length, flippedTakeRightBut(text))
|
260
|
+
})));
|
261
|
+
},
|
262
|
+
formatter: function (value) {
|
263
|
+
return pipe(valueNameMap, HashMap.get(value), Either.fromOption(() => new MInputError.Type({
|
264
|
+
message: `${this.label}: expected one of ${values}. Actual: ${MString.fromUnknown(value)}`
|
265
|
+
})));
|
266
|
+
},
|
267
|
+
schemaInstance
|
268
|
+
});
|
269
|
+
};
|
270
|
+
/**
|
271
|
+
* Same as `mappedLiterals` but `T` is assumed to be `CVReal.Type` which should be the most usual
|
272
|
+
* use case
|
273
|
+
*
|
274
|
+
* @category Constructors
|
275
|
+
*/
|
276
|
+
export const realMappedLiterals = params => mappedLiterals({
|
277
|
+
...params,
|
278
|
+
schemaInstance: CVReal.SchemaFromSelf
|
279
|
+
});
|
280
|
+
/**
|
281
|
+
* Builds a TemplatePlaceholder instance that parses/formats the regular expression regExp. `regExp`
|
282
|
+
* must start with the ^ character. Otherwise, the parser and formatter will not work properly.
|
283
|
+
*
|
284
|
+
* @category Constructors
|
285
|
+
*/
|
286
|
+
export const fulfilling = ({
|
287
|
+
name,
|
288
|
+
regExp,
|
289
|
+
regExpDescriptor
|
290
|
+
}) => {
|
291
|
+
const flippedTakeRightBut = Function.flip(MString.takeRightBut);
|
292
|
+
const match = label => MInputError.match({
|
293
|
+
regExp,
|
294
|
+
regExpDescriptor,
|
295
|
+
name: label
|
296
|
+
});
|
297
|
+
return make({
|
298
|
+
name,
|
299
|
+
description: `${regExpDescriptor}`,
|
300
|
+
parser: function (text) {
|
301
|
+
return pipe(text, match(this.label), Either.map(MTuple.makeBothBy({
|
302
|
+
toFirst: Function.identity,
|
303
|
+
toSecond: flow(String.length, flippedTakeRightBut(text))
|
304
|
+
})));
|
305
|
+
},
|
306
|
+
formatter: function (text) {
|
307
|
+
return pipe(text, match(this.label), Either.filterOrLeft(MString.hasLength(text.length), () => new MInputError.Type({
|
308
|
+
message: `${this.label}: expected ${regExpDescriptor}. Actual: '${text}'`
|
309
|
+
})));
|
310
|
+
},
|
311
|
+
schemaInstance: Schema.String
|
312
|
+
});
|
313
|
+
};
|
314
|
+
/**
|
315
|
+
* Builds a TemplatePlaceholder instance that parses/formats a non-empty string made up of
|
316
|
+
* characters other than those contained in `forbiddenChars`. `forbiddenChars` should be an array of
|
317
|
+
* 1-character strings (will not throw otherwise but strange behaviors can be expected)
|
318
|
+
*
|
319
|
+
* @category Constructors
|
320
|
+
*/
|
321
|
+
export const anythingBut = ({
|
322
|
+
name,
|
323
|
+
forbiddenChars
|
324
|
+
}) => {
|
325
|
+
const forbiddenCharsAsString = pipe(forbiddenChars, Array.join("', '"), MString.prepend("[ '"), MString.append("' ]"));
|
326
|
+
return fulfilling({
|
327
|
+
name,
|
328
|
+
regExp: pipe(forbiddenChars, MRegExpString.notInRange, MRegExpString.oneOrMore, MRegExpString.atStart, MRegExp.fromRegExpString()),
|
329
|
+
regExpDescriptor: `a non-empty string containing non of the following characters: ${forbiddenCharsAsString}`
|
330
|
+
});
|
331
|
+
};
|
332
|
+
/**
|
333
|
+
* Builds a TemplatePlaceholder instance that parses/formats all the remaining text.
|
334
|
+
*
|
335
|
+
* @category Constructors
|
336
|
+
*/
|
337
|
+
export const toEnd = name => fulfilling({
|
338
|
+
name,
|
339
|
+
regExp: /^.*/,
|
340
|
+
regExpDescriptor: 'a string'
|
341
|
+
});
|
342
|
+
//# sourceMappingURL=TemplatePlaceholder.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TemplatePlaceholder.js","names":["MInputError","MInspectable","MPipeable","MRegExp","MRegExpString","MString","MStruct","MTuple","MTypes","Array","Either","flow","Function","HashMap","pipe","Predicate","Schema","String","Struct","Tuple","CVNumberBase10Format","CVReal","moduleTag","_TypeId","Symbol","for","has","u","hasProperty","proto","_N","covariantValue","_T","invariantValue","IdSymbol","getLabelledDescription","BaseProto","_make","params","objectFromDataAndProto","make","enrichWith","label","name","prepend","get","description","parser","formatter","schemaInstance","self","modify","descriptorMapper","postParser","preFormatter","t1SchemaInstance","text","flatMap","call","mapBoth","onFirst","t","onSecond","right","all","t1","undefined","fixedLength","length","splitAt","assertLength","expected","value","paddedFixedLength","trimmer","trim","padder","pad","append","PadPosition","toId","padPosition","fillChar","fixedLengthToReal","numberBase10Format","numberParser","input","toRealParser","fromOption","Type","message","toDescription","numberFormatter","toNumberFormatter","repeat","SchemaFromSelf","real","toRealExtractor","flippedTakeRightBut","flip","takeRightBut","map","mapSecond","mappedLiterals","keyValuePairs","declare","_input","keys","getFirst","join","values","getSecond","fromUnknown","valueNameMap","swap","fromIterable","isTheStartOf","startsWith","findFirst","makeBothBy","toFirst","toSecond","realMappedLiterals","fulfilling","regExp","regExpDescriptor","match","identity","filterOrLeft","hasLength","anythingBut","forbiddenChars","forbiddenCharsAsString","notInRange","oneOrMore","atStart","fromRegExpString","toEnd"],"sources":["../../esm/TemplatePlaceholder.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;AAeA,SACCA,WAAW,EACXC,YAAY,EACZC,SAAS,EACTC,OAAO,EACPC,aAAa,EACbC,OAAO,EACPC,OAAO,EACPC,MAAM,EACNC,MAAM,QACA,uBAAuB;AAE9B,SACCC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,QAAQ,EACRC,OAAO,EACPC,IAAI,EAEJC,SAAS,EACTC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,KAAK,QAEC,QAAQ;AAEf,OAAO,KAAKC,oBAAoB,MAAM,yBAAyB;AAC/D,OAAO,KAAKC,MAAM,MAAM,WAAW;AAEnC;;;;;AAKA,OAAO,MAAMC,SAAS,GAAG,6CAA6C;AACtE,MAAMC,OAAO,gBAAkBC,MAAM,CAACC,GAAG,CAACH,SAAS,CAAY;AAqF/D;;;;;AAKA,OAAO,MAAMI,GAAG,GAAIC,CAAU,IAAiCZ,SAAS,CAACa,WAAW,CAACD,CAAC,EAAEJ,OAAO,CAAC;AAEhG;AACA;AACA,MAAMM,KAAK,GAAmC;EAC7C,CAACN,OAAO,GAAG;IAAEO,EAAE,EAAEtB,MAAM,CAACuB,cAAc;IAAEC,EAAE,EAAExB,MAAM,CAACyB;EAAc,CAAE;EACnE,CAAChC,YAAY,CAACiC,QAAQ,IAAC;IACtB,OAAOC,sBAAsB,CAAC,IAAI,CAAC;EACpC,CAAC;EACD,iBAAGlC,YAAY,CAACmC,SAAS,CAACd,SAAS,CAAC;EACpC,GAAGpB,SAAS,CAACkC;CACb;AAED,MAAMC,KAAK,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C,IAAIpE,WAAW,CAACyF,IAAI,CAAC;QACpBC,OAAO,EAAE,GAAG,IAAI,CAAChD,KAAK,cAAcmF,gBAAgB,cAAcrE,IAAI;OACtE,CAAC,CACH,CACD;IACF,CAAC;IACDP,cAAc,EAAEjC,MAAM,CAACC;GACvB,CAAC;AACH,CAAC;AAED;;;;;;;AAOA,OAAO,MAAMiH,WAAW,GAAGA,CAAyB;EACnDvF,IAAI;EACJwF;AAAc,CAId,KAAqB;EACrB,MAAMC,sBAAsB,GAAGtH,IAAI,CAClCqH,cAAc,EACd1H,KAAK,CAACoG,IAAI,CAAC,MAAM,CAAC,EAClBxG,OAAO,CAACuC,OAAO,CAAC,KAAK,CAAC,EACtBvC,OAAO,CAACyE,MAAM,CAAC,KAAK,CAAC,CACrB;EACD,OAAO6C,UAAU,CAAC;IACjBhF,IAAI;IACJiF,MAAM,EAAE9G,IAAI,CACXqH,cAAc,EACd/H,aAAa,CAACiI,UAAU,EACxBjI,aAAa,CAACkI,SAAS,EACvBlI,aAAa,CAACmI,OAAO,EACrBpI,OAAO,CAACqI,gBAAgB,EAAE,CAC1B;IACDX,gBAAgB,EAAE,kEAAkEO,sBAAsB;GAC1G,CAAC;AACH,CAAC;AAED;;;;;AAKA,OAAO,MAAMK,KAAK,GAA4B9F,IAAO,IACpDgF,UAAU,CAAC;EACVhF,IAAI;EACJiF,MAAM,EAAE,KAAK;EACbC,gBAAgB,EAAE;CAClB,CAAC","ignoreList":[]}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
/**
|
2
|
+
* This module implements a TemplateSeparator type which is a sub-type of the TemplatePart type (see
|
3
|
+
* TemplatePart.ts)
|
4
|
+
*
|
5
|
+
* A TemplateSeparator represents the immutable part of a template. Upon parsing, we must check that
|
6
|
+
* it is present as is in the text. Upon formatting, it must be inserted as is into the text. A
|
7
|
+
* Separator contains no valuable information
|
8
|
+
*/
|
9
|
+
import { MInputError, MInspectable, MPipeable, MString, MTypes } from '@parischap/effect-lib';
|
10
|
+
import { Either, flow, Function, Predicate, Struct } from 'effect';
|
11
|
+
/**
|
12
|
+
* Module tag
|
13
|
+
*
|
14
|
+
* @category Module markers
|
15
|
+
*/
|
16
|
+
export const moduleTag = '@parischap/conversions/TemplateSeparator/';
|
17
|
+
const _TypeId = /*#__PURE__*/Symbol.for(moduleTag);
|
18
|
+
/**
|
19
|
+
* Type guard
|
20
|
+
*
|
21
|
+
* @category Guards
|
22
|
+
*/
|
23
|
+
export const has = u => Predicate.hasProperty(u, _TypeId);
|
24
|
+
/** Proto */
|
25
|
+
const proto = {
|
26
|
+
[_TypeId]: _TypeId,
|
27
|
+
[MInspectable.IdSymbol]() {
|
28
|
+
return this.value;
|
29
|
+
},
|
30
|
+
... /*#__PURE__*/MInspectable.BaseProto(moduleTag),
|
31
|
+
...MPipeable.BaseProto
|
32
|
+
};
|
33
|
+
const _make = params => MTypes.objectFromDataAndProto(proto, params);
|
34
|
+
/**
|
35
|
+
* Builds a Separator instance that parses/formats a given string.
|
36
|
+
*
|
37
|
+
* @category Constructors
|
38
|
+
*/
|
39
|
+
export const make = value => _make({
|
40
|
+
value,
|
41
|
+
parser: pos => flow(MInputError.assertStartsWith({
|
42
|
+
startString: value,
|
43
|
+
name: `remaining text for separator at position ${pos}`
|
44
|
+
}), Either.map(MString.takeRightBut(value.length))),
|
45
|
+
formatter: Function.constant(value)
|
46
|
+
});
|
47
|
+
/**
|
48
|
+
* Returns the `value` property of `self`
|
49
|
+
*
|
50
|
+
* @category Destructors
|
51
|
+
*/
|
52
|
+
export const value = /*#__PURE__*/Struct.get('value');
|
53
|
+
/**
|
54
|
+
* Returns the `parser` property of `self`
|
55
|
+
*
|
56
|
+
* @category Destructors
|
57
|
+
*/
|
58
|
+
export const parser = /*#__PURE__*/Struct.get('parser');
|
59
|
+
/**
|
60
|
+
* Returns the `formatter` property of `self`
|
61
|
+
*
|
62
|
+
* @category Destructors
|
63
|
+
*/
|
64
|
+
export const formatter = /*#__PURE__*/Struct.get('formatter');
|
65
|
+
/**
|
66
|
+
* Slash Separator instance
|
67
|
+
*
|
68
|
+
* @category Instances
|
69
|
+
*/
|
70
|
+
export const slash = /*#__PURE__*/make('/');
|
71
|
+
/**
|
72
|
+
* Backslash Separator instance
|
73
|
+
*
|
74
|
+
* @category Instances
|
75
|
+
*/
|
76
|
+
export const backslash = /*#__PURE__*/make('\\');
|
77
|
+
/**
|
78
|
+
* Dot Separator instance
|
79
|
+
*
|
80
|
+
* @category Instances
|
81
|
+
*/
|
82
|
+
export const dot = /*#__PURE__*/make('.');
|
83
|
+
/**
|
84
|
+
* Hyphen Separator instance
|
85
|
+
*
|
86
|
+
* @category Instances
|
87
|
+
*/
|
88
|
+
export const hyphen = /*#__PURE__*/make('-');
|
89
|
+
/**
|
90
|
+
* Colon Separator instance
|
91
|
+
*
|
92
|
+
* @category Instances
|
93
|
+
*/
|
94
|
+
export const colon = /*#__PURE__*/make(':');
|
95
|
+
/**
|
96
|
+
* Comma Separator instance
|
97
|
+
*
|
98
|
+
* @category Instances
|
99
|
+
*/
|
100
|
+
export const comma = /*#__PURE__*/make(',');
|
101
|
+
/**
|
102
|
+
* Space Separator instance
|
103
|
+
*
|
104
|
+
* @category Instances
|
105
|
+
*/
|
106
|
+
export const space = /*#__PURE__*/make(' ');
|
107
|
+
//# sourceMappingURL=TemplateSeparator.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TemplateSeparator.js","names":["MInputError","MInspectable","MPipeable","MString","MTypes","Either","flow","Function","Predicate","Struct","moduleTag","_TypeId","Symbol","for","has","u","hasProperty","proto","IdSymbol","value","BaseProto","_make","params","objectFromDataAndProto","make","parser","pos","assertStartsWith","startString","name","map","takeRightBut","length","formatter","constant","get","slash","backslash","dot","hyphen","colon","comma","space"],"sources":["../../esm/TemplateSeparator.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;AASA,SAASA,WAAW,EAAEC,YAAY,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,uBA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,MAAMF,SAAS,gBAAgDxB,MAAM,CAAC0B,GAAG,CAAC,WAAW,CAAC;AAE7F;;;;;AAKA,OAAO,MAAMC,KAAK,gBAASZ,IAAI,CAAC,GAAG,CAAC;AAEpC;;;;;AAKA,OAAO,MAAMa,SAAS,gBAASb,IAAI,CAAC,IAAI,CAAC;AAEzC;;;;;AAKA,OAAO,MAAMc,GAAG,gBAASd,IAAI,CAAC,GAAG,CAAC;AAElC;;;;;AAKA,OAAO,MAAMe,MAAM,gBAASf,IAAI,CAAC,GAAG,CAAC;AAErC;;;;;AAKA,OAAO,MAAMgB,KAAK,gBAAShB,IAAI,CAAC,GAAG,CAAC;AAEpC;;;;;AAKA,OAAO,MAAMiB,KAAK,gBAASjB,IAAI,CAAC,GAAG,CAAC;AAEpC;;;;;AAKA,OAAO,MAAMkB,KAAK,gBAASlB,IAAI,CAAC,GAAG,CAAC","ignoreList":[]}
|
package/esm/index.js
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
export * as CVBigDecimal from './BigDecimal.js';
|
2
|
+
export * as CVBigInt from './BigInt.js';
|
3
|
+
export * as CVDateTime from './DateTime.js';
|
4
|
+
export * as CVDateTimeFormat from './DateTimeFormat.js';
|
5
|
+
export * as CVDateTimeFormatContext from './DateTimeFormatContext.js';
|
6
|
+
export * as CVEmail from './Email.js';
|
7
|
+
export * as CVInteger from './Integer.js';
|
8
|
+
export * as CVNumberBase10Format from './NumberBase10Format.js';
|
9
|
+
export * as CVPositiveInteger from './PositiveInteger.js';
|
10
|
+
export * as CVPositiveReal from './PositiveReal.js';
|
11
|
+
export * as CVReal from './Real.js';
|
12
|
+
export * as CVRoundingMode from './RoundingMode.js';
|
13
|
+
export * as CVRoundingOption from './RoundingOption.js';
|
14
|
+
export * as CVSchema from './Schema.js';
|
15
|
+
export * as CVSemVer from './SemVer.js';
|
16
|
+
export * as CVTemplate from './Template.js';
|
17
|
+
export * as CVTemplatePart from './TemplatePart.js';
|
18
|
+
export * as CVTemplateParts from './TemplateParts.js';
|
19
|
+
export * as CVTemplatePlaceholder from './TemplatePlaceholder.js';
|
20
|
+
export * as CVTemplateSeparator from './TemplateSeparator.js';
|
21
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","names":["CVBigDecimal","CVBigInt","CVDateTime","CVDateTimeFormat","CVDateTimeFormatContext","CVEmail","CVInteger","CVNumberBase10Format","CVPositiveInteger","CVPositiveReal","CVReal","CVRoundingMode","CVRoundingOption","CVSchema","CVSemVer","CVTemplate","CVTemplatePart","CVTemplateParts","CVTemplatePlaceholder","CVTemplateSeparator"],"sources":["../../esm/index.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,YAAY,MAAM,iBAAiB;AAC/C,OAAO,KAAKC,QAAQ,MAAM,aAAa;AACvC,OAAO,KAAKC,UAAU,MAAM,eAAe;AAC3C,OAAO,KAAKC,gBAAgB,MAAM,qBAAqB;AACvD,OAAO,KAAKC,uBAAuB,MAAM,4BAA4B;AACrE,OAAO,KAAKC,OAAO,MAAM,YAAY;AACrC,OAAO,KAAKC,SAAS,MAAM,cAAc;AACzC,OAAO,KAAKC,oBAAoB,MAAM,yBAAyB;AAC/D,OAAO,KAAKC,iBAAiB,MAAM,sBAAsB;AACzD,OAAO,KAAKC,cAAc,MAAM,mBAAmB;AACnD,OAAO,KAAKC,MAAM,MAAM,WAAW;AACnC,OAAO,KAAKC,cAAc,MAAM,mBAAmB;AACnD,OAAO,KAAKC,gBAAgB,MAAM,qBAAqB;AACvD,OAAO,KAAKC,QAAQ,MAAM,aAAa;AACvC,OAAO,KAAKC,QAAQ,MAAM,aAAa;AACvC,OAAO,KAAKC,UAAU,MAAM,eAAe;AAC3C,OAAO,KAAKC,cAAc,MAAM,mBAAmB;AACnD,OAAO,KAAKC,eAAe,MAAM,oBAAoB;AACrD,OAAO,KAAKC,qBAAqB,MAAM,0BAA0B;AACjE,OAAO,KAAKC,mBAAmB,MAAM,wBAAwB","ignoreList":[]}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/**
|
2
|
+
* A module that implements an integer brand (non-null fractional part disallowed). Not exported.
|
3
|
+
* Only used internally
|
4
|
+
*/
|
5
|
+
import { MNumber, MString } from '@parischap/effect-lib';
|
6
|
+
import { Brand, flow } from 'effect';
|
7
|
+
/**
|
8
|
+
* Module tag
|
9
|
+
*
|
10
|
+
* @internal
|
11
|
+
*/
|
12
|
+
const _moduleTag = '@parischap/conversions/Int/';
|
13
|
+
/**
|
14
|
+
* Module TypeId
|
15
|
+
*
|
16
|
+
* @internal
|
17
|
+
*/
|
18
|
+
export const _TypeId = /*#__PURE__*/Symbol.for(_moduleTag);
|
19
|
+
/**
|
20
|
+
* Brand constructor. Should not be used directly
|
21
|
+
*
|
22
|
+
* @internal
|
23
|
+
*/
|
24
|
+
export const constructor = /*#__PURE__*/Brand.refined(MNumber.isInt, /*#__PURE__*/flow(/*#__PURE__*/MString.fromNumber(10), /*#__PURE__*/MString.prepend("'"), /*#__PURE__*/MString.append("' does not represent an integer"), Brand.error));
|
25
|
+
/**
|
26
|
+
* Constructs an Option of an Int from a number.
|
27
|
+
*
|
28
|
+
* @internal
|
29
|
+
*/
|
30
|
+
export const fromNumberOption = /*#__PURE__*/constructor.option.bind(constructor);
|
31
|
+
/**
|
32
|
+
* Constructs an Either of an Int from a number.
|
33
|
+
*
|
34
|
+
* @internal
|
35
|
+
*/
|
36
|
+
export const fromNumber = /*#__PURE__*/constructor.either.bind(constructor);
|
37
|
+
/**
|
38
|
+
* Constructs an Int from a number or throws
|
39
|
+
*
|
40
|
+
* @internal
|
41
|
+
*/
|
42
|
+
export const fromNumberOrThrow = constructor;
|
43
|
+
//# sourceMappingURL=Int.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Int.js","names":["MNumber","MString","Brand","flow","_moduleTag","_TypeId","Symbol","for","constructor","refined","isInt","fromNumber","prepend","append","error","fromNumberOption","option","bind","either","fromNumberOrThrow"],"sources":["../../../esm/internal/Int.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;AAKA,SAASA,OAAO,EAAEC,OAAO,QAAgB,uBAAuB;AAChE,SAASC,KAAK,EAAUC,IAAI,QAAgB,QAAQ;AAEpD;;;;;AAKA,MAAMC,UAAU,GAAG,6BAA6B;AAEhD;;;;;AAKA,OAAO,MAAMC,OAAO,gBAAkBC,MAAM,CAACC,GAAG,CAACH,UAAU,CAAY;AAUvE;;;;;AAKA,OAAO,MAAMI,WAAW,gBAAGN,KAAK,CAACO,OAAO,CACvCT,OAAO,CAACU,KAAK,eACbP,IAAI,cACHF,OAAO,CAACU,UAAU,CAAC,EAAE,CAAC,eACtBV,OAAO,CAACW,OAAO,CAAC,GAAG,CAAC,eACpBX,OAAO,CAACY,MAAM,CAAC,iCAAiC,CAAC,EACjDX,KAAK,CAACY,KAAK,CACX,CACD;AAED;;;;;AAKA,OAAO,MAAMC,gBAAgB,gBAGzBP,WAAW,CAACQ,MAAM,CAACC,IAAI,CAACT,WAAW,CAAC;AAExC;;;;;AAKA,OAAO,MAAMG,UAAU,gBAGnBH,WAAW,CAACU,MAAM,CAACD,IAAI,CAACT,WAAW,CAAC;AAExC;;;;;AAKA,OAAO,MAAMW,iBAAiB,GAAwCX,WAAW","ignoreList":[]}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/**
|
2
|
+
* A module that implements a positive number brand (negative number disallowed). Not exported. Only
|
3
|
+
* used internally
|
4
|
+
*/
|
5
|
+
import { MString } from '@parischap/effect-lib';
|
6
|
+
import { Brand, flow, Number } from 'effect';
|
7
|
+
/**
|
8
|
+
* Module tag
|
9
|
+
*
|
10
|
+
* @internal
|
11
|
+
*/
|
12
|
+
export const _moduleTag = '@parischap/conversions/Positive/';
|
13
|
+
/**
|
14
|
+
* Module TypeId
|
15
|
+
*
|
16
|
+
* @internal
|
17
|
+
*/
|
18
|
+
export const _TypeId = /*#__PURE__*/Symbol.for(_moduleTag);
|
19
|
+
/**
|
20
|
+
* Brand constructor. Should not be used directly
|
21
|
+
*
|
22
|
+
* @internal
|
23
|
+
*/
|
24
|
+
export const constructor = /*#__PURE__*/Brand.refined(/*#__PURE__*/Number.greaterThanOrEqualTo(0), /*#__PURE__*/flow(/*#__PURE__*/MString.fromNumber(10), /*#__PURE__*/MString.prepend("'"), /*#__PURE__*/MString.append("' is not positive"), Brand.error));
|
25
|
+
/**
|
26
|
+
* Constructs an Option of a Positive from a number.
|
27
|
+
*
|
28
|
+
* @internal
|
29
|
+
*/
|
30
|
+
export const fromNumberOption = /*#__PURE__*/constructor.option.bind(constructor);
|
31
|
+
/**
|
32
|
+
* Constructs an Either of a Positive from a number.
|
33
|
+
*
|
34
|
+
* @internal
|
35
|
+
*/
|
36
|
+
export const fromNumber = /*#__PURE__*/constructor.either.bind(constructor);
|
37
|
+
/**
|
38
|
+
* Constructs a Positive from a number or throws
|
39
|
+
*
|
40
|
+
* @internal
|
41
|
+
*/
|
42
|
+
export const fromNumberOrThrow = constructor;
|
43
|
+
//# sourceMappingURL=Positive.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Positive.js","names":["MString","Brand","flow","Number","_moduleTag","_TypeId","Symbol","for","constructor","refined","greaterThanOrEqualTo","fromNumber","prepend","append","error","fromNumberOption","option","bind","either","fromNumberOrThrow"],"sources":["../../../esm/internal/Positive.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;AAKA,SAASA,OAAO,QAAgB,uBAAuB;AACvD,SAASC,KAAK,EAAUC,IAAI,EAAEC,MAAM,QAAgB,QAAQ;AAE5D;;;;;AAKA,OAAO,MAAMC,UAAU,GAAG,kCAAkC;AAE5D;;;;;AAKA,OAAO,MAAMC,OAAO,gBAAkBC,MAAM,CAACC,GAAG,CAACH,UAAU,CAAY;AAUvE;;;;;AAKA,OAAO,MAAMI,WAAW,gBAAGP,KAAK,CAACQ,OAAO,cACvCN,MAAM,CAACO,oBAAoB,CAAC,CAAC,CAAC,eAC9BR,IAAI,cACHF,OAAO,CAACW,UAAU,CAAC,EAAE,CAAC,eACtBX,OAAO,CAACY,OAAO,CAAC,GAAG,CAAC,eACpBZ,OAAO,CAACa,MAAM,CAAC,mBAAmB,CAAC,EACnCZ,KAAK,CAACa,KAAK,CACX,CACD;AAED;;;;;AAKA,OAAO,MAAMC,gBAAgB,gBAGzBP,WAAW,CAACQ,MAAM,CAACC,IAAI,CAACT,WAAW,CAAC;AAExC;;;;;AAKA,OAAO,MAAMG,UAAU,gBAGnBH,WAAW,CAACU,MAAM,CAACD,IAAI,CAACT,WAAW,CAAC;AAExC;;;;;AAKA,OAAO,MAAMW,iBAAiB,GAAwCX,WAAW","ignoreList":[]}
|
package/esm/package.json
ADDED
package/package.json
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
{
|
2
|
+
"name": "@parischap/conversions",
|
3
|
+
"author": "Jérôme MARTIN",
|
4
|
+
"license": "MIT",
|
5
|
+
"bugs": {
|
6
|
+
"url": "https://github.com/parischap/effect-libs/issues"
|
7
|
+
},
|
8
|
+
"funding": [
|
9
|
+
{
|
10
|
+
"type": "ko-fi",
|
11
|
+
"url": "https://ko-fi.com/parischap"
|
12
|
+
}
|
13
|
+
],
|
14
|
+
"keywords": [
|
15
|
+
"number",
|
16
|
+
"text",
|
17
|
+
"conversion",
|
18
|
+
"n2t",
|
19
|
+
"num2text",
|
20
|
+
"convert",
|
21
|
+
"typescript",
|
22
|
+
"effect",
|
23
|
+
"effect",
|
24
|
+
"typescript",
|
25
|
+
"functional-programming"
|
26
|
+
],
|
27
|
+
"description": "A functional library to convert number and dates to string and vice-versa",
|
28
|
+
"module": "./esm/index.js",
|
29
|
+
"exports": {
|
30
|
+
".": {
|
31
|
+
"default": "./cjs/index.js",
|
32
|
+
"import": "./esm/index.js",
|
33
|
+
"types": "./dts/index.d.ts"
|
34
|
+
}
|
35
|
+
},
|
36
|
+
"peerDependencies": {
|
37
|
+
"@parischap/effect-lib": "^0.6.0",
|
38
|
+
"effect": "^3.17.13"
|
39
|
+
},
|
40
|
+
"repository": {
|
41
|
+
"type": "git",
|
42
|
+
"url": "git+https://github.com/parischap/effect-libs.git",
|
43
|
+
"directory": "packages/conversions"
|
44
|
+
},
|
45
|
+
"homepage": "https://github.com/parischap/effect-libs/tree/master/packages/conversions",
|
46
|
+
"version": "0.1.0",
|
47
|
+
"main": "./cjs/index.js",
|
48
|
+
"types": "./dts/index.d.ts"
|
49
|
+
}
|