forked from tsirysndr/rescript-deno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo.res
190 lines (124 loc) · 3.6 KB
/
Demo.res
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
open Archive.Tar
open Archive.Untar
open IO
open Globals
open Assert
Console.log("Hello, world!")
Console.log(Deno.env->Env.get("HOME"))
Console.log(Deno.env->Env.has("PATH"))
let tar = newTar()
let content = TextEncoder.new()->TextEncoder.encode("hello")
let b = Buffer.new(content)
Console.log(b->Buffer.empty)
Console.log(b->Buffer.bytes)
tar->append("hello.txt", {reader: b, contentSize: b->Buffer.bytes->TypedArray.length})
Console.log(tar)
Console.log(tar->getReader)
let reader = tar->getReader
let untar = newUntar(reader)
Console.log(await untar->extract)
_assert(true)
assertAlmostEquals(0.01, 0.02, ~tolerance=0.1)
assertArrayIncludes([1, 2, 3], [1, 2])
assertEquals(1, 1)
let a = 1
assertExists(a)
assertFalse(false)
assertGreater(4, 1)
assertGreaterOrEqual(4, 4)
assertLess(1, 4)
assertLessOrEqual(4, 4)
assertMatch("hello", %re("/hello/"))
assertNotEquals(1, 2)
assertNotMatch("hello", %re("/world/"))
assertNotStrictEquals(1, 2)
type x = {a: int}
assertObjectMatch({a: 1}, {a: 1})
let z = {a: 1}
let y = z
assertStrictEquals(y, z)
assertStringIncludes("hello", "ello")
exception MyException({message: string})
assertThrows(() => {
raise(MyException({message: "hello"}))
})
Console.log(equal({a: 1}, {a: 1}))
let c = AbortController.new()
Console.log(c->AbortController.signal)
Console.log(URL.new("https://deno.land")->URL.toString)
let pattern = URLPattern.new(String("https://deno.land"))
Console.log(pattern)
let pattern = URLPattern.new(
URLPatternInit({
pathname: "/x",
baseURL: "https://deno.land",
}),
)
Console.log(pattern)
type query = {foo: string}
let params = URLSearchParams.new({foo: "bar"})
Console.log(params->URLSearchParams.toString)
Console.log(btoa("hello"))
Console.log(atob("aGVsbG8gd29ybGQ="))
/*
alert("hello")
let res = prompt("Are you sure?")
Console.log(res)
let res = confirm("Are you sure?")
Console.log(res)
let file = await Deno.create("hello.txt")
Console.log(file)
await Deno.mkdir("hello/world", ~options={recursive: true})
await Deno.writeTextFile("hello.txt", Deno.Data.String("hello"), ~options={create: true})
*/
/*
Deno.serveWithUnixOptions({path: "/tmp/deno.sock"}, ~handler=req => {
Response.new(String("Hello, world!"))
})->ignore
*/
/*
Deno.serve(~handler=req => {
Response.new(String("Hello, world!"))
})->ignore
*/
/*
let result = await fetch(String("https://rickandmortyapi.com/api/character"))
Console.log(await result->Response.json)
*/
let data = FormData.new()
data->FormData.append("foo", String("bar"))
Console.log(Deno.networkInterfaces())
let request = Request.new(
String("http://localhost:9007"),
~init={
body: FormData(data),
method: "POST",
// headers: {"Content-Type": "application/json"},
},
)
Console.log(request)
Console.log(await request->Request.formData)
let text = TextEncoder.new()->TextEncoder.encode("hello")
Console.log(TextDecoder.new()->TextDecoder.decode(text))
Console.log(await Deno.resolveDns("deno.land", "A"))
let command = Deno.Command.new(
"ls",
~options={
stdout: "piped",
stderr: "piped",
},
)
let process = command->Deno.Command.spawn
let output = await process->Deno.ChildProcess.output
let status = await process->Deno.ChildProcess.status
Console.log(status->Deno.CommandStatus.code)
let decoder = TextDecoder.new()
Console.log(decoder->TextDecoder.decode(output->Deno.CommandOutput.stdout))
Deno.serveWithOptions({port: 9007}, ~asyncHandler=async req => {
let headers = req->Request.headers
let body = await req->Request.text
Console.log(headers)
Console.log(headers->Headers.get("User-Agent"))
Console.log(body)
Response.new(String("Hello, world!"))
})->ignore