@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.
Files changed (137) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/LICENSE +1 -1
  3. package/README.md +2 -2
  4. package/array.gr +55 -7
  5. package/array.md +606 -560
  6. package/bigint.md +228 -228
  7. package/buffer.gr +85 -53
  8. package/buffer.md +442 -319
  9. package/bytes.gr +112 -35
  10. package/bytes.md +299 -219
  11. package/char.gr +201 -99
  12. package/char.md +447 -120
  13. package/exception.gr +11 -11
  14. package/exception.md +29 -4
  15. package/float32.gr +327 -3
  16. package/float32.md +698 -111
  17. package/float64.gr +320 -3
  18. package/float64.md +698 -111
  19. package/fs.gr +1082 -0
  20. package/fs.md +630 -0
  21. package/hash.gr +142 -88
  22. package/hash.md +105 -17
  23. package/int16.md +178 -178
  24. package/int32.gr +26 -5
  25. package/int32.md +266 -231
  26. package/int64.gr +27 -2
  27. package/int64.md +266 -231
  28. package/int8.md +178 -178
  29. package/json.gr +366 -51
  30. package/json.md +431 -15
  31. package/list.gr +328 -31
  32. package/list.md +759 -336
  33. package/map.gr +20 -12
  34. package/map.md +266 -260
  35. package/marshal.gr +41 -40
  36. package/marshal.md +14 -14
  37. package/number.gr +278 -35
  38. package/number.md +688 -269
  39. package/option.md +162 -162
  40. package/package.json +5 -3
  41. package/path.gr +48 -0
  42. package/path.md +180 -89
  43. package/pervasives.gr +2 -2
  44. package/pervasives.md +275 -275
  45. package/priorityqueue.gr +7 -7
  46. package/priorityqueue.md +131 -131
  47. package/queue.gr +183 -29
  48. package/queue.md +404 -148
  49. package/random.md +43 -43
  50. package/range.gr +4 -4
  51. package/range.md +42 -42
  52. package/rational.md +123 -123
  53. package/regex.gr +52 -51
  54. package/regex.md +102 -102
  55. package/result.md +118 -118
  56. package/runtime/atof/common.md +39 -39
  57. package/runtime/atof/decimal.gr +6 -6
  58. package/runtime/atof/decimal.md +14 -14
  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 +8 -8
  71. package/runtime/dataStructures.md +211 -211
  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 +8 -8
  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 +13 -13
  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 +348 -342
  98. package/runtime/string.gr +37 -105
  99. package/runtime/string.md +20 -26
  100. package/runtime/unsafe/constants.md +24 -24
  101. package/runtime/unsafe/conv.md +19 -19
  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 +147 -147
  117. package/set.gr +18 -11
  118. package/set.md +253 -247
  119. package/stack.gr +171 -2
  120. package/stack.md +371 -89
  121. package/string.gr +352 -557
  122. package/string.md +298 -255
  123. package/uint16.md +170 -170
  124. package/uint32.gr +25 -4
  125. package/uint32.md +249 -214
  126. package/uint64.gr +25 -5
  127. package/uint64.md +249 -214
  128. package/uint8.md +170 -170
  129. package/uri.gr +57 -53
  130. package/uri.md +88 -89
  131. package/wasi/file.gr +67 -59
  132. package/wasi/file.md +308 -308
  133. package/wasi/process.md +26 -26
  134. package/wasi/random.md +12 -12
  135. package/wasi/time.md +16 -16
  136. package/runtime/utils/printing.gr +0 -60
  137. package/runtime/utils/printing.md +0 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grain/stdlib",
3
- "version": "0.6.6",
3
+ "version": "0.7.1",
4
4
  "description": "The standard library for the Grain language.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://grain-lang.org",
@@ -18,7 +18,7 @@
18
18
  "directory": "stdlib"
19
19
  },
20
20
  "engines": {
21
- "node": ">=18.15"
21
+ "node": ">=22.13"
22
22
  },
23
23
  "main": "index.js",
24
24
  "files": [
@@ -27,7 +27,9 @@
27
27
  "index.js"
28
28
  ],
29
29
  "scripts": {
30
- "clean": "del-cli \"**/*.wasm\" \"**/*.wat\" \"**/*.modsig\""
30
+ "clean": "del-cli \"**/*.wasm\" \"**/*.wat\" \"**/*.gro\" \"**/*.modsig\"",
31
+ "doc": "grain doc ./ -o ./ --current-version=$(grain -v)",
32
+ "format": "grain format ./ -o ./"
31
33
  },
