@grain/stdlib 0.6.6 → 0.7.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.
Files changed (137) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/LICENSE +1 -1
  3. package/README.md +2 -2
  4. package/array.gr +55 -7
  5. package/array.md +123 -77
  6. package/bigint.md +30 -30
  7. package/buffer.gr +20 -53
  8. package/buffer.md +47 -47
  9. package/bytes.gr +111 -35
  10. package/bytes.md +111 -32
  11. package/char.gr +201 -99
  12. package/char.md +361 -34
  13. package/exception.gr +11 -11
  14. package/exception.md +26 -1
  15. package/float32.gr +327 -3
  16. package/float32.md +606 -19
  17. package/float64.gr +320 -3
  18. package/float64.md +606 -19
  19. package/fs.gr +1082 -0
  20. package/fs.md +630 -0
  21. package/hash.gr +142 -88
  22. package/hash.md +102 -14
  23. package/int16.md +23 -23
  24. package/int32.gr +25 -4
  25. package/int32.md +65 -30
  26. package/int64.gr +26 -1
  27. package/int64.md +65 -30
  28. package/int8.md +23 -23
  29. package/json.gr +366 -51
  30. package/json.md +418 -2
  31. package/list.gr +328 -31
  32. package/list.md +492 -69
  33. package/map.gr +20 -12
  34. package/map.md +44 -38
  35. package/marshal.gr +41 -40
  36. package/marshal.md +2 -2
  37. package/number.gr +159 -30
  38. package/number.md +215 -38
  39. package/option.md +21 -21
  40. package/package.json +5 -3
  41. package/path.gr +48 -0
  42. package/path.md +103 -12
  43. package/pervasives.gr +2 -2
  44. package/pervasives.md +37 -37
  45. package/priorityqueue.gr +7 -7
  46. package/priorityqueue.md +19 -19
  47. package/queue.gr +183 -29
  48. package/queue.md +296 -40
  49. package/random.md +6 -6
  50. package/range.gr +4 -4
  51. package/range.md +6 -6
  52. package/rational.md +16 -16
  53. package/regex.gr +52 -51
  54. package/regex.md +11 -11
  55. package/result.md +16 -16
  56. package/runtime/atof/common.md +39 -39
  57. package/runtime/atof/decimal.gr +6 -6
  58. package/runtime/atof/decimal.md +8 -8
  59. package/runtime/atof/lemire.gr +5 -5
  60. package/runtime/atof/lemire.md +1 -1
  61. package/runtime/atof/parse.gr +16 -16
  62. package/runtime/atof/parse.md +2 -2
  63. package/runtime/atof/slow.md +1 -1
  64. package/runtime/atof/table.md +2 -2
  65. package/runtime/atoi/parse.gr +3 -3
  66. package/runtime/atoi/parse.md +1 -1
  67. package/runtime/bigint.gr +15 -47
  68. package/runtime/bigint.md +54 -60
  69. package/runtime/compare.gr +2 -2
  70. package/runtime/compare.md +1 -1
  71. package/runtime/dataStructures.md +33 -33
  72. package/runtime/debugPrint.gr +4 -1
  73. package/runtime/debugPrint.md +9 -9
  74. package/runtime/equal.gr +99 -77
  75. package/runtime/equal.md +1 -1
  76. package/runtime/exception.gr +62 -82
  77. package/runtime/exception.md +62 -11
  78. package/runtime/gc.gr +39 -45
  79. package/runtime/gc.md +4 -4
  80. package/runtime/malloc.gr +7 -7
  81. package/runtime/malloc.md +4 -4
  82. package/runtime/math/kernel/cos.gr +70 -0
  83. package/runtime/math/kernel/cos.md +14 -0
  84. package/runtime/math/kernel/sin.gr +65 -0
  85. package/runtime/math/kernel/sin.md +14 -0
  86. package/runtime/math/kernel/tan.gr +136 -0
  87. package/runtime/math/kernel/tan.md +14 -0
  88. package/runtime/math/rempio2.gr +244 -0
  89. package/runtime/math/rempio2.md +14 -0
  90. package/runtime/math/trig.gr +130 -0
  91. package/runtime/math/trig.md +28 -0
  92. package/runtime/math/umuldi.gr +26 -0
  93. package/runtime/math/umuldi.md +14 -0
  94. package/runtime/numberUtils.gr +29 -29
  95. package/runtime/numberUtils.md +12 -12
  96. package/runtime/numbers.gr +373 -381
  97. package/runtime/numbers.md +79 -73
  98. package/runtime/string.gr +37 -105
  99. package/runtime/string.md +3 -9
  100. package/runtime/unsafe/constants.md +24 -24
  101. package/runtime/unsafe/conv.md +13 -13
  102. package/runtime/unsafe/memory.gr +24 -20
  103. package/runtime/unsafe/memory.md +27 -7
  104. package/runtime/unsafe/offsets.gr +36 -0
  105. package/runtime/unsafe/offsets.md +88 -0
  106. package/runtime/unsafe/panic.gr +28 -0
  107. package/runtime/unsafe/panic.md +14 -0
  108. package/runtime/unsafe/tags.md +32 -32
  109. package/runtime/unsafe/wasmf32.md +28 -28
  110. package/runtime/unsafe/wasmf64.md +28 -28
  111. package/runtime/unsafe/wasmi32.md +47 -47
  112. package/runtime/unsafe/wasmi64.md +50 -50
  113. package/runtime/utf8.gr +189 -0
  114. package/runtime/utf8.md +117 -0
  115. package/runtime/wasi.gr +4 -2
  116. package/runtime/wasi.md +138 -138
  117. package/set.gr +18 -11
  118. package/set.md +42 -36
  119. package/stack.gr +171 -2
  120. package/stack.md +297 -15
  121. package/string.gr +352 -557
  122. package/string.md +77 -34
  123. package/uint16.md +22 -22
  124. package/uint32.gr +25 -4
  125. package/uint32.md +63 -28
  126. package/uint64.gr +25 -5
  127. package/uint64.md +63 -28
  128. package/uint8.md +22 -22
  129. package/uri.gr +57 -53
  130. package/uri.md +11 -12
  131. package/wasi/file.gr +67 -59
  132. package/wasi/file.md +39 -39
  133. package/wasi/process.md +5 -5
  134. package/wasi/random.md +3 -3
  135. package/wasi/time.md +4 -4
  136. package/runtime/utils/printing.gr +0 -60
  137. package/runtime/utils/printing.md +0 -26
