@colisweb/rescript-toolkit 1.32.0 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "1.32.0",
3
+ "version": "2.0.0",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build",
@@ -1,4 +1,4 @@
1
- module Date = {
1
+ module Datetime = {
2
2
  type date = Js.Date.t
3
3
 
4
4
  let encoder: Decco.encoder<date> = value => value->Js.Date.toISOString->Decco.stringToJson
@@ -15,6 +15,24 @@ module Date = {
15
15
  type t = @decco.codec(codec) date
16
16
  }
17
17
 
18
+ module Date = {
19
+ type date = Js.Date.t
20
+
21
+ let encoder: Decco.encoder<date> = date =>
22
+ date->BsDateFns.formatWithPattern("yyyy-MM-dd")->Decco.stringToJson
23
+
24
+ let decoder: Decco.decoder<date> = json =>
25
+ switch Decco.stringFromJson(json) {
26
+ | Ok(v) => Js.Date.fromString(v)->Ok
27
+ | Error(_) as err => err
28
+ }
29
+
30
+ let codec: Decco.codec<date> = (encoder, decoder)
31
+
32
+ @decco
33
+ type t = @decco.codec(codec) date
34
+ }
35
+
18
36
  module Int = {
19
37
  let encoder = value => value->Decco.intToJson
20
38