@grain/stdlib 0.5.12 → 0.6.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/CHANGELOG.md +200 -0
- package/LICENSE +1 -1
- package/README.md +25 -2
- package/array.gr +1512 -199
- package/array.md +2032 -94
- package/bigint.gr +239 -140
- package/bigint.md +450 -106
- package/buffer.gr +595 -102
- package/buffer.md +903 -145
- package/bytes.gr +401 -110
- package/bytes.md +551 -63
- package/char.gr +228 -49
- package/char.md +373 -7
- package/exception.gr +26 -12
- package/exception.md +29 -5
- package/float32.gr +130 -109
- package/float32.md +185 -57
- package/float64.gr +112 -99
- package/float64.md +185 -57
- package/hash.gr +47 -37
- package/hash.md +21 -3
- package/int16.gr +430 -0
- package/int16.md +618 -0
- package/int32.gr +200 -269
- package/int32.md +254 -289
- package/int64.gr +142 -225
- package/int64.md +254 -289
- package/int8.gr +511 -0
- package/int8.md +786 -0
- package/json.gr +2084 -0
- package/json.md +608 -0
- package/list.gr +120 -68
- package/list.md +125 -80
- package/map.gr +560 -57
- package/map.md +672 -56
- package/marshal.gr +239 -227
- package/marshal.md +36 -4
- package/number.gr +626 -676
- package/number.md +738 -153
- package/option.gr +33 -35
- package/option.md +58 -42
- package/package.json +2 -2
- package/path.gr +148 -187
- package/path.md +47 -96
- package/pervasives.gr +75 -416
- package/pervasives.md +85 -180
- package/priorityqueue.gr +433 -74
- package/priorityqueue.md +422 -54
- package/queue.gr +362 -80
- package/queue.md +433 -38
- package/random.gr +67 -75
- package/random.md +68 -40
- package/range.gr +135 -63
- package/range.md +198 -43
- package/rational.gr +284 -0
- package/rational.md +545 -0
- package/regex.gr +933 -1066
- package/regex.md +59 -60
- package/result.gr +23 -25
- package/result.md +54 -39
- package/runtime/atof/common.gr +78 -82
- package/runtime/atof/common.md +22 -10
- package/runtime/atof/decimal.gr +102 -127
- package/runtime/atof/decimal.md +28 -7
- package/runtime/atof/lemire.gr +56 -71
- package/runtime/atof/lemire.md +9 -1
- package/runtime/atof/parse.gr +83 -110
- package/runtime/atof/parse.md +12 -2
- package/runtime/atof/slow.gr +28 -35
- package/runtime/atof/slow.md +9 -1
- package/runtime/atof/table.gr +19 -18
- package/runtime/atof/table.md +10 -2
- package/runtime/atoi/parse.gr +153 -136
- package/runtime/atoi/parse.md +50 -1
- package/runtime/bigint.gr +410 -517
- package/runtime/bigint.md +71 -57
- package/runtime/compare.gr +176 -85
- package/runtime/compare.md +31 -1
- package/runtime/dataStructures.gr +144 -32
- package/runtime/dataStructures.md +267 -31
- package/runtime/debugPrint.gr +34 -15
- package/runtime/debugPrint.md +37 -5
- package/runtime/equal.gr +53 -52
- package/runtime/equal.md +30 -1
- package/runtime/exception.gr +38 -47
- package/runtime/exception.md +10 -8
- package/runtime/gc.gr +23 -152
- package/runtime/gc.md +13 -17
- package/runtime/malloc.gr +31 -31
- package/runtime/malloc.md +11 -3
- package/runtime/numberUtils.gr +191 -172
- package/runtime/numberUtils.md +17 -9
- package/runtime/numbers.gr +1695 -1021
- package/runtime/numbers.md +1098 -134
- package/runtime/string.gr +540 -242
- package/runtime/string.md +76 -6
- package/runtime/unsafe/constants.gr +30 -13
- package/runtime/unsafe/constants.md +80 -0
- package/runtime/unsafe/conv.gr +55 -28
- package/runtime/unsafe/conv.md +41 -9
- package/runtime/unsafe/memory.gr +10 -30
- package/runtime/unsafe/memory.md +15 -19
- package/runtime/unsafe/tags.gr +37 -21
- package/runtime/unsafe/tags.md +88 -8
- package/runtime/unsafe/wasmf32.gr +30 -36
- package/runtime/unsafe/wasmf32.md +64 -56
- package/runtime/unsafe/wasmf64.gr +30 -36
- package/runtime/unsafe/wasmf64.md +64 -56
- package/runtime/unsafe/wasmi32.gr +49 -66
- package/runtime/unsafe/wasmi32.md +102 -94
- package/runtime/unsafe/wasmi64.gr +52 -79
- package/runtime/unsafe/wasmi64.md +108 -100
- package/runtime/utils/printing.gr +13 -15
- package/runtime/utils/printing.md +11 -3
- package/runtime/wasi.gr +294 -295
- package/runtime/wasi.md +62 -42
- package/set.gr +574 -64
- package/set.md +634 -54
- package/stack.gr +181 -64
- package/stack.md +271 -42
- package/string.gr +453 -533
- package/string.md +241 -151
- package/uint16.gr +369 -0
- package/uint16.md +585 -0
- package/uint32.gr +470 -0
- package/uint32.md +737 -0
- package/uint64.gr +471 -0
- package/uint64.md +737 -0
- package/uint8.gr +369 -0
- package/uint8.md +585 -0
- package/uri.gr +1093 -0
- package/uri.md +477 -0
- package/{sys → wasi}/file.gr +914 -500
- package/{sys → wasi}/file.md +454 -50
- package/wasi/process.gr +292 -0
- package/{sys → wasi}/process.md +164 -6
- package/wasi/random.gr +77 -0
- package/wasi/random.md +80 -0
- package/{sys → wasi}/time.gr +15 -22
- package/{sys → wasi}/time.md +5 -5
- package/immutablearray.gr +0 -929
- package/immutablearray.md +0 -1038
- package/immutablemap.gr +0 -493
- package/immutablemap.md +0 -479
- package/immutablepriorityqueue.gr +0 -360
- package/immutablepriorityqueue.md +0 -291
- package/immutableset.gr +0 -498
- package/immutableset.md +0 -449
- package/runtime/debug.gr +0 -2
- package/runtime/debug.md +0 -6
- package/runtime/unsafe/errors.gr +0 -36
- package/runtime/unsafe/errors.md +0 -204
- package/sys/process.gr +0 -254
- package/sys/random.gr +0 -79
- package/sys/random.md +0 -66
package/uri.md
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Uri
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Utilities for working with URIs.
|
|
6
|
+
|
|
7
|
+
<details disabled>
|
|
8
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
9
|
+
No other changes yet.
|
|
10
|
+
</details>
|
|
11
|
+
|
|
12
|
+
```grain
|
|
13
|
+
from "uri" include Uri
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Types
|
|
17
|
+
|
|
18
|
+
Type declarations included in the Uri module.
|
|
19
|
+
|
|
20
|
+
### Uri.**Uri**
|
|
21
|
+
|
|
22
|
+
```grain
|
|
23
|
+
record Uri {
|
|
24
|
+
scheme: Option<String>,
|
|
25
|
+
userinfo: Option<String>,
|
|
26
|
+
host: Option<String>,
|
|
27
|
+
port: Option<Number>,
|
|
28
|
+
path: String,
|
|
29
|
+
query: Option<String>,
|
|
30
|
+
fragment: Option<String>,
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Represents a parsed RFC 3986 URI.
|
|
35
|
+
|
|
36
|
+
### Uri.**ParseError**
|
|
37
|
+
|
|
38
|
+
```grain
|
|
39
|
+
enum ParseError {
|
|
40
|
+
ParseError,
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Represents an error encountered while parsing a URI.
|
|
45
|
+
|
|
46
|
+
### Uri.**ConstructUriError**
|
|
47
|
+
|
|
48
|
+
```grain
|
|
49
|
+
enum ConstructUriError {
|
|
50
|
+
UserinfoWithNoHost,
|
|
51
|
+
PortWithNoHost,
|
|
52
|
+
InvalidSchemeError,
|
|
53
|
+
InvalidUserinfoError,
|
|
54
|
+
InvalidHostError,
|
|
55
|
+
InvalidPortError,
|
|
56
|
+
InvalidPathError,
|
|
57
|
+
InvalidQueryError,
|
|
58
|
+
InvalidFragmentError,
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Represents an error encountered while constructing a URI with `make` or `update`.
|
|
63
|
+
|
|
64
|
+
### Uri.**ResolveReferenceError**
|
|
65
|
+
|
|
66
|
+
```grain
|
|
67
|
+
enum ResolveReferenceError {
|
|
68
|
+
BaseNotAbsolute,
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Represents an error encountered while attempting to resolve a URI reference to a target URI.
|
|
73
|
+
|
|
74
|
+
### Uri.**DecodingError**
|
|
75
|
+
|
|
76
|
+
```grain
|
|
77
|
+
enum DecodingError {
|
|
78
|
+
InvalidEncoding,
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Represents an error encountered while attempting to percent-decode a string.
|
|
83
|
+
|
|
84
|
+
### Uri.**EncodeSet**
|
|
85
|
+
|
|
86
|
+
```grain
|
|
87
|
+
enum EncodeSet {
|
|
88
|
+
EncodeNonUnreserved,
|
|
89
|
+
EncodeUserinfo,
|
|
90
|
+
EncodeRegisteredHost,
|
|
91
|
+
EncodePath,
|
|
92
|
+
EncodePathSegment,
|
|
93
|
+
EncodeQueryOrFragment,
|
|
94
|
+
EncodeCustom((Char => Bool)),
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Used to specify which characters to percent-encode from a string.
|
|
99
|
+
|
|
100
|
+
## Values
|
|
101
|
+
|
|
102
|
+
Functions and constants included in the Uri module.
|
|
103
|
+
|
|
104
|
+
### Uri.**encode**
|
|
105
|
+
|
|
106
|
+
<details disabled>
|
|
107
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
108
|
+
No other changes yet.
|
|
109
|
+
</details>
|
|
110
|
+
|
|
111
|
+
```grain
|
|
112
|
+
encode : (str: String, ?encodeSet: EncodeSet) => String
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Percent-encodes characters in a string based on the specified `EncodeSet`.
|
|
116
|
+
|
|
117
|
+
Parameters:
|
|
118
|
+
|
|
119
|
+
|param|type|description|
|
|
120
|
+
|-----|----|-----------|
|
|
121
|
+
|`str`|`String`|The string to encode|
|
|
122
|
+
|`?encodeSet`|`EncodeSet`|An indication for which characters to percent-encode. `EncodeNonUnreserved` by default|
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
|
|
126
|
+
|type|description|
|
|
127
|
+
|----|-----------|
|
|
128
|
+
|`String`|A percent-encoding of the given string|
|
|
129
|
+
|
|
130
|
+
Examples:
|
|
131
|
+
|
|
132
|
+
```grain
|
|
133
|
+
Uri.encode("h3ll0_.w ?o+rld", encodeSet=Uri.EncodeNonUnreserved) // "h3ll0_.w%20%3Fo%2Brld"
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```grain
|
|
137
|
+
Uri.encode("d+om@i:n.com", encodeSet=Uri.EncodeRegisteredHost) // "d+om%40i%3An.com"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
```grain
|
|
141
|
+
Uri.encode("word", encodeSet=Uri.EncodeCustom(c => c == 'o')) // "w%6Frd"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Uri.**decode**
|
|
145
|
+
|
|
146
|
+
<details disabled>
|
|
147
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
148
|
+
No other changes yet.
|
|
149
|
+
</details>
|
|
150
|
+
|
|
151
|
+
```grain
|
|
152
|
+
decode : (str: String) => Result<String, DecodingError>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Decodes any percent-encoded characters in a string.
|
|
156
|
+
|
|
157
|
+
Parameters:
|
|
158
|
+
|
|
159
|
+
|param|type|description|
|
|
160
|
+
|-----|----|-----------|
|
|
161
|
+
|`str`|`String`|The string to decode|
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
|
|
165
|
+
|type|description|
|
|
166
|
+
|----|-----------|
|
|
167
|
+
|`Result<String, DecodingError>`|`Ok(decoded)` containing the decoded string or `Err(err)` if the decoding failed|
|
|
168
|
+
|
|
169
|
+
### Uri.**encodeQuery**
|
|
170
|
+
|
|
171
|
+
<details disabled>
|
|
172
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
173
|
+
No other changes yet.
|
|
174
|
+
</details>
|
|
175
|
+
|
|
176
|
+
```grain
|
|
177
|
+
encodeQuery :
|
|
178
|
+
(urlVals: List<(String, String)>, ?encodeSet: EncodeSet) => String
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Encodes a list of key-value pairs into an query string.
|
|
182
|
+
|
|
183
|
+
Parameters:
|
|
184
|
+
|
|
185
|
+
|param|type|description|
|
|
186
|
+
|-----|----|-----------|
|
|
187
|
+
|`urlVals`|`List<(String, String)>`|A list of key-value pairs|
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
|
|
191
|
+
|type|description|
|
|
192
|
+
|----|-----------|
|
|
193
|
+
|`String`|A query string|
|
|
194
|
+
|
|
195
|
+
### Uri.**decodeQuery**
|
|
196
|
+
|
|
197
|
+
<details disabled>
|
|
198
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
199
|
+
No other changes yet.
|
|
200
|
+
</details>
|
|
201
|
+
|
|
202
|
+
```grain
|
|
203
|
+
decodeQuery : (str: String) => Result<List<(String, String)>, DecodingError>
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Decodes a query string into a list of pairs.
|
|
207
|
+
|
|
208
|
+
Parameters:
|
|
209
|
+
|
|
210
|
+
|param|type|description|
|
|
211
|
+
|-----|----|-----------|
|
|
212
|
+
|`str`|`String`|A query string|
|
|
213
|
+
|
|
214
|
+
Returns:
|
|
215
|
+
|
|
216
|
+
|type|description|
|
|
217
|
+
|----|-----------|
|
|
218
|
+
|`Result<List<(String, String)>, DecodingError>`|`Ok(decoded)` containing a list of key-value pairs from the decoded string or `Err(err)` if the decoding failed|
|
|
219
|
+
|
|
220
|
+
### Uri.**parse**
|
|
221
|
+
|
|
222
|
+
<details disabled>
|
|
223
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
224
|
+
No other changes yet.
|
|
225
|
+
</details>
|
|
226
|
+
|
|
227
|
+
```grain
|
|
228
|
+
parse : (str: String) => Result<Uri, ParseError>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Parses a string into a `Uri` according to RFC 3986. If the URI string has a
|
|
232
|
+
path it will be automatically normalized, removing unnecessary `.` and `..`
|
|
233
|
+
segments.
|
|
234
|
+
|
|
235
|
+
Parameters:
|
|
236
|
+
|
|
237
|
+
|param|type|description|
|
|
238
|
+
|-----|----|-----------|
|
|
239
|
+
|`str`|`String`|The RFC 3986 URI string to parse|
|
|
240
|
+
|
|
241
|
+
Returns:
|
|
242
|
+
|
|
243
|
+
|type|description|
|
|
244
|
+
|----|-----------|
|
|
245
|
+
|`Result<Uri, ParseError>`|`Ok(uri)` containing a `Uri` if the given string is a valid URI or `Err(ParseError)` otherwise|
|
|
246
|
+
|
|
247
|
+
Examples:
|
|
248
|
+
|
|
249
|
+
```grain
|
|
250
|
+
Uri.parse("https://grain-lang.org") == Ok(...)
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
```grain
|
|
254
|
+
Uri.parse("http://@*^%") == Err(Uri.ParseError)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Uri.**resolveReference**
|
|
258
|
+
|
|
259
|
+
<details disabled>
|
|
260
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
261
|
+
No other changes yet.
|
|
262
|
+
</details>
|
|
263
|
+
|
|
264
|
+
```grain
|
|
265
|
+
resolveReference :
|
|
266
|
+
(base: Uri, ref: Uri) => Result<Uri, ResolveReferenceError>
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Transforms a base URI and a URI reference into a target URI
|
|
270
|
+
|
|
271
|
+
Parameters:
|
|
272
|
+
|
|
273
|
+
|param|type|description|
|
|
274
|
+
|-----|----|-----------|
|
|
275
|
+
|`base`|`Uri`|The base URI to resolve a URI reference on|
|
|
276
|
+
|`ref`|`Uri`|The URI reference to apply onto the base|
|
|
277
|
+
|
|
278
|
+
Returns:
|
|
279
|
+
|
|
280
|
+
|type|description|
|
|
281
|
+
|----|-----------|
|
|
282
|
+
|`Result<Uri, ResolveReferenceError>`|`Ok(uri)` containing the target `Uri` or `Err(err)` if the input is malformed|
|
|
283
|
+
|
|
284
|
+
Examples:
|
|
285
|
+
|
|
286
|
+
```grain
|
|
287
|
+
resolveReference(unwrap(parse("https://grain-lang.org/docs/stdlib/uri")), unwrap(parse("../intro"))) // https://grain-lang.org/docs/intro
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
```grain
|
|
291
|
+
resolveReference(unwrap(parse("https://grain-lang.org/docs")), unwrap(parse("?key=val"))) // https://grain-lang.org/docs?key=val
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
```grain
|
|
295
|
+
resolveReference(unwrap(parse("https://grain-lang.org/docs")), unwrap(parse("google.com/search"))) // https://google.com/search
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Uri.**make**
|
|
299
|
+
|
|
300
|
+
<details disabled>
|
|
301
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
302
|
+
No other changes yet.
|
|
303
|
+
</details>
|
|
304
|
+
|
|
305
|
+
```grain
|
|
306
|
+
make :
|
|
307
|
+
(?scheme: Option<String>, ?userinfo: Option<String>, ?host: Option<String>,
|
|
308
|
+
?port: Option<Number>, ?path: String, ?query: Option<String>,
|
|
309
|
+
?fragment: Option<String>, ?encodeComponents: Bool) =>
|
|
310
|
+
Result<Uri, ConstructUriError>
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Constructs a new `Uri` from components.
|
|
314
|
+
|
|
315
|
+
Parameters:
|
|
316
|
+
|
|
317
|
+
|param|type|description|
|
|
318
|
+
|-----|----|-----------|
|
|
319
|
+
|`?scheme`|`Option<String>`|`Some(scheme)` containing the desired scheme component or `None` for a scheme-less URI|
|
|
320
|
+
|`?userinfo`|`Option<String>`|`Some(userinfo)` containing the desired userinfo component or `None` for a userinfo-less URI|
|
|
321
|
+
|`?host`|`Option<String>`|`Some(host)` containing the desired host component or `None` for a host-less URI|
|
|
322
|
+
|`?port`|`Option<Number>`|`Some(port)` containing the desired port component or `None` for a port-less URI|
|
|
323
|
+
|`?path`|`String`|The desired path for the URI. `""` by default|
|
|
324
|
+
|`?query`|`Option<String>`|`Some(query)` containing the desired query string component or `None` for a query-less URI|
|
|
325
|
+
|`?fragment`|`Option<String>`|`Some(fragment)` containing the desired fragment component or `None` for a fragment-less URI|
|
|
326
|
+
|`?encodeComponents`|`Bool`|Whether or not to apply percent encoding for each component to remove unsafe characters for each component|
|
|
327
|
+
|
|
328
|
+
Examples:
|
|
329
|
+
|
|
330
|
+
```grain
|
|
331
|
+
Uri.make(scheme=Some("https"), host=Some("grain-lang.org")) // https://grain-lang.org
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
```grain
|
|
335
|
+
Uri.make(host=Some("g/r@in"), encodeComponents=false) // Err(Uri.InvalidHostError)
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
```grain
|
|
339
|
+
Uri.make(scheme=Some("abc"), host=Some("g/r@in"), query=Some("k/ey=v^@l"), encodeComponents=true) // abc://g%2Fr%40in?k/ey=v%5E@l
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
```grain
|
|
343
|
+
Uri.make(port=Some(80)) // Err(Uri.PortWithNoHost)
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Uri.**update**
|
|
347
|
+
|
|
348
|
+
<details disabled>
|
|
349
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
350
|
+
No other changes yet.
|
|
351
|
+
</details>
|
|
352
|
+
|
|
353
|
+
```grain
|
|
354
|
+
update :
|
|
355
|
+
(uri: Uri, ?scheme: Option<Option<String>>,
|
|
356
|
+
?userinfo: Option<Option<String>>, ?host: Option<Option<String>>,
|
|
357
|
+
?port: Option<Option<Number>>, ?path: Option<String>,
|
|
358
|
+
?query: Option<Option<String>>, ?fragment: Option<Option<String>>,
|
|
359
|
+
?encodeComponents: Bool) => Result<Uri, ConstructUriError>
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Constructs a new `Uri` from a base `Uri` and components to update. The
|
|
363
|
+
pattern used to update each component is that `None` means the base URI's
|
|
364
|
+
component should be used and `Some(val)` means that a new value should be
|
|
365
|
+
used for that component.
|
|
366
|
+
|
|
367
|
+
Parameters:
|
|
368
|
+
|
|
369
|
+
|param|type|description|
|
|
370
|
+
|-----|----|-----------|
|
|
371
|
+
|`uri`|`Uri`|The `Uri` to update|
|
|
372
|
+
|`?scheme`|`Option<Option<String>>`|`Some(scheme)` containing the desired updated scheme component or `None` to maintain the base URI's scheme|
|
|
373
|
+
|`?userinfo`|`Option<Option<String>>`|`Some(userinfo)` containing the desired updated userinfo component or `None` to maintain the base URI's userinfo|
|
|
374
|
+
|`?host`|`Option<Option<String>>`|`Some(host)` containing the desired updated host component or `None` to maintain the base URI's host|
|
|
375
|
+
|`?port`|`Option<Option<Number>>`|`Some(port)` containing the desired updated port component or `None` to maintain the base URI's port|
|
|
376
|
+
|`?path`|`Option<String>`|`Some(path)` containing the desired updated path component or `None` to maintain the base URI's path|
|
|
377
|
+
|`?query`|`Option<Option<String>>`|`Some(query)` containing the desired updated query string component or `None` to maintain the base URI's query|
|
|
378
|
+
|`?fragment`|`Option<Option<String>>`|`Some(fragment)` containing the desired updated fragment component or `None` to maintain the base URI's fragment|
|
|
379
|
+
|`?encodeComponents`|`Bool`|Whether or not to apply percent encoding for each updated component to remove unsafe characters|
|
|
380
|
+
|
|
381
|
+
Examples:
|
|
382
|
+
|
|
383
|
+
```grain
|
|
384
|
+
let uri = Result.unwrap(Uri.parse("https://grain-lang.org/docs?k=v")) // Base URI for following examples
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
```grain
|
|
388
|
+
Uri.update(uri, scheme=Some(Some("ftp"))) // ftp://grain-lang.org/docs?k=v
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
```grain
|
|
392
|
+
Uri.update(uri, query=Some(None)) // https://grain-lang.org/docs
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
```grain
|
|
396
|
+
Uri.update(uri, host=Some(Some("g/r@in")), encodeComponents=true) // https://g%2Fr%40in/docs?k=v
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
```grain
|
|
400
|
+
Uri.update(uri, host=Some(None), port=Some(Some(80))) // Err(Uri.PortWithNoHost)
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### Uri.**hasAuthority**
|
|
404
|
+
|
|
405
|
+
<details disabled>
|
|
406
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
407
|
+
No other changes yet.
|
|
408
|
+
</details>
|
|
409
|
+
|
|
410
|
+
```grain
|
|
411
|
+
hasAuthority : (uri: Uri) => Bool
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
Determines whether a `Uri` has an authority (i.e. has a host component)
|
|
415
|
+
|
|
416
|
+
Parameters:
|
|
417
|
+
|
|
418
|
+
|param|type|description|
|
|
419
|
+
|-----|----|-----------|
|
|
420
|
+
|`uri`|`Uri`|The `Uri` to consider|
|
|
421
|
+
|
|
422
|
+
Returns:
|
|
423
|
+
|
|
424
|
+
|type|description|
|
|
425
|
+
|----|-----------|
|
|
426
|
+
|`Bool`|`true` if the `Uri` has an authority component or `false` otherwise|
|
|
427
|
+
|
|
428
|
+
### Uri.**isAbsolute**
|
|
429
|
+
|
|
430
|
+
<details disabled>
|
|
431
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
432
|
+
No other changes yet.
|
|
433
|
+
</details>
|
|
434
|
+
|
|
435
|
+
```grain
|
|
436
|
+
isAbsolute : (uri: Uri) => Bool
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
Determines whether a `Uri` is an absolute URI (has a scheme component)
|
|
440
|
+
|
|
441
|
+
Parameters:
|
|
442
|
+
|
|
443
|
+
|param|type|description|
|
|
444
|
+
|-----|----|-----------|
|
|
445
|
+
|`uri`|`Uri`|The `Uri` to consider|
|
|
446
|
+
|
|
447
|
+
Returns:
|
|
448
|
+
|
|
449
|
+
|type|description|
|
|
450
|
+
|----|-----------|
|
|
451
|
+
|`Bool`|`true` if the `Uri` is absolute (has a scheme component) or `false` otherwise|
|
|
452
|
+
|
|
453
|
+
### Uri.**toString**
|
|
454
|
+
|
|
455
|
+
<details disabled>
|
|
456
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
457
|
+
No other changes yet.
|
|
458
|
+
</details>
|
|
459
|
+
|
|
460
|
+
```grain
|
|
461
|
+
toString : (uri: Uri) => String
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
Converts the given `Uri` into a string.
|
|
465
|
+
|
|
466
|
+
Parameters:
|
|
467
|
+
|
|
468
|
+
|param|type|description|
|
|
469
|
+
|-----|----|-----------|
|
|
470
|
+
|`uri`|`Uri`|The `Uri` to convert|
|
|
471
|
+
|
|
472
|
+
Returns:
|
|
473
|
+
|
|
474
|
+
|type|description|
|
|
475
|
+
|----|-----------|
|
|
476
|
+
|`String`|A string representation of the `Uri`|
|
|
477
|
+
|