package/uint8.md CHANGED
@@ -33,7 +33,7 @@ No other changes yet.
33
33
  </details>
34
34
 
35
35
  ```grain
36
- fromNumber : (number: Number) => Uint8
36
+ fromNumber: (number: Number) => Uint8
37
37
  ```
38
38
 
39
39
  Converts a Number to a Uint8.
@@ -58,7 +58,7 @@ No other changes yet.
58
58
  </details>
59
59
 
60
60
  ```grain
61
- toNumber : (value: Uint8) => Number
61
+ toNumber: (value: Uint8) => Number
62
62
  ```
63
63
 
64
64
  Converts a Uint8 to a Number.
@@ -83,7 +83,7 @@ No other changes yet.
83
83
  </details>
84
84
 
85
85
  ```grain
86
- fromInt8 : (number: Int8) => Uint8
86
+ fromInt8: (number: Int8) => Uint8
87
87
  ```
88
88
 
89
89
  Converts an Int8 to a Uint8.
@@ -118,7 +118,7 @@ No other changes yet.
118
118
  </details>
119
119
 
120
120
  ```grain
121
- incr : (value: Uint8) => Uint8
121
+ incr: (value: Uint8) => Uint8
122
122
  ```
123
123
 
124
124
  Increments the value by one.
@@ -149,7 +149,7 @@ No other changes yet.
149
149
  </details>
150
150
 
151
151
  ```grain
152
- decr : (value: Uint8) => Uint8
152
+ decr: (value: Uint8) => Uint8
153
153
  ```
154
154
 
155
155
  Decrements the value by one.
@@ -184,7 +184,7 @@ No other changes yet.
184
184
  </details>
185
185
 
186
186
  ```grain
187
- (+) : (x: Uint8, y: Uint8) => Uint8
187
+ (+): (x: Uint8, y: Uint8) => Uint8
188
188
  ```
189
189
 
190
190
  Computes the sum of its operands.
@@ -217,7 +217,7 @@ No other changes yet.
217
217
  </details>
218
218
 
219
219
  ```grain
220
- (-) : (x: Uint8, y: Uint8) => Uint8
220
+ (-): (x: Uint8, y: Uint8) => Uint8
221
221
  ```