32
34
  "dependencies": {},
33
35
  "devDependencies": {
package/path.gr CHANGED
@@ -722,6 +722,54 @@ provide let extension = (path: Path) => {
722
722
  }
723
723
  }
724
724
 
725
+ /**
726
+ * Removes the extension from a path, if there is no extension, returns the path as is.
727
+ *
728
+ * @param path: The path to modify
729
+ * @returns The path with the extension removed
730
+ *
731
+ * @example removeExtension(fromString("file.txt")) == fromString("file")
732
+ * @example removeExtension(fromString(".gitignore")) == fromString(".gitignore")
733
+ * @example removeExtension(fromString("./dir/file")) == fromString("dir/file")
734
+ * @example removeExtension(fromString("./dir/")) == fromString("dir/")
735
+ *
736
+ * @since v7.0.0
737
+ */
738
+ provide let removeExtension = (path: Path) => {
739
+ match (pathInfo(path)) {
740
+ (base, File, [name, ...rest]) as pathInfo => {
741
+ let (name, _) = stemExtHelper(pathInfo)
742
+ toPath((base, File, [name, ...rest]))
743
+ },
744
+ _ => path,
745
+ }
746
+ }
747
+
748
+ /**
749
+ * Updates the file extension of the given path.
750
+ *
751
+ * @param path: The path to modify
752
+ * @param extension: The new extension
753
+ * @returns The modified path
754
+ *
755
+ * @example updateExtension(fromString("file.txt"), "ext") == fromString("file.ext")
756
+ * @example updateExtension(fromString("file.txt"), "") == fromString("file.")
757
+ * @example updateExtension(fromString(".gitignore"), "ext") == fromString(".gitignore.ext")
758
+ * @example updateExtension(fromString("./dir/file"), "ext") == fromString("dir/file.ext")
759
+ * @example updateExtension(fromString("./dir/"), "ext") == fromString("dir/")
760
+ *
761
+ * @since v7.0.0
762
+ */
763
+ provide let updateExtension = (path: Path, extension: String) => {
764
+ match (pathInfo(path)) {
765
+ (base, File, [name, ...rest]) as pathInfo => {
766
+ let (name, _) = stemExtHelper(pathInfo)
767
+ toPath((base, File, [name ++ "." ++ extension, ...rest]))
768
+ },
769
+ _ => path,
770
+ }
771
+ }
772
+
725
773
  // should only be used on absolute paths
