@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grain/stdlib",
|
|
3
|
-
"version": "0.
|
|
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": ">=
|
|
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
|
|
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
|
-
|
|
200
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
253
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
290
|
+
| param | type | description |
|
|
291
|
+
| ------ | ------ | ------------------- |
|
|
292
|
+
| `path` | `Path` | The path to inspect |
|
|
293
293
|
|
|
294
294
|
Returns:
|
|
295
295
|
|
|
296
|
-
|type|description|
|
|
297
|
-
|
|
298
|
-
|
|
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
|
|
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
|
-
|
|
320
|
+
| param | type | description |
|
|
321
|
+
| ------ | ------ | ------------------- |
|
|
322
|
+
| `path` | `Path` | The path to inspect |
|
|
323
323
|
|
|
324
324
|
Returns:
|
|
325
325
|
|
|
326
|
-
|type|description|
|
|
327
|
-
|
|
328
|
-
|
|
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
|
|
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
|
-
|
|
358
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
405
|
-
|
|
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
|
-
|
|
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
|
-
|
|
458
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
499
|
+
| param | type | description |
|
|
500
|
+
| ------ | ------ | ------------------- |
|
|
501
|
+
| `path` | `Path` | The path to inspect |
|
|
502
502
|
|
|
503
503
|
Returns:
|
|
504
504
|
|
|
505
|
-
|type|description|
|
|
506
|
-
|
|
507
|
-
|
|
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
|
|
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
|
-
|
|
534
|
+
| param | type | description |
|
|
535
|
+
| ------ | ------ | ------------------- |
|
|
536
|
+
| `path` | `Path` | The path to inspect |
|
|
537
537
|
|
|
538
538
|
Returns:
|
|
539
539
|
|
|
540
|
-
|type|description|
|
|
541
|
-
|
|
542
|
-
|
|
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
|
|
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
|
-
|
|
569
|
+
| param | type | description |
|
|
570
|
+
| ------ | ------ | ------------------- |
|
|
571
|
+
| `path` | `Path` | The path to inspect |
|
|
572
572
|
|
|
573
573
|
Returns:
|
|
574
574
|
|
|
575
|
-
|type|description|
|
|
576
|
-
|
|
577
|
-
|
|
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
|
|
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
|
-
|
|
612
|
+
| param | type | description |
|
|
613
|
+
| ------ | ------ | ------------------- |
|
|
614
|
+
| `path` | `Path` | The path to inspect |
|
|
615
615
|
|
|
616
616
|
Returns:
|
|
617
617
|
|
|
618
|
-
|type|description|
|
|
619
|
-
|
|
620
|
-
|
|
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
|
|
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
|
-
|
|
746
|
+
| param | type | description |
|
|
747
|
+
| ------ | ------ | ------------------- |
|
|
748
|
+
| `path` | `Path` | The path to inspect |
|
|
658
749
|
|
|
659
750
|
Returns:
|
|
660
751
|
|
|
661
|
-
|type|description|
|
|
662
|
-
|
|
663
|
-
|
|
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.
|
|
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.
|
|
250
|
+
Exception.registerBasePrinter(e => toString(e))
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
|