222
222
 
223
223
  Computes the difference of its operands.
@@ -250,7 +250,7 @@ No other changes yet.
250
250
  </details>
251
251
 
252
252
  ```grain
253
- (*) : (x: Uint8, y: Uint8) => Uint8
253
+ (*): (x: Uint8, y: Uint8) => Uint8
254
254
  ```
255
255
 
256
256
  Computes the product of its operands.
@@ -283,7 +283,7 @@ No other changes yet.
283
283
  </details>
284
284
 
285
285
  ```grain
286
- (/) : (x: Uint8, y: Uint8) => Uint8
286
+ (/): (x: Uint8, y: Uint8) => Uint8
287
287
  ```
288
288
 
289
289
  Computes the quotient of its operands.
@@ -316,7 +316,7 @@ No other changes yet.
316
316
  </details>
317
317
 
318
318
  ```grain
319
- rem : (x: Uint8, y: Uint8) => Uint8
319
+ rem: (x: Uint8, y: Uint8) => Uint8
320
320
  ```
321
321
 
322
322
  Computes the remainder of the division of its operands.
@@ -348,7 +348,7 @@ No other changes yet.
348
348
  </details>
349
349
 
350
350
  ```grain
351
- (<<) : (value: Uint8, amount: Uint8) => Uint8
351
+ (<<): (value: Uint8, amount: Uint8) => Uint8
352
352
  ```
353
353
 
354
354
  Shifts the bits of the value left by the given number of bits.
@@ -381,7 +381,7 @@ No other changes yet.
381
381
  </details>
382
382
 
383
383
  ```grain
384
- (>>>) : (value: Uint8, amount: Uint8) => Uint8
384
+ (>>>): (value: Uint8, amount: Uint8) => Uint8
385
385
  ```
386
386
 
387
387
  Shifts the bits of the value right by the given number of bits.
@@ -414,7 +414,7 @@ No other changes yet.
414
414
  </details>
415
415
 
416
416
  ```grain
417
- (==) : (x: Uint8, y: Uint8) => Bool
417
+ (==): (x: Uint8, y: Uint8) => Bool
418
418
  ```
419
419
 
420
420
  Checks if the first value is equal to the second value.
@@ -447,7 +447,7 @@ No other changes yet.
447
447
  </details>
448
448
 
449
449
  ```grain
450
- (!=) : (x: Uint8, y: Uint8) => Bool
450
+ (!=): (x: Uint8, y: Uint8) => Bool
451
451
  ```
452
452
 
453
453
  Checks if the first value is not equal to the second value.
@@ -480,7 +480,7 @@ No other changes yet.
480
480
  </details>
481
481
 
482
482
  ```grain
483
- (<) : (x: Uint8, y: Uint8) => Bool
483
+ (<): (x: Uint8, y: Uint8) => Bool
484
484
  ```
485
485
 
486
486
  Checks if the first value is less than the second value.
@@ -513,7 +513,7 @@ No other changes yet.
513
513
  </details>
514
514
 
515
515
  ```grain
516
- (>) : (x: Uint8, y: Uint8) => Bool
516
+ (>): (x: Uint8, y: Uint8) => Bool
517
517
  ```
518
518
 
519
519
  Checks if the first value is greater than the second value.
@@ -546,7 +546,7 @@ No other changes yet.
546
546
  </details>
547
547
 
548
548
  ```grain
549
- (<=) : (x: Uint8, y: Uint8) => Bool
549
+ (<=): (x: Uint8, y: Uint8) => Bool
550
550
  ```
551
551
 
552
552
  Checks if the first value is less than or equal to the second value.
@@ -584,7 +584,7 @@ No other changes yet.
584
584
  </details>
585
585
 
586
586
  ```grain
587
- (>=) : (x: Uint8, y: Uint8) => Bool
587
+ (>=): (x: Uint8, y: Uint8) => Bool
588
588
  ```
589
589
 
590
590
  Checks if the first value is greater than or equal to the second value.
@@ -622,7 +622,7 @@ No other changes yet.
622
622
  </details>
623
623
 
624
624
  ```grain
625
- lnot : (value: Uint8) => Uint8
625
+ lnot: (value: Uint8) => Uint8
626
626
  ```
627
627
 
628
628
  Computes the bitwise NOT of the given value.
@@ -653,7 +653,7 @@ No other changes yet.
653
653
  </details>
