Skip to content

Commit bf76242

Browse files
author
Jared Ramirez
committed
Update docs/readme; Make some errors warnings
1 parent c9042b8 commit bf76242

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
## rescript-json
22

3-
> A port of https://package.elm-lang.org/packages/elm/json/latest/ to rescript
3+
This package helps you convert between Rescript values and JSON values.
4+
5+
This package is usually used alongside http requests to talk to servers or with {{:https://rescript-lang.org/docs/manual/latest/external} external} calls talk to JavaScript.
46

57
### Install
8+
9+
In your projects root directory, run:
610
```
711
yarn add rescript-json
812
```
913

10-
Then in `bsconfig.js`:
14+
Then update `bsconfig.js` to include this package as a dependency:
1115
```
1216
{
1317
...,
1418
"bs-dependencies": [..., "rescript-json"]
1519
}
1620
```
1721

18-
### Checkout the Docs!
22+
### API Docs
1923

2024
The docs are [here](https://jaredramirez.github.io/rescript-json/gen/RescriptJson/Json/)!
2125

26+
### Credit
27+
28+
This package is a port of [Elm's JSON decoding library](https://package.elm-lang.org/packages/elm/json/latest/).
29+
30+
When creating this package, I basically went through the docs for the Elm library and implemented a Rescript version. Additional, because it's so well done, the documentation is copied verbatim.
31+
32+
Thanks to Evan Czaplicki ([@evancz](https://github.com/evancz)) and all other folks for designing and creating the excellent Elm package!
2233

bsconfig.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"name": "rescript-json",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"sources": [
55
{ "dir": "src", "subdirs": true },
66
{ "dir": "tests", "subdirs": true, "type": "dev" }
77
],
8-
"bs-dev-dependencies": ["@dusty-phillips/rescript-zora"]
8+
"bs-dev-dependencies": ["@dusty-phillips/rescript-zora"],
9+
"warnings": {
10+
"error": "+5+8"
11+
}
912
}

docs/gen/RescriptJson/Json/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<!DOCTYPE html>
2-
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Json (RescriptJson.Json)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../">Up</a><a href="../">RescriptJson</a> &#x00BB; Json</nav><h1>Module <code>Json</code></h1><h2 id="json-in-rescript"><a href="#json-in-rescript" class="anchor"></a>JSON in Rescript</h2><nav class="toc"><ul><li><a href="#example">Example</a></li><li><a href="#credit">Credit</a></li><li><a href="#docs">Docs</a></li></ul></nav></header><aside><p>This package helps you convert between Rescript values and JSON values.</p><p>This package is usually used alongside http requests to talk to servers or with <a href="https://rescript-lang.org/docs/manual/latest/external">external</a> calls talk to JavaScript.</p></aside><section><header><h3 id="example"><a href="#example" class="anchor"></a>Example</h3></header><aside><p>Have you seen this <a href="https://en.wikipedia.org/wiki/List_of_causes_of_death_by_rate">causes of death</a> table? Did you know that in 2002, war accounted for 0.3% of global deaths whereas road traffic accidents accounted for 2.09% and diarrhea accounted for 3.15%?</p><p>The table is interesting, but say we want to visualize this data in a nicer way. We will need some way to get the cause-of-death data from our server, so we create encoders and decoders:</p><pre><code class="ml">module Cause = {
2+
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Json (RescriptJson.Json)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../">Up</a><a href="../">RescriptJson</a> &#x00BB; Json</nav><h1>Module <code>Json</code></h1><h2 id="json-in-rescript"><a href="#json-in-rescript" class="anchor"></a>JSON in Rescript</h2><nav class="toc"><ul><li><a href="#install">Install</a></li><li><a href="#example">Example</a></li><li><a href="#docs">Docs</a></li><li><a href="#credit">Credit</a></li></ul></nav></header><aside><p>This package helps you convert between Rescript values and JSON values.</p><p>This package is usually used alongside http requests to talk to servers or with <a href="https://rescript-lang.org/docs/manual/latest/external">external</a> calls talk to JavaScript.</p></aside><section><header><h3 id="install"><a href="#install" class="anchor"></a>Install</h3></header><aside><p>In your projects root directory, run:</p><pre><code class="ml">yarn add rescript-json</code></pre><p>Then update `bsconfig.js` to include this package as a dependency:</p><pre><code class="ml">{
3+
...,
4+
&quot;bs-dependencies&quot;: [..., &quot;rescript-json&quot;]
5+
}</code></pre></aside></section><section><header><h3 id="example"><a href="#example" class="anchor"></a>Example</h3></header><aside><p>Have you seen this <a href="https://en.wikipedia.org/wiki/List_of_causes_of_death_by_rate">causes of death</a> table? Did you know that in 2002, war accounted for 0.3% of global deaths whereas road traffic accidents accounted for 2.09% and diarrhea accounted for 3.15%?</p><p>The table is interesting, but say we want to visualize this data in a nicer way. We will need some way to get the cause-of-death data from our server, so we create encoders and decoders:</p><pre><code class="ml">module Cause = {
36
type t =
47
{
58
name: string,
@@ -31,4 +34,4 @@
3134
)
3235
)
3336
}
34-
}</code></pre><p>Now in some other code we can use Cause.encode and Cause.decoder as building blocks. So if we want to decode a list of causes, saying Decode.list Cause.decoder will handle it!</p><p>Point is, the goal should be:</p><ol><li>Make small JSON decoders and encoders.</li><li>Snap together these building blocks as needed.</li></ol><p>So say you decide to make the name field more precise. Instead of a <code>string</code>, you want to use codes from the <a href="https://www.who.int/classifications/classification-of-diseases">International Classification of Diseases</a> recommended by the World Health Organization. These <a href="https://icd.who.int/browse10/2016/en">codes</a> are used in a lot of mortality data sets. So it may make sense to make a separate <code>icdCode</code> module with its own <code>IcdCode.encode</code> and <code>IcdCode.decoder</code> that ensure you are working with valid codes. From there, you can use them as building blocks in the <code>Cause</code> module!</p></aside></section><section><header><h3 id="credit"><a href="#credit" class="anchor"></a>Credit</h3></header><aside><p>This package is a port of <a href="https://package.elm-lang.org/packages/elm/json/latest/">Elm's JSON decoding library</a>.</p><p>Nearly all of the functions in this library, as well as its documentation, are copied from there. Thanks to Evan Czaplicki (<a href="https://github.com/evancz">@evancz</a>) and all other folks who worked the Elm package!</p></aside></section><section><header><h3 id="docs"><a href="#docs" class="anchor"></a>Docs</h3></header><dl><dt class="spec type" id="type-value"><a href="#type-value" class="anchor"></a><code><span class="keyword">type</span> <span class="keyword">nonrec</span> value</code><code> = Js.Json.t</code>;</dt></dl><aside><p>Represents a JavaScript value.</p></aside><div class="spec module" id="module-Decode"><a href="#module-Decode" class="anchor"></a><code><span class="keyword">module</span> <a href="Decode">Decode</a>: { ... };</code></div><aside><p>The Decode module. Accessed by <code>Json.Decode.*</code></p></aside><div class="spec module" id="module-Encode"><a href="#module-Encode" class="anchor"></a><code><span class="keyword">module</span> <a href="Encode">Encode</a>: { ... };</code></div><aside><p>The Encode module. Accessed by <code>Json.Encode.*</code></p></aside></section></div></body></html>
37+
}</code></pre><p>Now in some other code we can use Cause.encode and Cause.decoder as building blocks. So if we want to decode a list of causes, saying <code>Json.Decode.array(Cause.decoder)</code> will handle it!</p><p>Point is, the goal should be:</p><ol><li>Make small JSON decoders and encoders.</li><li>Snap together these building blocks as needed.</li></ol><p>So say you decide to make the name field more precise. Instead of a <code>string</code>, you want to use codes from the <a href="https://www.who.int/classifications/classification-of-diseases">International Classification of Diseases</a> recommended by the World Health Organization. These <a href="https://icd.who.int/browse10/2016/en">codes</a> are used in a lot of mortality data sets. So it may make sense to make a separate <code>icdCode</code> module with its own <code>IcdCode.encode</code> and <code>IcdCode.decoder</code> that ensure you are working with valid codes. From there, you can use them as building blocks in the <code>Cause</code> module!</p></aside></section><section><header><h3 id="docs"><a href="#docs" class="anchor"></a>Docs</h3></header><dl><dt class="spec type" id="type-value"><a href="#type-value" class="anchor"></a><code><span class="keyword">type</span> <span class="keyword">nonrec</span> value</code><code> = Js.Json.t</code>;</dt></dl><aside><p>Represents a JavaScript value.</p></aside><div class="spec module" id="module-Decode"><a href="#module-Decode" class="anchor"></a><code><span class="keyword">module</span> <a href="Decode">Decode</a>: { ... };</code></div><aside><p>The Decode module. Accessed by <code>Json.Decode.*</code></p></aside><div class="spec module" id="module-Encode"><a href="#module-Encode" class="anchor"></a><code><span class="keyword">module</span> <a href="Encode">Encode</a>: { ... };</code></div><aside><p>The Encode module. Accessed by <code>Json.Encode.*</code></p></aside></section><section><header><h3 id="credit"><a href="#credit" class="anchor"></a>Credit</h3></header><aside><p>This package is a port of <a href="https://package.elm-lang.org/packages/elm/json/latest/">Elm's JSON decoding library</a>.</p><p>When creating this package, I basically went through the docs for the Elm library and implemented a Rescript version. Additional, because it's so well done, the documentation is copied almost verbatim.</p><p>Thanks to Evan Czaplicki (<a href="https://github.com/evancz">@evancz</a>) and all other folks for designing and creating the excellent Elm package!</p></aside></section></div></body></html>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "rescript-json",
33
"keywords": ["rescript", "json", "decode", "encode"],
44
"homepage": "https://jaredramirez.github.io/rescript-json",
5-
"version": "1.0.0",
5+
"version": "1.0.1",
66
"main": "index.js",
77
"repository": "https://github.com/jaredramirez/rescript-json.git",
88
"author": "Jared Ramirez <jaredramirez@hey.com>",

src/Json.resi

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ This package helps you convert between Rescript values and JSON values.
55
This package is usually used alongside http requests to talk to servers or with {{:https://rescript-lang.org/docs/manual/latest/external} external} calls talk to JavaScript.
66
")
77

8+
@@ocaml.text("{2 Install}")
9+
10+
@@ocaml.text("
11+
In your projects root directory, run:
12+
{[
13+
yarn add rescript-json
14+
]}
15+
16+
Then update `bsconfig.js` to include this package as a dependency:
17+
{[
18+
{
19+
...,
20+
\"bs-dependencies\": [..., \"rescript-json\"]
21+
}
22+
]}
23+
")
24+
825
@@ocaml.text("{2 Example}")
926

1027
@@ocaml.text("
@@ -59,13 +76,6 @@ Point is, the goal should be:
5976
So say you decide to make the name field more precise. Instead of a [string], you want to use codes from the {{: https://www.who.int/classifications/classification-of-diseases} International Classification of Diseases} recommended by the World Health Organization. These {{: https://icd.who.int/browse10/2016/en} codes} are used in a lot of mortality data sets. So it may make sense to make a separate [icdCode] module with its own [IcdCode.encode] and [IcdCode.decoder] that ensure you are working with valid codes. From there, you can use them as building blocks in the [Cause] module!
6077
")
6178

62-
@@ocaml.text("{2 Credit}")
63-
@@ocaml.text("
64-
This package is a port of {{: https://package.elm-lang.org/packages/elm/json/latest/} Elm's JSON decoding library}.
65-
66-
Nearly all of the functions in this library, as well as its documentation, are copied from there. Thanks to Evan Czaplicki ({{: https://github.com/evancz} @evancz}) and all other folks who worked the Elm package!
67-
")
68-
6979
@@ocaml.text("{2 Docs}")
7080

7181
type value = Js.Json.t
@@ -76,3 +86,12 @@ module Decode = Json__Decode
7686

7787
module Encode = Json__Encode
7888
@@ocaml.text("The Encode module. Accessed by [Json.Encode.*]")
89+
90+
@@ocaml.text("{2 Credit}")
91+
@@ocaml.text("
92+
This package is a port of {{: https://package.elm-lang.org/packages/elm/json/latest/} Elm's JSON decoding library}.
93+
94+
When creating this package, I basically went through the docs for the Elm library and implemented a Rescript version. Additional, because it's so well done, the documentation is copied almost verbatim.
95+
96+
Thanks to Evan Czaplicki ({{: https://github.com/evancz} \@evancz}) and all other folks for designing and creating the excellent Elm package!
97+
")

0 commit comments

Comments
 (0)