@parischap/conversions 0.1.0 → 0.2.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.
Files changed (125) hide show
  1. package/README.md +51 -50
  2. package/cjs/BigDecimal.js +2 -2
  3. package/cjs/BigInt.js +7 -5
  4. package/cjs/BigInt.js.map +1 -1
  5. package/cjs/DateTime.js +144 -136
  6. package/cjs/DateTime.js.map +1 -1
  7. package/cjs/DateTimeFormat.js +7 -2
  8. package/cjs/DateTimeFormat.js.map +1 -1
  9. package/cjs/DateTimeFormatContext.js +11 -6
  10. package/cjs/DateTimeFormatContext.js.map +1 -1
  11. package/cjs/Email.js +11 -15
  12. package/cjs/Email.js.map +1 -1
  13. package/cjs/Integer.js +33 -23
  14. package/cjs/Integer.js.map +1 -1
  15. package/cjs/NumberBase10Format.js +65 -65
  16. package/cjs/PositiveInteger.js +44 -29
  17. package/cjs/PositiveInteger.js.map +1 -1
  18. package/cjs/PositiveReal.js +34 -24
  19. package/cjs/PositiveReal.js.map +1 -1
  20. package/cjs/Real.js +29 -18
  21. package/cjs/Real.js.map +1 -1
  22. package/cjs/RoundingMode.js +7 -4
  23. package/cjs/RoundingMode.js.map +1 -1
  24. package/cjs/RoundingOption.js +6 -6
  25. package/cjs/RoundingOption.js.map +1 -1
  26. package/cjs/Schema.js +29 -28
  27. package/cjs/Schema.js.map +1 -1
  28. package/cjs/SemVer.js +19 -20
  29. package/cjs/SemVer.js.map +1 -1
  30. package/cjs/Template.js +36 -31
  31. package/cjs/Template.js.map +1 -1
  32. package/cjs/TemplatePart.js +4 -4
  33. package/cjs/TemplateParts.js +3 -2
  34. package/cjs/TemplateParts.js.map +1 -1
  35. package/cjs/TemplatePlaceholder.js +56 -45
  36. package/cjs/TemplatePlaceholder.js.map +1 -1
  37. package/cjs/TemplateSeparator.js +17 -24
  38. package/cjs/TemplateSeparator.js.map +1 -1
  39. package/cjs/internal/Int.js +5 -8
  40. package/cjs/internal/Int.js.map +1 -1
  41. package/cjs/internal/Positive.js +5 -8
  42. package/cjs/internal/Positive.js.map +1 -1
  43. package/dts/BigDecimal.d.ts +2 -2
  44. package/dts/BigDecimal.d.ts.map +1 -1
  45. package/dts/BigInt.d.ts +7 -5
  46. package/dts/BigInt.d.ts.map +1 -1
  47. package/dts/DateTime.d.ts +145 -137
  48. package/dts/DateTime.d.ts.map +1 -1
  49. package/dts/DateTimeFormat.d.ts +7 -2
  50. package/dts/DateTimeFormat.d.ts.map +1 -1
  51. package/dts/DateTimeFormatContext.d.ts +17 -12
  52. package/dts/DateTimeFormatContext.d.ts.map +1 -1
  53. package/dts/Email.d.ts +16 -13
  54. package/dts/Email.d.ts.map +1 -1
  55. package/dts/Integer.d.ts +43 -21
  56. package/dts/Integer.d.ts.map +1 -1
  57. package/dts/NumberBase10Format.d.ts +68 -68
  58. package/dts/PositiveInteger.d.ts +54 -27
  59. package/dts/PositiveInteger.d.ts.map +1 -1
  60. package/dts/PositiveReal.d.ts +44 -22
  61. package/dts/PositiveReal.d.ts.map +1 -1
  62. package/dts/Real.d.ts +39 -16
  63. package/dts/Real.d.ts.map +1 -1
  64. package/dts/RoundingMode.d.ts +6 -3
  65. package/dts/RoundingMode.d.ts.map +1 -1
  66. package/dts/RoundingOption.d.ts +6 -6
  67. package/dts/Schema.d.ts +32 -33
  68. package/dts/Schema.d.ts.map +1 -1
  69. package/dts/SemVer.d.ts +25 -13
  70. package/dts/SemVer.d.ts.map +1 -1
  71. package/dts/Template.d.ts +30 -29
  72. package/dts/Template.d.ts.map +1 -1
  73. package/dts/TemplatePart.d.ts +4 -4
  74. package/dts/TemplateParts.d.ts +4 -3
  75. package/dts/TemplateParts.d.ts.map +1 -1
  76. package/dts/TemplatePlaceholder.d.ts +56 -44
  77. package/dts/TemplatePlaceholder.d.ts.map +1 -1
  78. package/dts/TemplateSeparator.d.ts +9 -51
  79. package/dts/TemplateSeparator.d.ts.map +1 -1
  80. package/dts/internal/Int.d.ts +0 -4
  81. package/dts/internal/Int.d.ts.map +1 -1
  82. package/dts/internal/Positive.d.ts +0 -4
  83. package/dts/internal/Positive.d.ts.map +1 -1
  84. package/esm/BigDecimal.js +2 -2
  85. package/esm/BigInt.js +7 -5
  86. package/esm/BigInt.js.map +1 -1
  87. package/esm/DateTime.js +144 -136
  88. package/esm/DateTime.js.map +1 -1
  89. package/esm/DateTimeFormat.js +7 -2
  90. package/esm/DateTimeFormat.js.map +1 -1
  91. package/esm/DateTimeFormatContext.js +11 -6
  92. package/esm/DateTimeFormatContext.js.map +1 -1
  93. package/esm/Email.js +10 -13
  94. package/esm/Email.js.map +1 -1
  95. package/esm/Integer.js +33 -23
  96. package/esm/Integer.js.map +1 -1
  97. package/esm/NumberBase10Format.js +65 -65
  98. package/esm/PositiveInteger.js +44 -29
  99. package/esm/PositiveInteger.js.map +1 -1
  100. package/esm/PositiveReal.js +34 -24
  101. package/esm/PositiveReal.js.map +1 -1
  102. package/esm/Real.js +29 -18
  103. package/esm/Real.js.map +1 -1
  104. package/esm/RoundingMode.js +6 -3
  105. package/esm/RoundingMode.js.map +1 -1
  106. package/esm/RoundingOption.js +6 -6
  107. package/esm/RoundingOption.js.map +1 -1
  108. package/esm/Schema.js +33 -34
  109. package/esm/Schema.js.map +1 -1
  110. package/esm/SemVer.js +18 -18
  111. package/esm/SemVer.js.map +1 -1
  112. package/esm/Template.js +36 -31
  113. package/esm/Template.js.map +1 -1
  114. package/esm/TemplatePart.js +4 -4
  115. package/esm/TemplateParts.js +3 -2
  116. package/esm/TemplateParts.js.map +1 -1
  117. package/esm/TemplatePlaceholder.js +55 -44
  118. package/esm/TemplatePlaceholder.js.map +1 -1
  119. package/esm/TemplateSeparator.js +16 -24
  120. package/esm/TemplateSeparator.js.map +1 -1
  121. package/esm/internal/Int.js +5 -7
  122. package/esm/internal/Int.js.map +1 -1
  123. package/esm/internal/Positive.js +5 -7
  124. package/esm/internal/Positive.js.map +1 -1
  125. package/package.json +2 -2