654
654
 
655
655
  ```grain
656
- (&) : (x: Uint8, y: Uint8) => Uint8
656
+ (&): (x: Uint8, y: Uint8) => Uint8
657
657
  ```
658
658
 
659
659
  Computes the bitwise AND (`&`) on the given operands.
@@ -686,7 +686,7 @@ No other changes yet.
686
686
  </details>
687
687
 
688
688
  ```grain
689
- (|) : (x: Uint8, y: Uint8) => Uint8
689
+ (|): (x: Uint8, y: Uint8) => Uint8
690
690
  ```
691
691
 
692
692
  Computes the bitwise OR (`|`) on the given operands.
@@ -719,7 +719,7 @@ No other changes yet.
719
719
  </details>
720
720
 
721
721
  ```grain
722
- (^) : (x: Uint8, y: Uint8) => Uint8
722
+ (^): (x: Uint8, y: Uint8) => Uint8
723
723
  ```
724
724
 
725
725
  Computes the bitwise XOR (`^`) on the given operands.
package/uri.gr CHANGED
@@ -82,18 +82,18 @@ provide enum EncodeSet {
82
82
 
83
83
  let isHexDigit = char => {
84
84
  use Char.{ (<=), (>=) }
85
- Char.isAsciiDigit(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.isAsciiDigit(char) ||
92
- Char.isAsciiAlpha(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.isAsciiDigit(char)) {
145
+ if (Char.Ascii.isDigit(char)) {
146
146
  Char.code(char) - 0x30
147
147
  } else {
148
- let char = Char.toAsciiLowercase(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.toAsciiUppercase(next), out)
177
- Buffer.addChar(Char.toAsciiUppercase(nextNext), out)
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
- (i >= len - 2 || !isHexDigit(chars[i + 1]) || !isHexDigit(chars[i + 2]))
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.toAsciiLowercase(chars[i]), ...acc])
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.isAsciiDigit)
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.isAsciiAlpha)
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,7 +109,7 @@ No other changes yet.
109
109
  </details>
110
110
 
111
111
  ```grain
112
- encode : (str: String, ?encodeSet: EncodeSet) => String
112
+ encode: (str: String, ?encodeSet: EncodeSet) => String
113
113
  ```
114
114
 
115
115
  Percent-encodes characters in a string based on the specified `EncodeSet`.
@@ -149,7 +149,7 @@ No other changes yet.
149
149
  </details>
150
150
 
151
151
  ```grain
152
- decode : (str: String) => Result<String, DecodingError>
152
+ decode: (str: String) => Result<String, DecodingError>
153
153
  ```
154
154
 
155
155
  Decodes any percent-encoded characters in a string.
@@ -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
 
@@ -200,7 +200,7 @@ No other changes yet.
200
200
  </details>
201
201
 
202
202
  ```grain
203
- decodeQuery : (str: String) => Result<List<(String, String)>, DecodingError>
203
+ decodeQuery: (str: String) => Result<List<(String, String)>, DecodingError>
204
204
  ```
205
205
 
206
206
  Decodes a query string into a list of pairs.
@@ -225,7 +225,7 @@ No other changes yet.
225
225
  </details>
226
226
 
227
227
  ```grain
228
- parse : (str: String) => Result<Uri, ParseError>
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
@@ -262,8 +262,7 @@ 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
@@ -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) =>
@@ -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>,
@@ -408,7 +407,7 @@ No other changes yet.
408
407
  </details>
409
408
 
410
409
  ```grain
411
- hasAuthority : (uri: Uri) => Bool
410
+ hasAuthority: (uri: Uri) => Bool
412
411
  ```
413
412
 
414
413
  Determines whether a `Uri` has an authority (i.e. has a host component)
@@ -433,7 +432,7 @@ No other changes yet.
433
432
  </details>
434
433
 
435
434
  ```grain
436
- isAbsolute : (uri: Uri) => Bool
435
+ isAbsolute: (uri: Uri) => Bool
437
436
  ```
438
437
 
439
438
  Determines whether a `Uri` is an absolute URI (has a scheme component)
@@ -458,7 +457,7 @@ No other changes yet.
458
457
  </details>
459
458
 
460
459
  ```grain
461
- toString : (uri: Uri) => String
460
+ toString: (uri: Uri) => String
462
461
  ```
463
462
 
464
463
  Converts the given `Uri` into a string.