726
774
  let rootHelper = (path: PathInfo) => match (path) {
727
775
  (Abs(root), _, _) => root,
package/path.md CHANGED
@@ -184,7 +184,7 @@ Functions and constants included in the Path module.
184
184
  </details>
185
185
 
186
186
  ```grain
187
- fromString : (pathStr: String, ?platform: Platform) => Path
187
+ fromString: (pathStr: String, ?platform: Platform) => Path
188
188
  ```
189
189
 
190
190
  Parses a path string into a `Path` using the path separators appropriate to
@@ -194,16 +194,16 @@ ambiguity.
194
194
 
195
195
  Parameters:
196
196
 
197
- |param|type|description|
198
- |-----|----|-----------|
199
- |`pathStr`|`String`|The string to parse as a path|
200
- |`?platform`|`Platform`|The platform whose path separators should be used for parsing|
197
+ | param | type | description |
198
+ | ----------- | ---------- | ------------------------------------------------------------- |
199
+ | `pathStr` | `String` | The string to parse as a path |
200
+ | `?platform` | `Platform` | The platform whose path separators should be used for parsing |
201
201
 
202
202
  Returns:
203
203
 
204
- |type|description|
205
- |----|-----------|
206
- |`Path`|The path wrapped with details encoded within the type|
204
+ | type | description |
205
+ | ------ | ----------------------------------------------------- |
206
+ | `Path` | The path wrapped with details encoded within the type |
207
207
 
208
208
  Examples:
209
209
 
@@ -238,7 +238,7 @@ fromString("C:\\file.txt", Windows) // a relative Path referencing the file C:\f
238
238
  </details>
239
239
 
240
240
  ```grain
241
- toString : (path: Path, ?platform: Platform) => String
241
+ toString: (path: Path, ?platform: Platform) => String
242
242
  ```
243
243
 
244
244
  Converts the given `Path` into a string, using the canonical path separator
@@ -247,16 +247,16 @@ A trailing slash is added to directory paths.
247
247
 
248
248
  Parameters:
249
249
 
250
- |param|type|description|
251
- |-----|----|-----------|
252
- |`path`|`Path`|The path to convert to a string|
253
- |`?platform`|`Platform`|The `Platform` to use to represent the path as a string|
250
+ | param | type | description |
251
+ | ----------- | ---------- | ------------------------------------------------------- |
252
+ | `path` | `Path` | The path to convert to a string |
253
+ | `?platform` | `Platform` | The `Platform` to use to represent the path as a string |
254
254
 
255
255
  Returns:
256
256
 
257
- |type|description|
258
- |----|-----------|
259
- |`String`|A string representing the given path|
257
+ | type | description |
258
+ | -------- | ------------------------------------ |
259
+ | `String` | A string representing the given path |
260
260
 
261
261
  Examples:
262
262
 
@@ -280,22 +280,22 @@ No other changes yet.
280
280
  </details>
281
281
 
282
282
  ```grain
283
- isDirectory : (path: Path) => Bool
283
+ isDirectory: (path: Path) => Bool
284
284
  ```
285
285
 
286
286
  Determines whether the path is a directory path.
287
287
 
288
288
  Parameters:
289
289
 
290
- |param|type|description|
291
- |-----|----|-----------|
292
- |`path`|`Path`|The path to inspect|
290
+ | param | type | description |
291
+ | ------ | ------ | ------------------- |
292
+ | `path` | `Path` | The path to inspect |
293
293
 
294
294
  Returns:
295
295
 
296
- |type|description|
297
- |----|-----------|
298
- |`Bool`|`true` if the path is a directory path or `false` otherwise|
296
+ | type | description |
297
+ | ------ | ----------------------------------------------------------- |
298
+ | `Bool` | `true` if the path is a directory path or `false` otherwise |
299
299
 
300
300
  Examples:
301
301
 
@@ -310,22 +310,22 @@ isDirectory(fromString("/bin/")) == true
310
310
  ### Path.**isAbsolute**
311
311
 
312
312
  ```grain
313
- isAbsolute : (path: Path) => Bool
313
+ isAbsolute: (path: Path) => Bool
314
314
  ```
315
315
 
316
316
  Determines whether the path is an absolute path.
317
317
 
318
318
  Parameters:
319
319
 
320
- |param|type|description|
321
- |-----|----|-----------|
322
- |`path`|`Path`|The path to inspect|
320
+ | param | type | description |
321
+ | ------ | ------ | ------------------- |
322
+ | `path` | `Path` | The path to inspect |
323
323
 
324
324
  Returns:
325
325
 
326
- |type|description|
327
- |----|-----------|
328
- |`Bool`|`true` if the path is absolute or `false` otherwise|
326
+ | type | description |
327
+ | ------ | --------------------------------------------------- |
328
+ | `Bool` | `true` if the path is absolute or `false` otherwise |
329
329
 
330
330
  Examples:
331
331
 
@@ -345,23 +345,23 @@ No other changes yet.
345
345
  </details>
346
346
 
347
347
  ```grain
348
- append : (path: Path, toAppend: Path) => Result<Path, AppendError>
348
+ append: (path: Path, toAppend: Path) => Result<Path, AppendError>
349
349
  ```
350
350
 
351
351
  Creates a new path by appending a relative path segment to a directory path.
352
352
 
353
353
  Parameters:
354
354
 
355
- |param|type|description|
356
- |-----|----|-----------|
357
- |`path`|`Path`|The base path|
358
- |`toAppend`|`Path`|The relative path to append|
355
+ | param | type | description |
356
+ | ---------- | ------ | --------------------------- |
357
+ | `path` | `Path` | The base path |
358
+ | `toAppend` | `Path` | The relative path to append |
359
359
 
360
360
  Returns:
361
361
 
362
- |type|description|
363
- |----|-----------|
364
- |`Result<Path, AppendError>`|`Ok(path)` combining the base and appended paths or `Err(err)` if the paths are incompatible|
362
+ | type | description |
363
+ | --------------------------- | -------------------------------------------------------------------------------------------- |
364
+ | `Result<Path, AppendError>` | `Ok(path)` combining the base and appended paths or `Err(err)` if the paths are incompatible |
365
365
 
366
366
  Examples:
367
367
 
@@ -385,7 +385,7 @@ No other changes yet.
385
385
  </details>
386
386
 
387
387
  ```grain
388
- relativeTo : (source: Path, dest: Path) => Result<Path, RelativizationError>
388
+ relativeTo: (source: Path, dest: Path) => Result<Path, RelativizationError>
389
389
  ```
390
390
 
391
391
  Attempts to construct a new relative path which will lead to the destination
@@ -399,16 +399,16 @@ source, the result will be `Err(ImpossibleRelativization)`.
399
399
 
400
400
  Parameters:
401
401
 
402
- |param|type|description|
403
- |-----|----|-----------|
404
- |`source`|`Path`|The source path|
405
- |`dest`|`Path`|The destination path to resolve|
402
+ | param | type | description |
403
+ | -------- | ------ | ------------------------------- |
404
+ | `source` | `Path` | The source path |
405
+ | `dest` | `Path` | The destination path to resolve |
406
406
 
407
407
  Returns:
408
408
 
409
- |type|description|
410
- |----|-----------|
411
- |`Result<Path, RelativizationError>`|`Ok(path)` containing the relative path if successfully resolved or `Err(err)` otherwise|
409
+ | type | description |
410
+ | ----------------------------------- | ---------------------------------------------------------------------------------------- |
411
+ | `Result<Path, RelativizationError>` | `Ok(path)` containing the relative path if successfully resolved or `Err(err)` otherwise |
412
412
 
413
413
  Examples:
414
414
 
@@ -444,7 +444,7 @@ No other changes yet.
444
444
  </details>
445
445
 
446
446
  ```grain
447
- ancestry :
447
+ ancestry:
448
448
  (base: Path, path: Path) => Result<AncestryStatus, IncompatibilityError>
449
449
  ```
450
450
 
@@ -452,16 +452,16 @@ Determines the relative ancestry betwen two paths.
452
452
 
453
453
  Parameters:
454
454
 
455
- |param|type|description|
456
- |-----|----|-----------|
457
- |`base`|`Path`|The first path to consider|
458
- |`path`|`Path`|The second path to consider|
455
+ | param | type | description |
456
+ | ------ | ------ | --------------------------- |
457
+ | `base` | `Path` | The first path to consider |
458
+ | `path` | `Path` | The second path to consider |
459
459
 
460
460
  Returns:
461
461
 
462
- |type|description|
463
- |----|-----------|
464
- |`Result<AncestryStatus, IncompatibilityError>`|`Ok(ancestryStatus)` with the relative ancestry between the paths if they are compatible or `Err(err)` if they are incompatible|
462
+ | type | description |
463
+ | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
464
+ | `Result<AncestryStatus, IncompatibilityError>` | `Ok(ancestryStatus)` with the relative ancestry between the paths if they are compatible or `Err(err)` if they are incompatible |
465
465
 
466
466
  Examples:
467
467
 
@@ -489,22 +489,22 @@ No other changes yet.
489
489
  </details>
490
490
 
491
491
  ```grain
492
- parent : (path: Path) => Path
492
+ parent: (path: Path) => Path
493
493
  ```
494
494
 
495
495
  Retrieves the path corresponding to the parent directory of the given path.
496
496
 
497
497
  Parameters:
498
498
 
499
- |param|type|description|
500
- |-----|----|-----------|
501
- |`path`|`Path`|The path to inspect|
499
+ | param | type | description |
500
+ | ------ | ------ | ------------------- |
501
+ | `path` | `Path` | The path to inspect |
502
502
 
503
503
  Returns:
504
504
 
505
- |type|description|
506
- |----|-----------|
507
- |`Path`|A path corresponding to the parent directory of the given path|
505
+ | type | description |
506
+ | ------ | -------------------------------------------------------------- |
507
+ | `Path` | A path corresponding to the parent directory of the given path |
508
508
 
509
509
  Examples:
510
510
 
@@ -524,22 +524,22 @@ No other changes yet.
524
524
  </details>
525
525
 
526
526
  ```grain
527
- basename : (path: Path) => Option<String>
527
+ basename: (path: Path) => Option<String>
528
528
  ```
529
529
 
530
530
  Retrieves the basename (named final segment) of a path.
531
531
 
532
532
  Parameters:
533
533
 
534
- |param|type|description|
535
- |-----|----|-----------|
536
- |`path`|`Path`|The path to inspect|
534
+ | param | type | description |
535
+ | ------ | ------ | ------------------- |
536
+ | `path` | `Path` | The path to inspect |
537
537
 
538
538
  Returns:
539
539
 
540
- |type|description|
541
- |----|-----------|
542
- |`Option<String>`|`Some(path)` containing the basename of the path or `None` if the path does not have one|
540
+ | type | description |
541
+ | ---------------- | ---------------------------------------------------------------------------------------- |
542
+ | `Option<String>` | `Some(path)` containing the basename of the path or `None` if the path does not have one |
543
543
 
544
544
  Examples:
545
545
 
@@ -559,22 +559,22 @@ No other changes yet.
559
559
  </details>
560
560
 
561
561
  ```grain
562
- stem : (path: Path) => Result<String, PathOperationError>
562
+ stem: (path: Path) => Result<String, PathOperationError>
563
563
  ```
564
564
 
565
565
  Retrieves the basename of a file path without the extension.
566
566
 
567
567
  Parameters:
568
568
 
569
- |param|type|description|
570
- |-----|----|-----------|
571
- |`path`|`Path`|The path to inspect|
569
+ | param | type | description |
570
+ | ------ | ------ | ------------------- |
571
+ | `path` | `Path` | The path to inspect |
572
572
 
573
573
  Returns:
574
574
 
575
- |type|description|
576
- |----|-----------|
577
- |`Result<String, PathOperationError>`|`Ok(path)` containing the stem of the file path or `Err(err)` if the path is a directory path|
575
+ | type | description |
576
+ | ------------------------------------ | --------------------------------------------------------------------------------------------- |
577
+ | `Result<String, PathOperationError>` | `Ok(path)` containing the stem of the file path or `Err(err)` if the path is a directory path |
578
578
 
579
579
  Examples:
580
580
 
@@ -602,22 +602,22 @@ No other changes yet.
602
602
  </details>
603
603
 
604
604
  ```grain
605
- extension : (path: Path) => Result<String, PathOperationError>
605
+ extension: (path: Path) => Result<String, PathOperationError>
606
606
  ```
607
607
 
608
608
  Retrieves the extension on the basename of a file path.
609
609
 
610
610
  Parameters:
611
611
 
612
- |param|type|description|
613
- |-----|----|-----------|
614
- |`path`|`Path`|The path to inspect|
612
+ | param | type | description |
613
+ | ------ | ------ | ------------------- |
614
+ | `path` | `Path` | The path to inspect |
615
615
 
616
616
  Returns:
617
617
 
618
- |type|description|
619
- |----|-----------|
620
- |`Result<String, PathOperationError>`|`Ok(path)` containing the extension of the file path or `Err(err)` if the path is a directory path|
618
+ | type | description |
619
+ | ------------------------------------ | -------------------------------------------------------------------------------------------------- |
620
+ | `Result<String, PathOperationError>` | `Ok(path)` containing the extension of the file path or `Err(err)` if the path is a directory path |
621
621
 
622
622
  Examples:
623
623
 
@@ -637,6 +637,97 @@ extension(fromString(".a.tar.gz")) == Ok(".tar.gz")
637
637
  extension(fromString("/dir/")) == Err(IncompatiblePathType) // can only take extension of a file path
638
638
  ```
639
639
 
640
+ ### Path.**removeExtension**
641
+
642
+ <details disabled>
643
+ <summary tabindex="-1">Added in <code>next</code></summary>
644
+ No other changes yet.
645
+ </details>
646
+
647
+ ```grain
648
+ removeExtension: (path: Path) => Path
649
+ ```
650
+
651
+ Removes the extension from a path, if there is no extension, returns the path as is.
652
+
653
+ Parameters:
654
+
655
+ | param | type | description |
656
+ | ------ | ------ | ------------------ |
657
+ | `path` | `Path` | The path to modify |
658
+
659
+ Returns:
660
+
661
+ | type | description |
662
+ | ------ | ----------------------------------- |
663
+ | `Path` | The path with the extension removed |
664
+
665
+ Examples:
666
+
667
+ ```grain
668
+ removeExtension(fromString("file.txt")) == fromString("file")
669
+ ```
670
+
671
+ ```grain
672
+ removeExtension(fromString(".gitignore")) == fromString(".gitignore")
673
+ ```
674
+
675
+ ```grain
676
+ removeExtension(fromString("./dir/file")) == fromString("dir/file")
677
+ ```
678
+
679
+ ```grain
680
+ removeExtension(fromString("./dir/")) == fromString("dir/")
681
+ ```
682
+
683
+ ### Path.**updateExtension**
684
+
685
+ <details disabled>
686
+ <summary tabindex="-1">Added in <code>next</code></summary>
687
+ No other changes yet.
688
+ </details>
689
+
690
+ ```grain
691
+ updateExtension: (path: Path, extension: String) => Path
692
+ ```
693
+
694
+ Updates the file extension of the given path.
695
+
696
+ Parameters:
697
+
698
+ | param | type | description |
699
+ | ----------- | -------- | ------------------ |
700
+ | `path` | `Path` | The path to modify |
701
+ | `extension` | `String` | The new extension |
702
+
703
+ Returns:
704
+
705
+ | type | description |
706
+ | ------ | ----------------- |
707
+ | `Path` | The modified path |
708
+
709
+ Examples:
710
+
711
+ ```grain
712
+ updateExtension(fromString("file.txt"), "ext") == fromString("file.ext")
713
+ ```
714
+
715
+ ```grain
716
+ updateExtension(fromString("file.txt"), "") == fromString("file.")
717
+ ```
718
+
719
+ ```grain
720
+ updateExtension(fromString(".gitignore"), "ext") == fromString(".gitignore.ext")
721
+ ```
722
+
723
+ ```grain
724
+ updateExtension(fromString("./dir/file"), "ext") == fromString("dir/file.ext")
725
+ ```
726
+
727
+ ```grain
728
+ updateExtension(fromString("./dir/"), "ext") == fromString("dir/")
729
+ ```
730
+
640
731
  ### Path.**root**
641
732
 
642
733
  <details disabled>
@@ -645,22 +736,22 @@ No other changes yet.
645
736
  </details>
646
737
 
647
738
  ```grain
648
- root : (path: Path) => Result<AbsoluteRoot, PathOperationError>
739
+ root: (path: Path) => Result<AbsoluteRoot, PathOperationError>
649
740
  ```
650
741
 
651
742
  Retrieves the root of the absolute path.
652
743
 
653
744
  Parameters:
654
745
 
655
- |param|type|description|
656
- |-----|----|-----------|
657
- |`path`|`Path`|The path to inspect|
746
+ | param | type | description |
747
+ | ------ | ------ | ------------------- |
748
+ | `path` | `Path` | The path to inspect |
658
749
 
659
750
  Returns:
660
751
 
661
- |type|description|
662
- |----|-----------|
663
- |`Result<AbsoluteRoot, PathOperationError>`|`Ok(root)` containing the root of the path or `Err(err)` if the path is a relative path|
752
+ | type | description |
753
+ | ------------------------------------------ | --------------------------------------------------------------------------------------- |
754
+ | `Result<AbsoluteRoot, PathOperationError>` | `Ok(root)` containing the root of the path or `Err(err)` if the path is a relative path |
664
755
 
665
756
  Examples:
666
757
 
package/pervasives.gr CHANGED
@@ -236,7 +236,7 @@ provide primitive unbox = "@unbox"
236
236
  primitive elideTypeInfo = "@meta.elide_type_info"
237
237
  @unsafe
238
238
  let setupExceptions = () => {
239
- Exception.dangerouslyRegisterPrinter(e => {
239
+ Exception.registerPrinter(e => {
240
240
  match (e) {
241
241
  Failure(msg) => Some("Failure: " ++ msg),
242
242
  InvalidArgument(msg) => Some("Invalid argument: " ++ msg),
@@ -247,7 +247,7 @@ let setupExceptions = () => {
247
247
  // If type information is elided, remove dependency on toString as
248
248
  // it will have no effect on exceptions
249
249
  if (!elideTypeInfo) {
250
- Exception.dangerouslyRegisterBasePrinter(e => Some(toString(e)))
250
+ Exception.registerBasePrinter(e => toString(e))
251
251
  }
252
252
  }
253
253