package/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  # conversions
4
4
 
5
- An [Effect](https://effect.website/docs/introduction) library to replace the native javascript INTL namespace.
5
+ An [`Effect`](https://effect.website/docs/introduction) library to partially replace the native javascript INTL namespace.
6
6
 
7
7
  Non machine-dependent, safe, bidirectional (implements parsing and formatting), tested and documented, 100% Typescript, 100% functional.
8
8
 
9
- Can also come in handy to non-Effect users.
9
+ Can also come in handy to non-`Effect` users.
10
10
 
11
11
  </div>
12
12
 
@@ -35,7 +35,7 @@ Depending on the package manager you use, run one of the following commands in y
35
35
  yarn add effect @parischap/effect-lib @parischap/conversions
36
36
  ```
37
37
 
38
- Bundled and tree-shaken, this module is only about [30kB](https://bundlephobia.com/package/@parischap/conversions). Minified and gzipped, it falls to [7kB](https://bundlephobia.com/package/@parischap/conversions)! (source bundlephobia)
38
+ We use two peerDependencies. If you are not an `Effect` user, the size may seem important. But, in fact, we use little of each peerDependency. Bundled and tree-shaken, this module is only about [69kB](https://bundlephobia.com/package/@parischap/conversions). Minified and gzipped, it falls to [15kB](https://bundlephobia.com/package/@parischap/conversions)! (source bundlephobia)
39
39
 
40
40
  ## API
41
41
 
@@ -45,14 +45,14 @@ After reading this introduction, you may take a look at the [API](https://parisc
45
45
 
46
46
  This package contains:
47
47
 
48
- - a [module to round numbers and BigDecimal's](#RoundingModule) with the same rounding options as those offered by the javascript INTL namespace: Ceil, Floor, Expand, Trunc, HalfCeil...
49
- - a safe, easy-to-use [number/BigDecimal parser/formatter](#NumberParserFormatter) with almost all the options offered by the javascript INTL namespace: choice of the thousand separator, of the fractional separator, of the minimum and maximum number of fractional digits, of the rounding mode, of the sign display mode, of whether to show or not the integer part when it's zero, of whether to use a scientific or engineering notation, of the character to use as exponent mark... It can also be used as a Schema instead of the existing Schema.NumberFromString transformer.
50
- - an equivalent to the PHP [sprintf and sscanf functions](#Templating) with real typing of the placeholders. Although Effect Schema does offer the [TemplateLiteralParser API](https://effect.website/docs/schema/basic-usage/#templateliteralparser), the latter does not provide a solution to situations such as fixed length fields (potentially padded), numbers formatted otherwise than in the English format... It can also be used as a Schema
51
- - a very easy to use [DateTime module](#DateTimeModule) that implements natively the Iso calendar (Iso year and Iso week). It is also faster than its Effect counterpart because it implements an internal state that's only used to speed up calculation times (but does not alter the result of functions; so DateTime functions can be viewed as pure from a user's perspective). It can therefore be useful in applications where time is of essence.
52
- - a [DateTime parser/formatter](#DateTimeParserFormatter) which supports many of the available [unicode tokens](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table). It can also be used as a Schema instead of the existing Schema.Date transformer.
53
- - a few [brands](#Branding) which come in handy in many projects such as email, semantic versioning, integer numbers, positive integer numbers, real numbers and positive real numbers. All these brands are also defined as Schemas.
48
+ - a [module to round numbers and `BigDecimal`'s](#RoundingModule) with the same rounding options as those offered by the javascript INTL namespace: Ceil, Floor, Expand, Trunc, HalfCeil...
49
+ - a safe, easy-to-use [number/`BigDecimal` parser/formatter](#NumberParserFormatter) with almost all the options offered by the javascript INTL namespace: choice of the thousand separator, of the fractional separator, of the minimum and maximum number of fractional digits, of the rounding mode, of the sign display mode, of whether to show or not the integer part when it's zero, of whether to use a scientific or engineering notation, of the character to use as exponent mark... It can also be used as a `Schema` instead of the `Effect.Schema.NumberFromString` transformer.
50
+ - an equivalent to the PHP [sprintf and sscanf functions](#Templating) with real typing of the placeholders. Although `Effect.Schema` does offer the [`TemplateLiteralParser` API](https://effect.website/docs/schema/basic-usage/#templateliteralparser), the latter does not provide a solution to situations such as fixed length fields (potentially padded), numbers formatted otherwise than in the English format... This module can also be used as a `Schema`.
51
+ - a very easy to use [`CVDateTime` module](#DateTimeModule) that implements natively the Iso calendar (Iso year and Iso week). It is also faster than its `Effect` counterpart as it implements an internal state that's only used to speed up calculation times (but does not alter the result of functions; so `CVDateTime` functions can be viewed as pure from a user's perspective). It can therefore be useful in applications where time is of essence.
52
+ - a [`CVDateTime` parser/formatter](#DateTimeParserFormatter) which supports many of the available [unicode tokens](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table). It can also be used as a `Schema` instead of the `Effect.Schema.Date` transformer.
53
+ - a few [brands](#Branding) which come in handy in many projects such as email, semantic versioning, integer numbers, positive integer numbers, real numbers and positive real numbers. All these brands are also defined as `Schemas`. Please read the [`Effect` documentation about Branding](https://effect.website/docs/code-style/branded-types/) if you are not familiar with this concept
54
54
 
55
- Most functions of this package return an Either or an Option to signify the possibility of an error. However, if you are not an Effect user and do not care to learn more about it, you can simply use the `OrThrow` variant of the function. For instance, use `CVDateTime.setWeekdayOrThrow` instead of `CVDateTime.setWeekday`. As its name suggests, it will throw in case of an `Error`. Some functions return functions that return an `Either` or throw. In that case, the variant for non Effect users contains the word `Throwing`, e.g. use `CVDateTimeFormat.toThrowingFormatter` instead of `CVDateTimeFormat.toFormatter`.
55
+ Most functions of this package return an `Either` or an `Option` to signify the possibility of an error. However, if you are not an `Effect` user and do not care to learn more about it, you can simply use the `OrThrow` variant of the function. For instance, use `CVDateTime.setWeekdayOrThrow` instead of `CVDateTime.setWeekday`. As its name suggests, it will throw in case failure. Some functions return functions that return an `Either` or throw. In that case, the variant for non-`Effect` users contains the word `Throwing`, e.g. use `CVDateTimeFormat.toThrowingFormatter` instead of `CVDateTimeFormat.toFormatter`.
56
56
 
57
57
  ### <a name="RoundingModule"></a>A) Rounding module
58
58
 
@@ -177,9 +177,9 @@ export enum Type {
177
177
  }
178
178
  ```
179
179
 
180
- #### 3. CVRoundingOption instances
180
+ #### 3. `CVRoundingOption` instances
181
181
 
182
- Instead of building your own CVRoundingOption, you can use the `halfExpand2` CVRoundingOption instance (`HalfExpand` rounding mode with a precision of two fractional digits). It will come in handy in accounting apps of most countries. For example:
182
+ Instead of building your own `CVRoundingOption`, you can use the `halfExpand2` `CVRoundingOption` instance (`HalfExpand` rounding mode with a precision of two fractional digits). It will come in handy in accounting apps of most countries. For example:
183
183
 
184
184
  ```ts
185
185
  import { CVRoundingOption } from "@parischap/conversions";
@@ -200,7 +200,7 @@ console.log(numberRounder(-12.457));
200
200
 
201
201
  #### 4. Debugging and equality
202
202
 
203
- CVRoundingOption objects implement Effect equivalence and equality based on equivalence and equality of the precision and roundingMode properties. They also implement a .toString() method. For instance:
203
+ `CVRoundingOption` objects implement `Effect` equivalence and equality based on equivalence and equality of the `precision` and `roundingMode` properties. They also implement a `.toString()` method. For instance:
204
204
 
205
205
  ```ts
206
206
  import { CVRoundingMode, CVRoundingOption } from "@parischap/conversions";
@@ -226,7 +226,7 @@ console.log(Equal.equals(CVRoundingOption.halfExpand2, dummyOption1));
226
226
  console.log(Equal.equals(CVRoundingOption.halfExpand2, dummyOption2));
227
227
  ```
228
228
 
229
- ### <a name="NumberParserFormatter"></a>B) Number and BigDecimal parser/formatter
229
+ ### <a name="NumberParserFormatter"></a>B) Number and `BigDecimal` parser/formatter
230
230
 
231
231
  #### 1. Usage example
232
232
 
@@ -293,19 +293,19 @@ console.log(frenchStyleDecoder("1 024,56"));
293
293
  console.log(frenchStyleEncoder(CVReal.unsafeFromNumber(1024.56)));
294
294
  ```
295
295
 
296
- #### 2. CVNumberBase10Format instances
296
+ #### 2. `CVNumberBase10Format` instances
297
297
 
298
- In the previous example, we used the `ukStyleNumber`, `ukStyleUngroupedNumber` and `frenchStyleInteger` CVNumberBase10Format instances.
298
+ In the previous example, we used the `ukStyleNumber`, `ukStyleUngroupedNumber` and `frenchStyleInteger` `CVNumberBase10Format` instances.
299
299
 
300
300
  You will find in the [API](https://parischap.github.io/effect-libs/conversions/NumberBase10Format.ts) the list of all pre-defined instances.
301
301
 
302
- #### 3. CVNumberBase10Format Instance modifiers
302
+ #### 3. `CVNumberBase10Format` Instance modifiers
303
303
 
304
- Sometimes, you will need to bring some small modifications to a pre-defined CVNumberBase10Format instance. For instance, in the previous example, we defined the `ukStyleNumberWithEngineeringNotation` instance by using the `withEngineeringScientificNotation` modifier on the `ukStyleNumber` pre-defined instance.
304
+ Sometimes, you will need to bring some small modifications to a pre-defined `CVNumberBase10Format` instance. For instance, in the previous example, we defined the `ukStyleNumberWithEngineeringNotation` instance by using the `withEngineeringScientificNotation` modifier on the `ukStyleNumber` pre-defined instance.
305
305
 
306
306
  There are quite a few such modifiers whose list you will find in the [API](https://parischap.github.io/effect-libs/conversions/NumberBase10Format.ts).
307
307
 
308
- #### 4. CVNumberBase10Format in more details
308
+ #### 4. `CVNumberBase10Format` in more details
309
309
 
310
310
  If you have very specific needs, you can define your own CVNumberBase10Format instance that must comply with the following interface:
311
311
 
@@ -401,7 +401,7 @@ const frenchStyleNumber = CVNumberBase10Format.make({
401
401
 
402
402
  #### 5. Debugging and equality
403
403
 
404
- CVNumberBase10Format objects implement a `.toString()` method and a `toDescription` destructor.
404
+ `CVNumberBase10Format` objects implement a `.toString()` method and a `toDescription` destructor.
405
405
  The `.toString()` method will display the name of the object and all available properties. The `toDescription` destructor will produce a short summary of the format.
406
406
 
407
407
  For instance:
@@ -586,9 +586,9 @@ These two texts obviously share the same structure which is the template:
586
586
 
587
587
  Placeholder1 is a Placeholder2-year old Placeholder3.
588
588
 
589
- Placeholder1, Placeholder2 and Placeholder3 are the mutable parts of the template. They contain valuable information. We call them `TemplatePlaceholder`'s.
589
+ Placeholder1, Placeholder2 and Placeholder3 are the mutable parts of the template. We call them `CVTemplatePlaceholder`'s.
590
590
 
591
- " is a " and "-year old " are the immutable parts of the template. We call them `TemplateSeperator`'s.
591
+ " is a ", "-year old " and "." are the immutable parts of the template. We call them `CVTemplateSeperator`'s.
592
592
 
593
593
  From a text with the above structure, we can extract the values of Placeholder1, Placeholder2, and Placeholder3. In the present case:
594
594
 
@@ -603,31 +603,34 @@ Inversely, given a template and the values of the placeholders that compose it (
603
603
 
604
604
  we will obtain the text: "Tom is a 15-year old boy."
605
605
 
606
- #### 3. CVTemplateSeparator's
606
+ #### 3. `CVTemplateSeparator`'s
607
607
 
608
- A `CVTemplateSeparator` represents the immutable part of a template. Upon parsing, we must check that it is present as is in the text. Upon formatting, it must be inserted as is into the text. A `CVTemplateSeparator` contains no valuable information.
608
+ A `CVTemplateSeparator` represents the immutable part of a template. Upon parsing, we must check that it is present as is in the text. Upon formatting, it must be inserted as is into the text.
609
609
 
610
610
  To create a `CVTemplateSeparator`, you usually call the `CVTemplateSeparator.make` constructor. However, the TemplateSeparator.ts module exports a series of predefined `CVTemplateSeparator` instances, such as `CVTemplateSeparator.slash` and `CVTemplateSeparator.space`. You can find the list of all predefined `CVTemplateSeparator` instances in the [API](https://parischap.github.io/effect-libs/conversions/TemplatePart.ts).
611
611
 
612
612
  #### 4. CVTemplatePlaceholder's
613
613
 
614
- A Placeholder represents the mutable part of a template. Each Placeholder defines a parser and a formatter: the parser takes a text, consumes a part of that text, optionnally converts the consumed part to a value of type T and, if successful, returns a right of that value and of what has not been consumed. In case of an error, it returns a left. The formatter takes a value of type T, converts it to a string (if T is not string), checks that the result is coherent and, if so, inserts that string into the text. Otherwise, it returns a left.
614
+ A `CVTemplatePlaceholder` represents the mutable part of a template. Each `CVTemplatePlaceholder` defines a parser and a formatter:
615
+
616
+ - the parser takes a text, consumes a part of that text, optionnally converts the consumed part to a value of type T and, if successful, returns a `Right` of that value and of what has not been consumed. In case of failure, it returns a `Left`.
617
+ - the formatter takes a value of type T, converts it to a string (if T is not string), checks that the result is coherent and, if so, inserts that string into the text. Otherwise, it returns a `Left`.
615
618
 
616
619
  There are several predefined Placeholder's:
617
620
 
618
621
  - `fixedLength`: this Placeholder always reads/writes the same number of characters from/into the text.
619
622
  - `paddedFixedLength`: same as `fixedLength` but the consumed text is trimmed off of a `fillChar` on the left or right and the written text is padded with a `fillChar` on the left or right.
620
- - `fixedLengthToReal`: same as fixedLength but the parser tries to convert the consumed text into a `CVReal` using the passed `CVNumberBase10Format`. The formatter takes a `CVReal` and tries to convert and write it as an n-character string. You can pass a `fillChar` that is trimmed off the consumed text upon parsing and padded to the written text upon formatting.
623
+ - `fixedLengthToReal`: same as `fixedLength` but the parser tries to convert the consumed text into a `CVReal` using the passed `CVNumberBase10Format`. The formatter takes a `CVReal` and tries to convert and write it as an n-character string. You can pass a `fillChar` that is trimmed off the consumed text upon parsing and padded to the written text upon formatting.
621
624
  - `real`: the parser of this Placeholder reads from the text all the characters that it can interpret as a number in the provided `CVNumberBase10Format` and converts the consumed text into a `CVReal`. The formatter takes a `CVReal` and converts it into a string according to the provided `CVNumberBase10Format`.
622
625
  - `mappedLiterals`: this Placeholder takes as input a map that must define a bijection between a list of strings and a list of values. The parser tries to read from the text one of the strings in the list. Upon success, it returns the corresponding value. The formatter takes a value and tries to find it in the list. Upon success, it writes the corresponding string into the text.
623
- - `realMappedLiterals`: same as `mappedLiterals` but values are assumed to be of type CVReal.Type which is the most usual use case.
626
+ - `realMappedLiterals`: same as `mappedLiterals` but values are assumed to be of type `CVReal` which is the most usual use case.
624
627
  - `fulfilling`: the parser of this Placeholder reads as much of the text as it can that fulfills the passed regular expression. The formatter only accepts a string that matches the passed regular expression and writes it into the text.
625
- - `anythingBut`: this is a special case of the `fulfilling` placeholder. The parser of this Placeholder reads from the text until it meets one of the `forbiddenChars` passed as parameter (the result must be a non-empty string). The formatter will only accept a non-empty string that does not contain any of the forbidden chars and write it to the text.
626
- - `toEnd`: this is another special case of the `fulfilling` placeholder. The parser of this Placeholder reads all the remaining text. The formatter accepts any string and writes it. This Placeholder should only be used as the last `CVTemplatePart` of a `CVTemplate`.
628
+ - `anythingBut`: this is a special case of the `fulfilling` `CVTemplatePlaceholder`. The parser reads from the text until it meets one of the `forbiddenChars` passed as parameter (the result must be a non-empty string). The formatter will only accept a non-empty string that does not contain any of the forbidden chars and write it to the text.
629
+ - `toEnd`: this is another special case of the `fulfilling` `CVTemplatePlaceholder`. The parser reads all the remaining text. The formatter accepts any string and writes it. This `CVTemplatePlaceholder` should only be used as the last `CVTemplatePart` of a `CVTemplate`.
627
630
 
628
- Each `CVTemplatePlaceholder` must be given a name that will be used as the name of the property of the result object of parsing or of the input object of formatting. This name needs not be unique inside a template. The same name can appear several times. However, even if there are several `CVTemplatePlaceholder`'s with the same name, there will be only one property with that name. When parsing, this implies that all `CVTemplatePlaceholder`'s with the same name must yield the same value. When formatting, this implies that the value needs only be provided once and will be shared by all `CVTemplatePlaceholder`'s.
631
+ Each `CVTemplatePlaceholder` must be given a name that will be used as the name of the property of the result object of parsing or of the input object of formatting. This name needs not be unique inside a CVTemplate. The same name can appear several times. However, even if there are several `CVTemplatePlaceholder`'s with the same name, there will be only one property with that name. When parsing, this implies that all `CVTemplatePlaceholder`'s with the same name must yield the same value. When formatting, this implies that the value needs only be provided once and will be shared by all `CVTemplatePlaceholder`'s with that name.
629
632
 
630
- If none of these Placeholder instances suits you, you can define you own with the `make` constructor. You will find detailed explanations of the predefined Placeholder instances and of the make constructor in the [API](https://parischap.github.io/effect-libs/conversions/TemplatePart.ts).
633
+ If none of these `CVTemplatePlaceholder` instances suits you, you can define you own with the `make` constructor. You will find detailed explanations of the predefined `CVTemplatePlaceholder` instances and of the make constructor in the [API](https://parischap.github.io/effect-libs/conversions/TemplatePart.ts).
631
634
 
632
635
  #### 5. A more complex example
633
636
 
@@ -714,8 +717,7 @@ console.log(formatter({ weekday: CVReal.unsafeFromNumber(10) }));
714
717
 
715
718
  #### 6. Debugging
716
719
 
717
- CVTemplate objects implement a `.toString()` method.
718
- The `.toString()` method will display a synthetic description of the template followed by the description of each CVPlaceholder.
720
+ `CVTemplate` objects implement a `.toString()` method that displays a synthetic description of the template followed by the description of each contained `CVTemplatePlaceholder`.
719
721
 
720
722
  For instance:
721
723
 
@@ -770,15 +772,15 @@ console.log(template);
770
772
 
771
773
  This package implements an immutable `CVDateTime` object: once created, the characteristics of a `CVDateTime` object will never change. However, the provided Setters functions allow you to get a copy of an existing `CVDateTime` object with just one charactreristic modified.
772
774
 
773
- Although immutable when considered from the outer world, `CVDateTime` objects do keep an internal state that is only used to improve performance (but does not alter results). CVDateTime functions can therefore be regarded as pure: they will always yield the same result whatever the state the object is in.
775
+ Although immutable when considered from the outer world, `CVDateTime` objects do keep an internal state that is only used to improve performance (but does not alter results). `CVDateTime` functions can therefore be regarded as pure: they will always yield the same result whatever the state the object is in.
774
776
 
775
- Unlike the Javascript Date objects and the Effect DateTime objects, `CVDateTime` objects handle both
777
+ Unlike the Javascript `Date` objects and the `Effect.DateTime` objects, `CVDateTime` objects handle both
776
778
  the Gregorian and Iso calendars. So you can easily get/set the iso year and iso week of a
777
779
  `CVDateTime` object.
778
780
 
779
781
  A `CVDateTime` object has a `zoneOffset` which is the difference in hours between the time in the local zone and UTC time (e.g zoneOffset=1 for timezone +1:00). All the data in a `CVDateTime` object is zoneOffset-dependent, except `timestamp`.
780
782
 
781
- You cannot create a `CVDateTime` object from a string. In that case, use the `CVDateTimeFormat` module.
783
+ You cannot create a `CVDateTime` object from a string. If this is your need, use the `CVDateTimeFormat` module.
782
784
 
783
785
  #### 2. Usage example
784
786
 
@@ -1169,7 +1171,7 @@ console.log(jsEncoder(new Date(0)));
1169
1171
 
1170
1172
  #### 2. Available tokens
1171
1173
 
1172
- Many of the available [unicode tokens](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table) can be used to define DateTimeFormats. Here is a list of all currently available tokens:
1174
+ Many of the available [unicode tokens](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table) can be used to define `CVDateTimeFormat`'s. Here is a list of all currently available tokens:
1173
1175
 
1174
1176
  ```ts
1175
1177
  export type Token =
@@ -1247,16 +1249,17 @@ export type Token =
1247
1249
  | "zszs";
1248
1250
  ```
1249
1251
 
1250
- #### 3. CVDateTimeFormatContext
1252
+ #### 3. `CVDateTimeFormatContext`
1253
+
1254
+ Some of the available tokens are language specific. For instance the `MMMM` token is expected to display `december` in English and `décembre` in French. For this reason, you need to build a `CVDateTimeFormatContext` before building a `CVDateTimeFormat`. You can build a `CVDateTimeFormatContext` in one of the three following ways:
1251
1255
 
1252
- Some of the available tokens are language specific. For instance the `MMMM` token is expected to display `december` in English and `décembre` in French. For this reason, you need to build a `CVDateTimeFormatContext` before building a `CVDateTimeFormat`. You can either use the provided `enGB` instance (for Great Britain English language), or build a `CVDateTimeFormatContext` from the name of a locale (e.g. `const frenchContext = CVDateTimeFormatContext.fromLocaleOrThrow("fr-FR")`) or, if you have very specific needs or your locale is not available, build a `CVDateTimeFormatContext` by providing directly your translations by using the `CVDateTimeFormatContext.fromNames` constructor.
1256
+ - you can use the provided `CVDateTimeFormatContext.enGB` instance (for Great Britain English language)
1257
+ - you can build a `CVDateTimeFormatContext` from the name of a locale, e.g. `const frenchContext = CVDateTimeFormatContext.fromLocaleOrThrow("fr-FR")`
1258
+ - if you have very specific needs or your locale is not available, you can build a `CVDateTimeFormatContext` by providing directly your translations to the `CVDateTimeFormatContext.fromNames` constructor.
1253
1259
 
1254
1260
  #### 4. Debugging
1255
1261
 
1256
- CVDateTimeFormat objects implement a `.toString()` method.
1257
- The `.toString()` method will display a synthetic description of the template followed by the description of each CVPlaceholder.
1258
-
1259
- For instance:
1262
+ `CVDateTimeFormat` objects implement a `.toString()` method which displays a synthetic description of the template followed by the description of each CVPlaceholder. For instance:
1260
1263
 
1261
1264
  ```ts
1262
1265
  import {
@@ -1290,15 +1293,13 @@ console.log(frenchFormat);
1290
1293
 
1291
1294
  #### 1. Introduction
1292
1295
 
1293
- Read the [Effect documentation about Branding](https://effect.website/docs/code-style/branded-types/) if you are not familiar with this concept.
1294
-
1295
- In this package you will find the following Brands:
1296
+ In this package you will find the following [`Brand`'s](https://effect.website/docs/code-style/branded-types/):
1296
1297
 
1297
1298
  - `CVEmail`: represents a valid email string
1298
1299
  - `CVSemVer`: represents a valid semantic versioning string
1299
- - `CVReal`: represents a valid floating-point number (+Infinity, Infinity, -Infinity, NaN not allowed). Can be used to represent a temperature, height from sea-level,...
1300
- - `CVPositiveReal`: same as CVReal but the number must be positive. Can be used to represent a price, a speed,...
1301
- - `CVInteger`: same as CVReal but the number must be an integer. Can be used to represent a floor, a signed quantity...
1302
- - `CVPositiveInteger`: same as CVInteger but the number must be positive. Can be used to represent an age, a quantity,...
1300
+ - `CVReal`: represents a valid floating-point number (+Infinity, Infinity, -Infinity, NaN not allowed). Can be used to represent a temperature, a height from sea-level,...
1301
+ - `CVPositiveReal`: same as `CVReal` but the number must be positive. Can be used to represent a price, a speed,...
1302
+ - `CVInteger`: same as `CVReal` but the number must be an integer. Can be used to represent a floor in a lift, a signed quantity...
1303
+ - `CVPositiveInteger`: same as `CVInteger` but the number must be positive. Can be used to represent an age, a quantity,...
1303
1304
 
1304
1305
  You will also find all the functions to convert from one brand to another. Do not hesitate to take a look at the [API](https://parischap.github.io/effect-libs/docs/conversions) to learn more about what this module offers in terms of branding.
package/cjs/BigDecimal.js CHANGED
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.fromReal = void 0;
7
7
  var _effect = /*#__PURE__*/require("effect");
8
- /** A simple extension to the Effect BigDecimal module */
8
+ /** A simple extension to the `Effect.BigDecimal` module */
9
9
 
10
10
  /**
11
- * Constructs a BigDecimal from a Real
11
+ * Constructs a `BigDecimal` from a `CVReal`
12
12
  *
13
13
  * @category Constructors
14
14
  */
package/cjs/BigInt.js CHANGED
@@ -5,28 +5,30 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.fromRealOrThrow = exports.fromRealOption = exports.fromReal = exports.fromInteger = void 0;
7
7
  var _effectLib = /*#__PURE__*/require("@parischap/effect-lib");
8
- /** A simple extension to the Effect BigInt module */
8
+ /** A simple extension to the `Effect.BigInt` module */
9
9
 
10
10
  /**
11
- * Constructs a BigInt from a Integer
11
+ * Constructs a `BigInt` from a `CVInteger`
12
12
  *
13
13
  * @category Constructors
14
14
  */
15
15
  const fromInteger = exports.fromInteger = _effectLib.MBigInt.fromPrimitiveOrThrow;
16
16
  /**
17
- * Constructs an Option of a BigInt from a Real
17
+ * Tries to construct a `BigInt` from a `CVReal`. Returns a `Some` if the conversion can be
18
+ * performed, a `None` otherwise
18
19
  *
19
20
  * @category Constructors
20
21
  */
21
22
  const fromRealOption = exports.fromRealOption = _effectLib.MBigInt.fromPrimitiveOption;
22
23
  /**
23
- * Constructs an Either of a BigInt from a Real
24
+ * Tries to construct a `BigInt` from a `CVReal`. Returns a `Right` if the conversion can be
25
+ * performed, a `Left` otherwise
24
26
  *
25
27
  * @category Constructors
26
28
  */
27
29
  const fromReal = exports.fromReal = _effectLib.MBigInt.fromPrimitive;
28
30
  /**
29
- * Constructs a BigInt from a Real or throws
31
+ * Constructs a `BigInt` from a `CVReal` if possible. Throws otherwise
30
32
  *
31
33
  * @category Constructors
32
34
  */
package/cjs/BigInt.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"BigInt.js","names":["_effectLib","require","fromInteger","exports","MBigInt","fromPrimitiveOrThrow","fromRealOption","fromPrimitiveOption","fromReal","fromPrimitive","fromRealOrThrow"],"sources":["../../esm/BigInt.ts"],"sourcesContent":[null],"mappings":";;;;;;AAEA,IAAAA,UAAA,gBAAAC,OAAA;AAFA;;AAOA;;;;;AAKO,MAAMC,WAAW,GAAAC,OAAA,CAAAD,WAAA,GACvBF,UAAA,CAAAI,OAAO,CAACC,oBAAoB;AAE7B;;;;;AAKO,MAAMC,cAAc,GAAAH,OAAA,CAAAG,cAAA,GAGvBN,UAAA,CAAAI,OAAO,CAACG,mBAA4B;AAExC;;;;;AAKO,MAAMC,QAAQ,GAAAL,OAAA,CAAAK,QAAA,GAGjBR,UAAA,CAAAI,OAAO,CAACK,aAAsB;AAElC;;;;;AAKO,MAAMC,eAAe,GAAAP,OAAA,CAAAO,eAAA,GAC3BV,UAAA,CAAAI,OAAO,CAACC,oBAA6B","ignoreList":[]}
1
+ {"version":3,"file":"BigInt.js","names":["_effectLib","require","fromInteger","exports","MBigInt","fromPrimitiveOrThrow","fromRealOption","fromPrimitiveOption","fromReal","fromPrimitive","fromRealOrThrow"],"sources":["../../esm/BigInt.ts"],"sourcesContent":[null],"mappings":";;;;;;AAEA,IAAAA,UAAA,gBAAAC,OAAA;AAFA;;AAOA;;;;;AAKO,MAAMC,WAAW,GAAAC,OAAA,CAAAD,WAAA,GACvBF,UAAA,CAAAI,OAAO,CAACC,oBAAoB;AAE7B;;;;;;AAMO,MAAMC,cAAc,GAAAH,OAAA,CAAAG,cAAA,GAGvBN,UAAA,CAAAI,OAAO,CAACG,mBAA4B;AAExC;;;;;;AAMO,MAAMC,QAAQ,GAAAL,OAAA,CAAAK,QAAA,GAGjBR,UAAA,CAAAI,OAAO,CAACK,aAAsB;AAElC;;;;;AAKO,MAAMC,eAAe,GAAAP,OAAA,CAAAO,eAAA,GAC3BV,UAAA,CAAAI,OAAO,CAACC,oBAA6B","ignoreList":[]}