@grain/stdlib 0.6.6 → 0.7.1
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 +67 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/array.gr +55 -7
- package/array.md +606 -560
- package/bigint.md +228 -228
- package/buffer.gr +85 -53
- package/buffer.md +442 -319
- package/bytes.gr +112 -35
- package/bytes.md +299 -219
- package/char.gr +201 -99
- package/char.md +447 -120
- package/exception.gr +11 -11
- package/exception.md +29 -4
- package/float32.gr +327 -3
- package/float32.md +698 -111
- package/float64.gr +320 -3
- package/float64.md +698 -111
- package/fs.gr +1082 -0
- package/fs.md +630 -0
- package/hash.gr +142 -88
- package/hash.md +105 -17
- package/int16.md +178 -178
- package/int32.gr +26 -5
- package/int32.md +266 -231
- package/int64.gr +27 -2
- package/int64.md +266 -231
- package/int8.md +178 -178
- package/json.gr +366 -51
- package/json.md +431 -15
- package/list.gr +328 -31
- package/list.md +759 -336
- package/map.gr +20 -12
- package/map.md +266 -260
- package/marshal.gr +41 -40
- package/marshal.md +14 -14
- package/number.gr +278 -35
- package/number.md +688 -269
- package/option.md +162 -162
- package/package.json +5 -3
- package/path.gr +48 -0
- package/path.md +180 -89
- package/pervasives.gr +2 -2
- package/pervasives.md +275 -275
- package/priorityqueue.gr +7 -7
- package/priorityqueue.md +131 -131
- package/queue.gr +183 -29
- package/queue.md +404 -148
- package/random.md +43 -43
- package/range.gr +4 -4
- package/range.md +42 -42
- package/rational.md +123 -123
- package/regex.gr +52 -51
- package/regex.md +102 -102
- package/result.md +118 -118
- package/runtime/atof/common.md +39 -39
- package/runtime/atof/decimal.gr +6 -6
- package/runtime/atof/decimal.md +14 -14
- package/runtime/atof/lemire.gr +5 -5
- package/runtime/atof/lemire.md +1 -1
- package/runtime/atof/parse.gr +16 -16
- package/runtime/atof/parse.md +2 -2
- package/runtime/atof/slow.md +1 -1
- package/runtime/atof/table.md +2 -2
- package/runtime/atoi/parse.gr +3 -3
- package/runtime/atoi/parse.md +1 -1
- package/runtime/bigint.gr +15 -47
- package/runtime/bigint.md +54 -60
- package/runtime/compare.gr +2 -2
- package/runtime/compare.md +8 -8
- package/runtime/dataStructures.md +211 -211
- package/runtime/debugPrint.gr +4 -1
- package/runtime/debugPrint.md +9 -9
- package/runtime/equal.gr +99 -77
- package/runtime/equal.md +8 -8
- package/runtime/exception.gr +62 -82
- package/runtime/exception.md +62 -11
- package/runtime/gc.gr +39 -45
- package/runtime/gc.md +4 -4
- package/runtime/malloc.gr +7 -7
- package/runtime/malloc.md +13 -13
- package/runtime/math/kernel/cos.gr +70 -0
- package/runtime/math/kernel/cos.md +14 -0
- package/runtime/math/kernel/sin.gr +65 -0
- package/runtime/math/kernel/sin.md +14 -0
- package/runtime/math/kernel/tan.gr +136 -0
- package/runtime/math/kernel/tan.md +14 -0
- package/runtime/math/rempio2.gr +244 -0
- package/runtime/math/rempio2.md +14 -0
- package/runtime/math/trig.gr +130 -0
- package/runtime/math/trig.md +28 -0
- package/runtime/math/umuldi.gr +26 -0
- package/runtime/math/umuldi.md +14 -0
- package/runtime/numberUtils.gr +29 -29
- package/runtime/numberUtils.md +12 -12
- package/runtime/numbers.gr +373 -381
- package/runtime/numbers.md +348 -342
- package/runtime/string.gr +37 -105
- package/runtime/string.md +20 -26
- package/runtime/unsafe/constants.md +24 -24
- package/runtime/unsafe/conv.md +19 -19
- package/runtime/unsafe/memory.gr +24 -20
- package/runtime/unsafe/memory.md +27 -7
- package/runtime/unsafe/offsets.gr +36 -0
- package/runtime/unsafe/offsets.md +88 -0
- package/runtime/unsafe/panic.gr +28 -0
- package/runtime/unsafe/panic.md +14 -0
- package/runtime/unsafe/tags.md +32 -32
- package/runtime/unsafe/wasmf32.md +28 -28
- package/runtime/unsafe/wasmf64.md +28 -28
- package/runtime/unsafe/wasmi32.md +47 -47
- package/runtime/unsafe/wasmi64.md +50 -50
- package/runtime/utf8.gr +189 -0
- package/runtime/utf8.md +117 -0
- package/runtime/wasi.gr +4 -2
- package/runtime/wasi.md +147 -147
- package/set.gr +18 -11
- package/set.md +253 -247
- package/stack.gr +171 -2
- package/stack.md +371 -89
- package/string.gr +352 -557
- package/string.md +298 -255
- package/uint16.md +170 -170
- package/uint32.gr +25 -4
- package/uint32.md +249 -214
- package/uint64.gr +25 -5
- package/uint64.md +249 -214
- package/uint8.md +170 -170
- package/uri.gr +57 -53
- package/uri.md +88 -89
- package/wasi/file.gr +67 -59
- package/wasi/file.md +308 -308
- package/wasi/process.md +26 -26
- package/wasi/random.md +12 -12
- package/wasi/time.md +16 -16
- package/runtime/utils/printing.gr +0 -60
- package/runtime/utils/printing.md +0 -26
package/uri.gr
CHANGED
|
@@ -82,18 +82,18 @@ provide enum EncodeSet {
|
|
|
82
82
|
|
|
83
83
|
let isHexDigit = char => {
|
|
84
84
|
use Char.{ (<=), (>=) }
|
|
85
|
-
Char.
|
|
86
|
-
char >= 'A' && char <= 'F'
|
|
87
|
-
char >= 'a' && char <= 'f'
|
|
85
|
+
Char.Ascii.isDigit(char)
|
|
86
|
+
|| char >= 'A' && char <= 'F'
|
|
87
|
+
|| char >= 'a' && char <= 'f'
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
let isUnreservedChar = char => {
|
|
91
|
-
Char.
|
|
92
|
-
Char.
|
|
93
|
-
char == '-'
|
|
94
|
-
char == '.'
|
|
95
|
-
char == '_'
|
|
96
|
-
char == '~'
|
|
91
|
+
Char.Ascii.isDigit(char)
|
|
92
|
+
|| Char.Ascii.isAlpha(char)
|
|
93
|
+
|| char == '-'
|
|
94
|
+
|| char == '.'
|
|
95
|
+
|| char == '_'
|
|
96
|
+
|| char == '~'
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
let isSubDelim = char => {
|
|
@@ -142,10 +142,10 @@ let makeEncoder = (encodeSet: EncodeSet) => {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
let charToHexValue = char => {
|
|
145
|
-
if (Char.
|
|
145
|
+
if (Char.Ascii.isDigit(char)) {
|
|
146
146
|
Char.code(char) - 0x30
|
|
147
147
|
} else {
|
|
148
|
-
let char = Char.
|
|
148
|
+
let char = Char.Ascii.toLowercase(char)
|
|
149
149
|
Char.code(char) - 0x60 + 9
|
|
150
150
|
}
|
|
151
151
|
}
|
|
@@ -173,8 +173,8 @@ let decodeValid = (str, onlyUnreserved=false) => {
|
|
|
173
173
|
let pctDecodedVal = charToHexValue(next) * 16 + charToHexValue(nextNext)
|
|
174
174
|
if (onlyUnreserved && !isUnreservedChar(Char.fromCode(pctDecodedVal))) {
|
|
175
175
|
Buffer.addChar('%', out)
|
|
176
|
-
Buffer.addChar(Char.
|
|
177
|
-
Buffer.addChar(Char.
|
|
176
|
+
Buffer.addChar(Char.Ascii.toUppercase(next), out)
|
|
177
|
+
Buffer.addChar(Char.Ascii.toUppercase(nextNext), out)
|
|
178
178
|
} else {
|
|
179
179
|
Buffer.addUint8(Uint8.fromNumber(pctDecodedVal), out)
|
|
180
180
|
}
|
|
@@ -189,8 +189,12 @@ let isValidEncoding = str => {
|
|
|
189
189
|
let len = Array.length(chars)
|
|
190
190
|
for (let mut i = 0; i < len; i += 1) {
|
|
191
191
|
if (
|
|
192
|
-
chars[i] == '%'
|
|
193
|
-
|
|
192
|
+
chars[i] == '%'
|
|
193
|
+
&& (
|
|
194
|
+
i >= len - 2
|
|
195
|
+
|| !isHexDigit(chars[i + 1])
|
|
196
|
+
|| !isHexDigit(chars[i + 2])
|
|
197
|
+
)
|
|
194
198
|
) {
|
|
195
199
|
return false
|
|
196
200
|
}
|
|
@@ -209,7 +213,7 @@ let normalizeHost = str => {
|
|
|
209
213
|
} else if (i >= 2 && chars[i - 2] == '%') {
|
|
210
214
|
getChars(i - 3, ['%', chars[i - 1], chars[i], ...acc])
|
|
211
215
|
} else {
|
|
212
|
-
getChars(i - 1, [Char.
|
|
216
|
+
getChars(i - 1, [Char.Ascii.toLowercase(chars[i]), ...acc])
|
|
213
217
|
}
|
|
214
218
|
}
|
|
215
219
|
let chars = getChars(String.length(str) - 1, [])
|
|
@@ -259,15 +263,15 @@ let removeDotSegments = path => {
|
|
|
259
263
|
|
|
260
264
|
/**
|
|
261
265
|
* Percent-encodes characters in a string based on the specified `EncodeSet`.
|
|
262
|
-
*
|
|
266
|
+
*
|
|
263
267
|
* @param str: The string to encode
|
|
264
268
|
* @param encodeSet: An indication for which characters to percent-encode. `EncodeNonUnreserved` by default
|
|
265
269
|
* @returns A percent-encoding of the given string
|
|
266
|
-
*
|
|
270
|
+
*
|
|
267
271
|
* @example Uri.encode("h3ll0_.w ?o+rld", encodeSet=Uri.EncodeNonUnreserved) // "h3ll0_.w%20%3Fo%2Brld"
|
|
268
272
|
* @example Uri.encode("d+om@i:n.com", encodeSet=Uri.EncodeRegisteredHost) // "d+om%40i%3An.com"
|
|
269
273
|
* @example Uri.encode("word", encodeSet=Uri.EncodeCustom(c => c == 'o')) // "w%6Frd"
|
|
270
|
-
*
|
|
274
|
+
*
|
|
271
275
|
* @since v0.6.0
|
|
272
276
|
*/
|
|
273
277
|
provide let encode = (str, encodeSet=EncodeNonUnreserved) => {
|
|
@@ -301,10 +305,10 @@ provide let encode = (str, encodeSet=EncodeNonUnreserved) => {
|
|
|
301
305
|
|
|
302
306
|
/**
|
|
303
307
|
* Decodes any percent-encoded characters in a string.
|
|
304
|
-
*
|
|
308
|
+
*
|
|
305
309
|
* @param str: The string to decode
|
|
306
310
|
* @returns `Ok(decoded)` containing the decoded string or `Err(err)` if the decoding failed
|
|
307
|
-
*
|
|
311
|
+
*
|
|
308
312
|
* @since v0.6.0
|
|
309
313
|
*/
|
|
310
314
|
provide let decode = str => {
|
|
@@ -317,10 +321,10 @@ provide let decode = str => {
|
|
|
317
321
|
|
|
318
322
|
/**
|
|
319
323
|
* Encodes a list of key-value pairs into an query string.
|
|
320
|
-
*
|
|
324
|
+
*
|
|
321
325
|
* @param urlVals: A list of key-value pairs
|
|
322
326
|
* @returns A query string
|
|
323
|
-
*
|
|
327
|
+
*
|
|
324
328
|
* @since v0.6.0
|
|
325
329
|
*/
|
|
326
330
|
provide let encodeQuery = (urlVals, encodeSet=EncodeNonUnreserved) => {
|
|
@@ -333,10 +337,10 @@ provide let encodeQuery = (urlVals, encodeSet=EncodeNonUnreserved) => {
|
|
|
333
337
|
|
|
334
338
|
/**
|
|
335
339
|
* Decodes a query string into a list of pairs.
|
|
336
|
-
*
|
|
340
|
+
*
|
|
337
341
|
* @param str: A query string
|
|
338
342
|
* @returns `Ok(decoded)` containing a list of key-value pairs from the decoded string or `Err(err)` if the decoding failed
|
|
339
|
-
*
|
|
343
|
+
*
|
|
340
344
|
* @since v0.6.0
|
|
341
345
|
*/
|
|
342
346
|
provide let decodeQuery = str => {
|
|
@@ -419,7 +423,7 @@ module Matchers {
|
|
|
419
423
|
}
|
|
420
424
|
}
|
|
421
425
|
|
|
422
|
-
provide let digit = charTest(Char.
|
|
426
|
+
provide let digit = charTest(Char.Ascii.isDigit)
|
|
423
427
|
|
|
424
428
|
provide let digitInRange = (low, high) => charTest(char => {
|
|
425
429
|
let code = Char.code(char)
|
|
@@ -427,7 +431,7 @@ module Matchers {
|
|
|
427
431
|
code >= zero + low && code <= zero + high
|
|
428
432
|
})
|
|
429
433
|
|
|
430
|
-
provide let alpha = charTest(Char.
|
|
434
|
+
provide let alpha = charTest(Char.Ascii.isAlpha)
|
|
431
435
|
|
|
432
436
|
provide let hexDigit = charTest(isHexDigit)
|
|
433
437
|
|
|
@@ -698,13 +702,13 @@ let parseFragment = (i, str, withDelim=false) => {
|
|
|
698
702
|
* Parses a string into a `Uri` according to RFC 3986. If the URI string has a
|
|
699
703
|
* path it will be automatically normalized, removing unnecessary `.` and `..`
|
|
700
704
|
* segments.
|
|
701
|
-
*
|
|
705
|
+
*
|
|
702
706
|
* @param str: The RFC 3986 URI string to parse
|
|
703
707
|
* @returns `Ok(uri)` containing a `Uri` if the given string is a valid URI or `Err(ParseError)` otherwise
|
|
704
|
-
*
|
|
708
|
+
*
|
|
705
709
|
* @example Uri.parse("https://grain-lang.org") == Ok(...)
|
|
706
710
|
* @example Uri.parse("http://@*^%") == Err(Uri.ParseError)
|
|
707
|
-
*
|
|
711
|
+
*
|
|
708
712
|
* @since v0.6.0
|
|
709
713
|
*/
|
|
710
714
|
provide let parse = str => {
|
|
@@ -727,15 +731,15 @@ provide let parse = str => {
|
|
|
727
731
|
|
|
728
732
|
/**
|
|
729
733
|
* Transforms a base URI and a URI reference into a target URI
|
|
730
|
-
*
|
|
734
|
+
*
|
|
731
735
|
* @param base: The base URI to resolve a URI reference on
|
|
732
736
|
* @param ref: The URI reference to apply onto the base
|
|
733
737
|
* @returns `Ok(uri)` containing the target `Uri` or `Err(err)` if the input is malformed
|
|
734
|
-
*
|
|
738
|
+
*
|
|
735
739
|
* @example resolveReference(unwrap(parse("https://grain-lang.org/docs/stdlib/uri")), unwrap(parse("../intro"))) // https://grain-lang.org/docs/intro
|
|
736
740
|
* @example resolveReference(unwrap(parse("https://grain-lang.org/docs")), unwrap(parse("?key=val"))) // https://grain-lang.org/docs?key=val
|
|
737
741
|
* @example resolveReference(unwrap(parse("https://grain-lang.org/docs")), unwrap(parse("google.com/search"))) // https://google.com/search
|
|
738
|
-
*
|
|
742
|
+
*
|
|
739
743
|
* @since v0.6.0
|
|
740
744
|
*/
|
|
741
745
|
provide let resolveReference = (base, ref) => {
|
|
@@ -779,7 +783,7 @@ provide let resolveReference = (base, ref) => {
|
|
|
779
783
|
|
|
780
784
|
/**
|
|
781
785
|
* Constructs a new `Uri` from components.
|
|
782
|
-
*
|
|
786
|
+
*
|
|
783
787
|
* @param scheme: `Some(scheme)` containing the desired scheme component or `None` for a scheme-less URI
|
|
784
788
|
* @param userinfo: `Some(userinfo)` containing the desired userinfo component or `None` for a userinfo-less URI
|
|
785
789
|
* @param host: `Some(host)` containing the desired host component or `None` for a host-less URI
|
|
@@ -788,12 +792,12 @@ provide let resolveReference = (base, ref) => {
|
|
|
788
792
|
* @param query: `Some(query)` containing the desired query string component or `None` for a query-less URI
|
|
789
793
|
* @param fragment: `Some(fragment)` containing the desired fragment component or `None` for a fragment-less URI
|
|
790
794
|
* @param encodeComponents: Whether or not to apply percent encoding for each component to remove unsafe characters for each component
|
|
791
|
-
*
|
|
795
|
+
*
|
|
792
796
|
* @example Uri.make(scheme=Some("https"), host=Some("grain-lang.org")) // https://grain-lang.org
|
|
793
797
|
* @example Uri.make(host=Some("g/r@in"), encodeComponents=false) // Err(Uri.InvalidHostError)
|
|
794
798
|
* @example 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
|
|
795
799
|
* @example Uri.make(port=Some(80)) // Err(Uri.PortWithNoHost)
|
|
796
|
-
*
|
|
800
|
+
*
|
|
797
801
|
* @since v0.6.0
|
|
798
802
|
*/
|
|
799
803
|
provide let make = (
|
|
@@ -909,7 +913,7 @@ enum UpdateAction<a> {
|
|
|
909
913
|
* pattern used to update each component is that `None` means the base URI's
|
|
910
914
|
* component should be used and `Some(val)` means that a new value should be
|
|
911
915
|
* used for that component.
|
|
912
|
-
*
|
|
916
|
+
*
|
|
913
917
|
* @param uri: The `Uri` to update
|
|
914
918
|
* @param scheme: `Some(scheme)` containing the desired updated scheme component or `None` to maintain the base URI's scheme
|
|
915
919
|
* @param userinfo: `Some(userinfo)` containing the desired updated userinfo component or `None` to maintain the base URI's userinfo
|
|
@@ -919,13 +923,13 @@ enum UpdateAction<a> {
|
|
|
919
923
|
* @param query: `Some(query)` containing the desired updated query string component or `None` to maintain the base URI's query
|
|
920
924
|
* @param fragment: `Some(fragment)` containing the desired updated fragment component or `None` to maintain the base URI's fragment
|
|
921
925
|
* @param encodeComponents: Whether or not to apply percent encoding for each updated component to remove unsafe characters
|
|
922
|
-
*
|
|
926
|
+
*
|
|
923
927
|
* @example let uri = Result.unwrap(Uri.parse("https://grain-lang.org/docs?k=v")) // Base URI for following examples
|
|
924
928
|
* @example Uri.update(uri, scheme=Some(Some("ftp"))) // ftp://grain-lang.org/docs?k=v
|
|
925
929
|
* @example Uri.update(uri, query=Some(None)) // https://grain-lang.org/docs
|
|
926
930
|
* @example Uri.update(uri, host=Some(Some("g/r@in")), encodeComponents=true) // https://g%2Fr%40in/docs?k=v
|
|
927
931
|
* @example Uri.update(uri, host=Some(None), port=Some(Some(80))) // Err(Uri.PortWithNoHost)
|
|
928
|
-
*
|
|
932
|
+
*
|
|
929
933
|
* @since v0.6.0
|
|
930
934
|
*/
|
|
931
935
|
provide let update = (
|
|
@@ -1053,41 +1057,41 @@ provide let update = (
|
|
|
1053
1057
|
|
|
1054
1058
|
/**
|
|
1055
1059
|
* Determines whether a `Uri` has an authority (i.e. has a host component)
|
|
1056
|
-
*
|
|
1060
|
+
*
|
|
1057
1061
|
* @param uri: The `Uri` to consider
|
|
1058
1062
|
* @returns `true` if the `Uri` has an authority component or `false` otherwise
|
|
1059
|
-
*
|
|
1063
|
+
*
|
|
1060
1064
|
* @since v0.6.0
|
|
1061
1065
|
*/
|
|
1062
1066
|
provide let hasAuthority = uri => uri.host != None
|
|
1063
1067
|
|
|
1064
1068
|
/**
|
|
1065
1069
|
* Determines whether a `Uri` is an absolute URI (has a scheme component)
|
|
1066
|
-
*
|
|
1070
|
+
*
|
|
1067
1071
|
* @param uri: The `Uri` to consider
|
|
1068
1072
|
* @returns `true` if the `Uri` is absolute (has a scheme component) or `false` otherwise
|
|
1069
|
-
*
|
|
1073
|
+
*
|
|
1070
1074
|
* @since v0.6.0
|
|
1071
1075
|
*/
|
|
1072
1076
|
provide let isAbsolute = uri => uri.scheme != None
|
|
1073
1077
|
|
|
1074
1078
|
/**
|
|
1075
1079
|
* Converts the given `Uri` into a string.
|
|
1076
|
-
*
|
|
1080
|
+
*
|
|
1077
1081
|
* @param uri: The `Uri` to convert
|
|
1078
1082
|
* @returns A string representation of the `Uri`
|
|
1079
|
-
*
|
|
1083
|
+
*
|
|
1080
1084
|
* @since v0.6.0
|
|
1081
1085
|
*/
|
|
1082
1086
|
provide let toString = uri => {
|
|
1083
1087
|
let optStr = (opt, display) => Option.mapWithDefault(display, "", opt)
|
|
1084
1088
|
|
|
1085
|
-
optStr(uri.scheme, s => s ++ ":")
|
|
1086
|
-
optStr(uri.host, (_) => "//")
|
|
1087
|
-
optStr(uri.userinfo, u => u ++ "@")
|
|
1088
|
-
optStr(uri.host, identity)
|
|
1089
|
-
optStr(uri.port, p => ":" ++ toString(p))
|
|
1090
|
-
uri.path
|
|
1091
|
-
optStr(uri.query, q => "?" ++ q)
|
|
1092
|
-
optStr(uri.fragment, f => "#" ++ f)
|
|
1089
|
+
optStr(uri.scheme, s => s ++ ":")
|
|
1090
|
+
++ optStr(uri.host, (_) => "//")
|
|
1091
|
+
++ optStr(uri.userinfo, u => u ++ "@")
|
|
1092
|
+
++ optStr(uri.host, identity)
|
|
1093
|
+
++ optStr(uri.port, p => ":" ++ toString(p))
|
|
1094
|
+
++ uri.path
|
|
1095
|
+
++ optStr(uri.query, q => "?" ++ q)
|
|
1096
|
+
++ optStr(uri.fragment, f => "#" ++ f)
|
|
1093
1097
|
}
|
package/uri.md
CHANGED
|
@@ -109,23 +109,23 @@ No other changes yet.
|
|
|
109
109
|
</details>
|
|
110
110
|
|
|
111
111
|
```grain
|
|
112
|
-
encode
|
|
112
|
+
encode: (str: String, ?encodeSet: EncodeSet) => String
|
|
113
113
|
```
|
|
114
114
|
|
|
115
115
|
Percent-encodes characters in a string based on the specified `EncodeSet`.
|
|
116
116
|
|
|
117
117
|
Parameters:
|
|
118
118
|
|
|
119
|
-
|param|type|description|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
123
|
|
|
124
124
|
Returns:
|
|
125
125
|
|
|
126
|
-
|type|description|
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
| type | description |
|
|
127
|
+
| -------- | -------------------------------------- |
|
|
128
|
+
| `String` | A percent-encoding of the given string |
|
|
129
129
|
|
|
130
130
|
Examples:
|
|
131
131
|
|
|
@@ -149,22 +149,22 @@ No other changes yet.
|
|
|
149
149
|
</details>
|
|
150
150
|
|
|
151
151
|
```grain
|
|
152
|
-
decode
|
|
152
|
+
decode: (str: String) => Result<String, DecodingError>
|
|
153
153
|
```
|
|
154
154
|
|
|
155
155
|
Decodes any percent-encoded characters in a string.
|
|
156
156
|
|
|
157
157
|
Parameters:
|
|
158
158
|
|
|
159
|
-
|param|type|description|
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
| param | type | description |
|
|
160
|
+
| ----- | -------- | -------------------- |
|
|
161
|
+
| `str` | `String` | The string to decode |
|
|
162
162
|
|
|
163
163
|
Returns:
|
|
164
164
|
|
|
165
|
-
|type|description|
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
| type | description |
|
|
166
|
+
| ------------------------------- | -------------------------------------------------------------------------------- |
|
|
167
|
+
| `Result<String, DecodingError>` | `Ok(decoded)` containing the decoded string or `Err(err)` if the decoding failed |
|
|
168
168
|
|
|
169
169
|
### Uri.**encodeQuery**
|
|
170
170
|
|
|
@@ -174,7 +174,7 @@ No other changes yet.
|
|
|
174
174
|
</details>
|
|
175
175
|
|
|
176
176
|
```grain
|
|
177
|
-
encodeQuery
|
|
177
|
+
encodeQuery:
|
|
178
178
|
(urlVals: List<(String, String)>, ?encodeSet: EncodeSet) => String
|
|
179
179
|
```
|
|
180
180
|
|
|
@@ -182,15 +182,15 @@ Encodes a list of key-value pairs into an query string.
|
|
|
182
182
|
|
|
183
183
|
Parameters:
|
|
184
184
|
|
|
185
|
-
|param|type|description|
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
| param | type | description |
|
|
186
|
+
| --------- | ------------------------ | ------------------------- |
|
|
187
|
+
| `urlVals` | `List<(String, String)>` | A list of key-value pairs |
|
|
188
188
|
|
|
189
189
|
Returns:
|
|
190
190
|
|
|
191
|
-
|type|description|
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
| type | description |
|
|
192
|
+
| -------- | -------------- |
|
|
193
|
+
| `String` | A query string |
|
|
194
194
|
|
|
195
195
|
### Uri.**decodeQuery**
|
|
196
196
|
|
|
@@ -200,22 +200,22 @@ No other changes yet.
|
|
|
200
200
|
</details>
|
|
201
201
|
|
|
202
202
|
```grain
|
|
203
|
-
decodeQuery
|
|
203
|
+
decodeQuery: (str: String) => Result<List<(String, String)>, DecodingError>
|
|
204
204
|
```
|
|
205
205
|
|
|
206
206
|
Decodes a query string into a list of pairs.
|
|
207
207
|
|
|
208
208
|
Parameters:
|
|
209
209
|
|
|
210
|
-
|param|type|description|
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
| param | type | description |
|
|
211
|
+
| ----- | -------- | -------------- |
|
|
212
|
+
| `str` | `String` | A query string |
|
|
213
213
|
|
|
214
214
|
Returns:
|
|
215
215
|
|
|
216
|
-
|type|description|
|
|
217
|
-
|
|
218
|
-
|
|
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
219
|
|
|
220
220
|
### Uri.**parse**
|
|
221
221
|
|
|
@@ -225,7 +225,7 @@ No other changes yet.
|
|
|
225
225
|
</details>
|
|
226
226
|
|
|
227
227
|
```grain
|
|
228
|
-
parse
|
|
228
|
+
parse: (str: String) => Result<Uri, ParseError>
|
|
229
229
|
```
|
|
230
230
|
|
|
231
231
|
Parses a string into a `Uri` according to RFC 3986. If the URI string has a
|
|
@@ -234,15 +234,15 @@ segments.
|
|
|
234
234
|
|
|
235
235
|
Parameters:
|
|
236
236
|
|
|
237
|
-
|param|type|description|
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
| param | type | description |
|
|
238
|
+
| ----- | -------- | -------------------------------- |
|
|
239
|
+
| `str` | `String` | The RFC 3986 URI string to parse |
|
|
240
240
|
|
|
241
241
|
Returns:
|
|
242
242
|
|
|
243
|
-
|type|description|
|
|
244
|
-
|
|
245
|
-
|
|
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
246
|
|
|
247
247
|
Examples:
|
|
248
248
|
|
|
@@ -262,24 +262,23 @@ No other changes yet.
|
|
|
262
262
|
</details>
|
|
263
263
|
|
|
264
264
|
```grain
|
|
265
|
-
resolveReference :
|
|
266
|
-
(base: Uri, ref: Uri) => Result<Uri, ResolveReferenceError>
|
|
265
|
+
resolveReference: (base: Uri, ref: Uri) => Result<Uri, ResolveReferenceError>
|
|
267
266
|
```
|
|
268
267
|
|
|
269
268
|
Transforms a base URI and a URI reference into a target URI
|
|
270
269
|
|
|
271
270
|
Parameters:
|
|
272
271
|
|
|
273
|
-
|param|type|description|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
272
|
+
| param | type | description |
|
|
273
|
+
| ------ | ----- | ------------------------------------------ |
|
|
274
|
+
| `base` | `Uri` | The base URI to resolve a URI reference on |
|
|
275
|
+
| `ref` | `Uri` | The URI reference to apply onto the base |
|
|
277
276
|
|
|
278
277
|
Returns:
|
|
279
278
|
|
|
280
|
-
|type|description|
|
|
281
|
-
|
|
282
|
-
|
|
279
|
+
| type | description |
|
|
280
|
+
| ------------------------------------ | ----------------------------------------------------------------------------- |
|
|
281
|
+
| `Result<Uri, ResolveReferenceError>` | `Ok(uri)` containing the target `Uri` or `Err(err)` if the input is malformed |
|
|
283
282
|
|
|
284
283
|
Examples:
|
|
285
284
|
|
|
@@ -303,7 +302,7 @@ No other changes yet.
|
|
|
303
302
|
</details>
|
|
304
303
|
|
|
305
304
|
```grain
|
|
306
|
-
make
|
|
305
|
+
make:
|
|
307
306
|
(?scheme: Option<String>, ?userinfo: Option<String>, ?host: Option<String>,
|
|
308
307
|
?port: Option<Number>, ?path: String, ?query: Option<String>,
|
|
309
308
|
?fragment: Option<String>, ?encodeComponents: Bool) =>
|
|
@@ -314,16 +313,16 @@ Constructs a new `Uri` from components.
|
|
|
314
313
|
|
|
315
314
|
Parameters:
|
|
316
315
|
|
|
317
|
-
|param|type|description|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
316
|
+
| param | type | description |
|
|
317
|
+
| ------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
318
|
+
| `?scheme` | `Option<String>` | `Some(scheme)` containing the desired scheme component or `None` for a scheme-less URI |
|
|
319
|
+
| `?userinfo` | `Option<String>` | `Some(userinfo)` containing the desired userinfo component or `None` for a userinfo-less URI |
|
|
320
|
+
| `?host` | `Option<String>` | `Some(host)` containing the desired host component or `None` for a host-less URI |
|
|
321
|
+
| `?port` | `Option<Number>` | `Some(port)` containing the desired port component or `None` for a port-less URI |
|
|
322
|
+
| `?path` | `String` | The desired path for the URI. `""` by default |
|
|
323
|
+
| `?query` | `Option<String>` | `Some(query)` containing the desired query string component or `None` for a query-less URI |
|
|
324
|
+
| `?fragment` | `Option<String>` | `Some(fragment)` containing the desired fragment component or `None` for a fragment-less URI |
|
|
325
|
+
| `?encodeComponents` | `Bool` | Whether or not to apply percent encoding for each component to remove unsafe characters for each component |
|
|
327
326
|
|
|
328
327
|
Examples:
|
|
329
328
|
|
|
@@ -351,7 +350,7 @@ No other changes yet.
|
|
|
351
350
|
</details>
|
|
352
351
|
|
|
353
352
|
```grain
|
|
354
|
-
update
|
|
353
|
+
update:
|
|
355
354
|
(uri: Uri, ?scheme: Option<Option<String>>,
|
|
356
355
|
?userinfo: Option<Option<String>>, ?host: Option<Option<String>>,
|
|
357
356
|
?port: Option<Option<Number>>, ?path: Option<String>,
|
|
@@ -366,17 +365,17 @@ used for that component.
|
|
|
366
365
|
|
|
367
366
|
Parameters:
|
|
368
367
|
|
|
369
|
-
|param|type|description|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
368
|
+
| param | type | description |
|
|
369
|
+
| ------------------- | ------------------------ | ---------------------------------------------------------------------------------------------------------------- |
|
|
370
|
+
| `uri` | `Uri` | The `Uri` to update |
|
|
371
|
+
| `?scheme` | `Option<Option<String>>` | `Some(scheme)` containing the desired updated scheme component or `None` to maintain the base URI's scheme |
|
|
372
|
+
| `?userinfo` | `Option<Option<String>>` | `Some(userinfo)` containing the desired updated userinfo component or `None` to maintain the base URI's userinfo |
|
|
373
|
+
| `?host` | `Option<Option<String>>` | `Some(host)` containing the desired updated host component or `None` to maintain the base URI's host |
|
|
374
|
+
| `?port` | `Option<Option<Number>>` | `Some(port)` containing the desired updated port component or `None` to maintain the base URI's port |
|
|
375
|
+
| `?path` | `Option<String>` | `Some(path)` containing the desired updated path component or `None` to maintain the base URI's path |
|
|
376
|
+
| `?query` | `Option<Option<String>>` | `Some(query)` containing the desired updated query string component or `None` to maintain the base URI's query |
|
|
377
|
+
| `?fragment` | `Option<Option<String>>` | `Some(fragment)` containing the desired updated fragment component or `None` to maintain the base URI's fragment |
|
|
378
|
+
| `?encodeComponents` | `Bool` | Whether or not to apply percent encoding for each updated component to remove unsafe characters |
|
|
380
379
|
|
|
381
380
|
Examples:
|
|
382
381
|
|
|
@@ -408,22 +407,22 @@ No other changes yet.
|
|
|
408
407
|
</details>
|
|
409
408
|
|
|
410
409
|
```grain
|
|
411
|
-
hasAuthority
|
|
410
|
+
hasAuthority: (uri: Uri) => Bool
|
|
412
411
|
```
|
|
413
412
|
|
|
414
413
|
Determines whether a `Uri` has an authority (i.e. has a host component)
|
|
415
414
|
|
|
416
415
|
Parameters:
|
|
417
416
|
|
|
418
|
-
|param|type|description|
|
|
419
|
-
|
|
420
|
-
|
|
417
|
+
| param | type | description |
|
|
418
|
+
| ----- | ----- | --------------------- |
|
|
419
|
+
| `uri` | `Uri` | The `Uri` to consider |
|
|
421
420
|
|
|
422
421
|
Returns:
|
|
423
422
|
|
|
424
|
-
|type|description|
|
|
425
|
-
|
|
426
|
-
|
|
423
|
+
| type | description |
|
|
424
|
+
| ------ | ------------------------------------------------------------------- |
|
|
425
|
+
| `Bool` | `true` if the `Uri` has an authority component or `false` otherwise |
|
|
427
426
|
|
|
428
427
|
### Uri.**isAbsolute**
|
|
429
428
|
|
|
@@ -433,22 +432,22 @@ No other changes yet.
|
|
|
433
432
|
</details>
|
|
434
433
|
|
|
435
434
|
```grain
|
|
436
|
-
isAbsolute
|
|
435
|
+
isAbsolute: (uri: Uri) => Bool
|
|
437
436
|
```
|
|
438
437
|
|
|
439
438
|
Determines whether a `Uri` is an absolute URI (has a scheme component)
|
|
440
439
|
|
|
441
440
|
Parameters:
|
|
442
441
|
|
|
443
|
-
|param|type|description|
|
|
444
|
-
|
|
445
|
-
|
|
442
|
+
| param | type | description |
|
|
443
|
+
| ----- | ----- | --------------------- |
|
|
444
|
+
| `uri` | `Uri` | The `Uri` to consider |
|
|
446
445
|
|
|
447
446
|
Returns:
|
|
448
447
|
|
|
449
|
-
|type|description|
|
|
450
|
-
|
|
451
|
-
|
|
448
|
+
| type | description |
|
|
449
|
+
| ------ | ----------------------------------------------------------------------------- |
|
|
450
|
+
| `Bool` | `true` if the `Uri` is absolute (has a scheme component) or `false` otherwise |
|
|
452
451
|
|
|
453
452
|
### Uri.**toString**
|
|
454
453
|
|
|
@@ -458,20 +457,20 @@ No other changes yet.
|
|
|
458
457
|
</details>
|
|
459
458
|
|
|
460
459
|
```grain
|
|
461
|
-
toString
|
|
460
|
+
toString: (uri: Uri) => String
|
|
462
461
|
```
|
|
463
462
|
|
|
464
463
|
Converts the given `Uri` into a string.
|
|
465
464
|
|
|
466
465
|
Parameters:
|
|
467
466
|
|
|
468
|
-
|param|type|description|
|
|
469
|
-
|
|
470
|
-
|
|
467
|
+
| param | type | description |
|
|
468
|
+
| ----- | ----- | -------------------- |
|
|
469
|
+
| `uri` | `Uri` | The `Uri` to convert |
|
|
471
470
|
|
|
472
471
|
Returns:
|
|
473
472
|
|
|
474
|
-
|type|description|
|
|
475
|
-
|
|
476
|
-
|
|
473
|
+
| type | description |
|
|
474
|
+
| -------- | ------------------------------------ |
|
|
475
|
+
| `String` | A string representation of the `Uri` |
|
|
477
476
|
|