@grain/stdlib 0.7.0 → 0.7.2

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 (62) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/array.md +491 -491
  3. package/bigint.md +198 -198
  4. package/buffer.gr +66 -1
  5. package/buffer.md +395 -272
  6. package/bytes.gr +1 -0
  7. package/bytes.md +200 -199
  8. package/char.md +125 -125
  9. package/exception.md +9 -9
  10. package/float32.md +195 -195
  11. package/float64.md +195 -195
  12. package/fs.md +115 -115
  13. package/hash.md +16 -16
  14. package/int16.md +155 -155
  15. package/int32.gr +1 -1
  16. package/int32.md +207 -207
  17. package/int64.gr +1 -1
  18. package/int64.md +207 -207
  19. package/int8.md +155 -155
  20. package/json.md +59 -59
  21. package/list.md +347 -347
  22. package/map.md +222 -222
  23. package/marshal.md +12 -12
  24. package/number.gr +119 -5
  25. package/number.md +503 -261
  26. package/option.md +141 -141
  27. package/package.json +2 -2
  28. package/path.gr +82 -65
  29. package/path.md +210 -141
  30. package/pervasives.md +238 -238
  31. package/priorityqueue.md +112 -112
  32. package/queue.md +117 -117
  33. package/random.md +37 -37
  34. package/range.md +36 -36
  35. package/rational.md +107 -107
  36. package/regex.md +91 -91
  37. package/result.md +102 -102
  38. package/runtime/atof/decimal.md +6 -6
  39. package/runtime/compare.md +7 -7
  40. package/runtime/dataStructures.md +178 -178
  41. package/runtime/equal.md +7 -7
  42. package/runtime/exception.md +15 -15
  43. package/runtime/malloc.md +9 -9
  44. package/runtime/numbers.md +269 -269
  45. package/runtime/string.md +17 -17
  46. package/runtime/unsafe/conv.md +6 -6
  47. package/runtime/unsafe/memory.gr +2 -19
  48. package/runtime/unsafe/memory.md +10 -10
  49. package/runtime/utf8.md +31 -31
  50. package/runtime/wasi.md +9 -9
  51. package/set.md +211 -211
  52. package/stack.md +122 -122
  53. package/string.md +228 -228
  54. package/uint16.md +148 -148
  55. package/uint32.md +192 -192
  56. package/uint64.md +192 -192
  57. package/uint8.md +148 -148
  58. package/uri.md +77 -77
  59. package/wasi/file.md +269 -269
  60. package/wasi/process.md +21 -21
  61. package/wasi/random.md +9 -9
  62. package/wasi/time.md +12 -12
package/path.md CHANGED
@@ -28,12 +28,21 @@ No other changes yet.
28
28
  from "path" include Path
29
29
  ```
30
30
 
31
+ ```grain
32
+ let p = Path.fromString("./tmp/file.txt")
33
+ ```
34
+
31
35
  ## Types
32
36
 
33
37
  Type declarations included in the Path module.
34
38
 
35
39
  ### Path.**AbsoluteRoot**
36
40
 
41
+ <details disabled>
42
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
43
+ No other changes yet.
44
+ </details>
45
+
37
46
  ```grain
38
47
  enum AbsoluteRoot {
39
48
  Root,
@@ -45,6 +54,11 @@ Represents an absolute path's anchor point.
45
54
 
46
55
  ### Path.**Relative**
47
56
 
57
+ <details disabled>
58
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
59
+ No other changes yet.
60
+ </details>
61
+
48
62
  ```grain
49
63
  type Relative
50
64
  ```
@@ -53,6 +67,11 @@ Represents a relative path.
53
67
 
54
68
  ### Path.**Absolute**
55
69
 
70
+ <details disabled>
71
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
72
+ No other changes yet.
73
+ </details>
74
+
56
75
  ```grain
57
76
  type Absolute
58
77
  ```
@@ -61,6 +80,11 @@ Represents an absolute path.
61
80
 
62
81
  ### Path.**File**
63
82
 
83
+ <details disabled>
84
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
85
+ No other changes yet.
86
+ </details>
87
+
64
88
  ```grain
65
89
  type File
66
90
  ```
@@ -69,6 +93,11 @@ Represents a path referencing a file.
69
93
 
70
94
  ### Path.**Directory**
71
95
 
96
+ <details disabled>
97
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
98
+ No other changes yet.
99
+ </details>
100
+
72
101
  ```grain
73
102
  type Directory
74
103
  ```
@@ -77,6 +106,11 @@ Represents a path referencing a directory.
77
106
 
78
107
  ### Path.**TypedPath**
79
108
 
109
+ <details disabled>
110
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
111
+ No other changes yet.
112
+ </details>
113
+
80
114
  ```grain
81
115
  type TypedPath<a, b>
82
116
  ```
@@ -86,6 +120,11 @@ Represents a path typed on (`Absolute` or `Relative`) and (`File` or
86
120
 
87
121
  ### Path.**Path**
88
122
 
123
+ <details disabled>
124
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
125
+ No other changes yet.
126
+ </details>
127
+
89
128
  ```grain
90
129
  enum Path {
91
130
  AbsoluteFile(TypedPath<Absolute, File>),
@@ -99,6 +138,11 @@ Represents a system path.
99
138
 
100
139
  ### Path.**Platform**
101
140
 
141
+ <details disabled>
142
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
143
+ No other changes yet.
144
+ </details>
145
+
102
146
  ```grain
103
147
  enum Platform {
104
148
  Windows,
@@ -110,6 +154,11 @@ Represents a platform-specific path encoding scheme.
110
154
 
111
155
  ### Path.**PathOperationError**
112
156
 
157
+ <details disabled>
158
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
159
+ No other changes yet.
160
+ </details>
161
+
113
162
  ```grain
114
163
  enum PathOperationError {
115
164
  IncompatiblePathType,
@@ -120,6 +169,11 @@ Represents an error that can occur when finding a property of a path.
120
169
 
121
170
  ### Path.**AppendError**
122
171
 
172
+ <details disabled>
173
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
174
+ No other changes yet.
175
+ </details>
176
+
123
177
  ```grain
124
178
  enum AppendError {
125
179
  AppendToFile,
@@ -131,6 +185,11 @@ Represents an error that can occur when appending paths.
131
185
 
132
186
  ### Path.**AncestryStatus**
133
187
 
188
+ <details disabled>
189
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
190
+ No other changes yet.
191
+ </details>
192
+
134
193
  ```grain
135
194
  enum AncestryStatus {
136
195
  Descendant,
@@ -144,6 +203,11 @@ Represents the status of an ancestry check between two paths.
144
203
 
145
204
  ### Path.**IncompatibilityError**
146
205
 
206
+ <details disabled>
207
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
208
+ No other changes yet.
209
+ </details>
210
+
147
211
  ```grain
148
212
  enum IncompatibilityError {
149
213
  DifferentRoots,
@@ -156,6 +220,11 @@ for an operation.
156
220
 
157
221
  ### Path.**RelativizationError**
158
222
 
223
+ <details disabled>
224
+ <summary tabindex="-1">Added in <code>0.5.5</code></summary>
225
+ No other changes yet.
226
+ </details>
227
+
159
228
  ```grain
160
229
  enum RelativizationError {
161
230
  Incompatible(IncompatibilityError),
@@ -194,33 +263,33 @@ ambiguity.
194
263
 
195
264
  Parameters:
196
265
 
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|
266
+ | param | type | description |
267
+ | ----------- | ---------- | ------------------------------------------------------------- |
268
+ | `pathStr` | `String` | The string to parse as a path |
269
+ | `?platform` | `Platform` | The platform whose path separators should be used for parsing |
201
270
 
202
271
  Returns:
203
272
 
204
- |type|description|
205
- |----|-----------|
206
- |`Path`|The path wrapped with details encoded within the type|
273
+ | type | description |
274
+ | ------ | ----------------------------------------------------- |
275
+ | `Path` | The path wrapped with details encoded within the type |
207
276
 
208
277
  Examples:
209
278
 
210
279
  ```grain
211
- fromString("file.txt") // a relative Path referencing the file ./file.txt
280
+ Path.fromString("file.txt") // a relative Path referencing the file ./file.txt
212
281
  ```
213
282
 
214
283
  ```grain
215
- fromString(".") // a relative Path referencing the current directory
284
+ Path.fromString(".") // a relative Path referencing the current directory
216
285
  ```
217
286
 
218
287
  ```grain
219
- fromString("/bin/", Posix) // an absolute Path referencing the directory /bin/
288
+ Path.fromString("/bin/", Path.Posix) // an absolute Path referencing the directory /bin/
220
289
  ```
221
290
 
222
291
  ```grain
223
- fromString("C:\\file.txt", Windows) // a relative Path referencing the file C:\file.txt
292
+ Path.fromString("C:\\file.txt", Path.Windows) // a relative Path referencing the file C:\file.txt
224
293
  ```
225
294
 
226
295
  ### Path.**toString**
@@ -247,29 +316,29 @@ A trailing slash is added to directory paths.
247
316
 
248
317
  Parameters:
249
318
 
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|
319
+ | param | type | description |
320
+ | ----------- | ---------- | ------------------------------------------------------- |
321
+ | `path` | `Path` | The path to convert to a string |
322
+ | `?platform` | `Platform` | The `Platform` to use to represent the path as a string |
254
323
 
255
324
  Returns:
256
325
 
257
- |type|description|
258
- |----|-----------|
259
- |`String`|A string representing the given path|
326
+ | type | description |
327
+ | -------- | ------------------------------------ |
328
+ | `String` | A string representing the given path |
260
329
 
261
330
  Examples:
262
331
 
263
332
  ```grain
264
- toString(fromString("/file.txt")) == "/file.txt"
333
+ Path.toString(Path.fromString("/file.txt")) == "/file.txt"
265
334
  ```
266
335
 
267
336
  ```grain
268
- toString(fromString("dir/"), Posix) == "./dir/"
337
+ Path.toString(Path.fromString("dir/"), Path.Posix) == "./dir/"
269
338
  ```
270
339
 
271
340
  ```grain
272
- toString(fromString("C:/file.txt"), Windows) == "C:\\file.txt"
341
+ Path.toString(Path.fromString("C:/file.txt"), Path.Windows) == "C:\\file.txt"
273
342
  ```
274
343
 
275
344
  ### Path.**isDirectory**
@@ -287,24 +356,24 @@ Determines whether the path is a directory path.
287
356
 
288
357
  Parameters:
289
358
 
290
- |param|type|description|
291
- |-----|----|-----------|
292
- |`path`|`Path`|The path to inspect|
359
+ | param | type | description |
360
+ | ------ | ------ | ------------------- |
361
+ | `path` | `Path` | The path to inspect |
293
362
 
294
363
  Returns:
295
364
 
296
- |type|description|
297
- |----|-----------|
298
- |`Bool`|`true` if the path is a directory path or `false` otherwise|
365
+ | type | description |
366
+ | ------ | ----------------------------------------------------------- |
367
+ | `Bool` | `true` if the path is a directory path or `false` otherwise |
299
368
 
300
369
  Examples:
301
370
 
302
371
  ```grain
303
- isDirectory(fromString("file.txt")) == false
372
+ Path.isDirectory(Path.fromString("file.txt")) == false
304
373
  ```
305
374
 
306
375
  ```grain
307
- isDirectory(fromString("/bin/")) == true
376
+ Path.isDirectory(Path.fromString("/bin/")) == true
308
377
  ```
309
378
 
310
379
  ### Path.**isAbsolute**
@@ -317,24 +386,24 @@ Determines whether the path is an absolute path.
317
386
 
318
387
  Parameters:
319
388
 
320
- |param|type|description|
321
- |-----|----|-----------|
322
- |`path`|`Path`|The path to inspect|
389
+ | param | type | description |
390
+ | ------ | ------ | ------------------- |
391
+ | `path` | `Path` | The path to inspect |
323
392
 
324
393
  Returns:
325
394
 
326
- |type|description|
327
- |----|-----------|
328
- |`Bool`|`true` if the path is absolute or `false` otherwise|
395
+ | type | description |
396
+ | ------ | --------------------------------------------------- |
397
+ | `Bool` | `true` if the path is absolute or `false` otherwise |
329
398
 
330
399
  Examples:
331
400
 
332
401
  ```grain
333
- isAbsolute(fromString("/Users/me")) == true
402
+ Path.isAbsolute(Path.fromString("/Users/me")) == true
334
403
  ```
335
404
 
336
405
  ```grain
337
- isAbsolute(fromString("./file.txt")) == false
406
+ Path.isAbsolute(Path.fromString("./file.txt")) == false
338
407
  ```
339
408
 
340
409
  ### Path.**append**
@@ -352,29 +421,29 @@ Creates a new path by appending a relative path segment to a directory path.
352
421
 
353
422
  Parameters:
354
423
 
355
- |param|type|description|
356
- |-----|----|-----------|
357
- |`path`|`Path`|The base path|
358
- |`toAppend`|`Path`|The relative path to append|
424
+ | param | type | description |
425
+ | ---------- | ------ | --------------------------- |
426
+ | `path` | `Path` | The base path |
427
+ | `toAppend` | `Path` | The relative path to append |
359
428
 
360
429
  Returns:
361
430
 
362
- |type|description|
363
- |----|-----------|
364
- |`Result<Path, AppendError>`|`Ok(path)` combining the base and appended paths or `Err(err)` if the paths are incompatible|
431
+ | type | description |
432
+ | --------------------------- | -------------------------------------------------------------------------------------------- |
433
+ | `Result<Path, AppendError>` | `Ok(path)` combining the base and appended paths or `Err(err)` if the paths are incompatible |
365
434
 
366
435
  Examples:
367
436
 
368
437
  ```grain
369
- append(fromString("./dir/"), fromString("file.txt")) == Ok(fromString("./dir/file.txt"))
438
+ Path.append(Path.fromString("./dir/"), Path.fromString("file.txt")) == Ok(Path.fromString("./dir/file.txt"))
370
439
  ```
371
440
 
372
441
  ```grain
373
- append(fromString("a.txt"), fromString("b.sh")) == Err(AppendToFile) // cannot append to file path
442
+ Path.append(Path.fromString("a.txt"), Path.fromString("b.sh")) == Err(Path.AppendToFile) // cannot append to file path
374
443
  ```
375
444
 
376
445
  ```grain
377
- append(fromString("./dir/"), fromString("/dir2")) == Err(AppendAbsolute) // cannot append an absolute path
446
+ Path.append(Path.fromString("./dir/"), Path.fromString("/dir2")) == Err(Path.AppendAbsolute) // cannot append an absolute path
378
447
  ```
379
448
 
380
449
  ### Path.**relativeTo**
@@ -392,48 +461,48 @@ Attempts to construct a new relative path which will lead to the destination
392
461
  path from the source path.
393
462
 
394
463
  If the source and destination are incompatible in their bases, the result
395
- will be `Err(IncompatibilityError)`.
464
+ will be `Err(Path.IncompatibilityError)`.
396
465
 
397
466
  If the route to the destination cannot be concretely determined from the
398
- source, the result will be `Err(ImpossibleRelativization)`.
467
+ source, the result will be `Err(Path.ImpossibleRelativization)`.
399
468
 
400
469
  Parameters:
401
470
 
402
- |param|type|description|
403
- |-----|----|-----------|
404
- |`source`|`Path`|The source path|
405
- |`dest`|`Path`|The destination path to resolve|
471
+ | param | type | description |
472
+ | -------- | ------ | ------------------------------- |
473
+ | `source` | `Path` | The source path |
474
+ | `dest` | `Path` | The destination path to resolve |
406
475
 
407
476
  Returns:
408
477
 
409
- |type|description|
410
- |----|-----------|
411
- |`Result<Path, RelativizationError>`|`Ok(path)` containing the relative path if successfully resolved or `Err(err)` otherwise|
478
+ | type | description |
479
+ | ----------------------------------- | ---------------------------------------------------------------------------------------- |
480
+ | `Result<Path, RelativizationError>` | `Ok(path)` containing the relative path if successfully resolved or `Err(err)` otherwise |
412
481
 
413
482
  Examples:
414
483
 
415
484
  ```grain
416
- relativeTo(fromString("/usr"), fromString("/usr/bin")) == Ok(fromString("./bin"))
485
+ Path.relativeTo(Path.fromString("/usr"), Path.fromString("/usr/bin")) == Ok(Path.fromString("./bin"))
417
486
  ```
418
487
 
419
488
  ```grain
420
- relativeTo(fromString("/home/me"), fromString("/home/me")) == Ok(fromString("."))
489
+ Path.relativeTo(Path.fromString("/home/me"), Path.fromString("/home/me")) == Ok(Path.fromString("."))
421
490
  ```
422
491
 
423
492
  ```grain
424
- relativeTo(fromString("/file.txt"), fromString("/etc/")) == Ok(fromString("../etc/"))
493
+ Path.relativeTo(Path.fromString("/file.txt"), Path.fromString("/etc/")) == Ok(Path.fromString("../etc/"))
425
494
  ```
426
495
 
427
496
  ```grain
428
- relativeTo(fromString(".."), fromString("../../thing")) Ok(fromString("../thing"))
497
+ Path.relativeTo(Path.fromString(".."), Path.fromString("../../thing")) Ok(Path.fromString("../thing"))
429
498
  ```
430
499
 
431
500
  ```grain
432
- relativeTo(fromString("/usr/bin"), fromString("C:/Users")) == Err(Incompatible(DifferentRoots))
501
+ Path.relativeTo(Path.fromString("/usr/bin"), Path.fromString("C:/Users")) == Err(Path.Incompatible(Path.DifferentRoots))
433
502
  ```
434
503
 
435
504
  ```grain
436
- relativeTo(fromString("../here"), fromString("./there")) == Err(ImpossibleRelativization)
505
+ Path.relativeTo(Path.fromString("../here"), Path.fromString("./there")) == Err(Path.ImpossibleRelativization)
437
506
  ```
438
507
 
439
508
  ### Path.**ancestry**
@@ -448,37 +517,37 @@ ancestry:
448
517
  (base: Path, path: Path) => Result<AncestryStatus, IncompatibilityError>
449
518
  ```
450
519
 
451
- Determines the relative ancestry betwen two paths.
520
+ Determines the relative ancestry between two paths.
452
521
 
453
522
  Parameters:
454
523
 
455
- |param|type|description|
456
- |-----|----|-----------|
457
- |`base`|`Path`|The first path to consider|
458
- |`path`|`Path`|The second path to consider|
524
+ | param | type | description |
525
+ | ------ | ------ | --------------------------- |
526
+ | `base` | `Path` | The first path to consider |
527
+ | `path` | `Path` | The second path to consider |
459
528
 
460
529
  Returns:
461
530
 
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|
531
+ | type | description |
532
+ | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
533
+ | `Result<AncestryStatus, IncompatibilityError>` | `Ok(ancestryStatus)` with the relative ancestry between the paths if they are compatible or `Err(err)` if they are incompatible |
465
534
 
466
535
  Examples:
467
536
 
468
537
  ```grain
469
- ancestry(fromString("/usr"), fromString("/usr/bin/bash")) == Ok(Ancestor)
538
+ Path.ancestry(Path.fromString("/usr"), Path.fromString("/usr/bin/bash")) == Ok(Path.Ancestor)
470
539
  ```
471
540
 
472
541
  ```grain
473
- ancestry(fromString("/Users/me"), fromString("/Users")) == Ok(Descendant)
542
+ Path.ancestry(Path.fromString("/Users/me"), Path.fromString("/Users")) == Ok(Path.Descendant)
474
543
  ```
475
544
 
476
545
  ```grain
477
- ancestry(fromString("/usr"), fromString("/etc")) == Ok(Neither)
546
+ Path.ancestry(Path.fromString("/usr"), Path.fromString("/etc")) == Ok(Path.Neither)
478
547
  ```
479
548
 
480
549
  ```grain
481
- ancestry(fromString("C:/dir1"), fromString("/dir2")) == Err(DifferentRoots)
550
+ Path.ancestry(Path.fromString("C:/dir1"), Path.fromString("/dir2")) == Err(Path.DifferentRoots)
482
551
  ```
483
552
 
484
553
  ### Path.**parent**
@@ -496,24 +565,24 @@ Retrieves the path corresponding to the parent directory of the given path.
496
565
 
497
566
  Parameters:
498
567
 
499
- |param|type|description|
500
- |-----|----|-----------|
501
- |`path`|`Path`|The path to inspect|
568
+ | param | type | description |
569
+ | ------ | ------ | ------------------- |
570
+ | `path` | `Path` | The path to inspect |
502
571
 
503
572
  Returns:
504
573
 
505
- |type|description|
506
- |----|-----------|
507
- |`Path`|A path corresponding to the parent directory of the given path|
574
+ | type | description |
575
+ | ------ | -------------------------------------------------------------- |
576
+ | `Path` | A path corresponding to the parent directory of the given path |
508
577
 
509
578
  Examples:
510
579
 
511
580
  ```grain
512
- parent(fromString("./dir/inner")) == fromString("./dir/")
581
+ Path.parent(Path.fromString("./dir/inner")) == Path.fromString("./dir/")
513
582
  ```
514
583
 
515
584
  ```grain
516
- parent(fromString("/")) == fromString("/")
585
+ Path.parent(Path.fromString("/")) == Path.fromString("/")
517
586
  ```
518
587
 
519
588
  ### Path.**basename**
@@ -531,24 +600,24 @@ Retrieves the basename (named final segment) of a path.
531
600
 
532
601
  Parameters:
533
602
 
534
- |param|type|description|
535
- |-----|----|-----------|
536
- |`path`|`Path`|The path to inspect|
603
+ | param | type | description |
604
+ | ------ | ------ | ------------------- |
605
+ | `path` | `Path` | The path to inspect |
537
606
 
538
607
  Returns:
539
608
 
540
- |type|description|
541
- |----|-----------|
542
- |`Option<String>`|`Some(path)` containing the basename of the path or `None` if the path does not have one|
609
+ | type | description |
610
+ | ---------------- | ---------------------------------------------------------------------------------------- |
611
+ | `Option<String>` | `Some(path)` containing the basename of the path or `None` if the path does not have one |
543
612
 
544
613
  Examples:
545
614
 
546
615
  ```grain
547
- basename(fromString("./dir/file.txt")) == Some("file.txt")
616
+ Path.basename(Path.fromString("./dir/file.txt")) == Some("file.txt")
548
617
  ```
549
618
 
550
619
  ```grain
551
- basename(fromString(".."))) == None
620
+ Path.basename(Path.fromString(".."))) == None
552
621
  ```
553
622
 
554
623
  ### Path.**stem**
@@ -566,32 +635,32 @@ Retrieves the basename of a file path without the extension.
566
635
 
567
636
  Parameters:
568
637
 
569
- |param|type|description|
570
- |-----|----|-----------|
571
- |`path`|`Path`|The path to inspect|
638
+ | param | type | description |
639
+ | ------ | ------ | ------------------- |
640
+ | `path` | `Path` | The path to inspect |
572
641
 
573
642
  Returns:
574
643
 
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|
644
+ | type | description |
645
+ | ------------------------------------ | --------------------------------------------------------------------------------------------- |
646
+ | `Result<String, PathOperationError>` | `Ok(path)` containing the stem of the file path or `Err(err)` if the path is a directory path |
578
647
 
579
648
  Examples:
580
649
 
581
650
  ```grain
582
- stem(fromString("file.txt")) == Ok("file")
651
+ Path.stem(Path.fromString("file.txt")) == Ok("file")
583
652
  ```
584
653
 
585
654
  ```grain
586
- stem(fromString(".gitignore")) == Ok(".gitignore")
655
+ Path.stem(Path.fromString(".gitignore")) == Ok(".gitignore")
587
656
  ```
588
657
 
589
658
  ```grain
590
- stem(fromString(".a.tar.gz")) == Ok(".a")
659
+ Path.stem(Path.fromString(".a.tar.gz")) == Ok(".a")
591
660
  ```
592
661
 
593
662
  ```grain
594
- stem(fromString("/dir/")) == Err(IncompatiblePathType) // can only take stem of a file path
663
+ Path.stem(Path.fromString("/dir/")) == Err(Path.IncompatiblePathType) // can only take stem of a file path
595
664
  ```
596
665
 
597
666
  ### Path.**extension**
@@ -609,32 +678,32 @@ Retrieves the extension on the basename of a file path.
609
678
 
610
679
  Parameters:
611
680
 
612
- |param|type|description|
613
- |-----|----|-----------|
614
- |`path`|`Path`|The path to inspect|
681
+ | param | type | description |
682
+ | ------ | ------ | ------------------- |
683
+ | `path` | `Path` | The path to inspect |
615
684
 
616
685
  Returns:
617
686
 
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|
687
+ | type | description |
688
+ | ------------------------------------ | -------------------------------------------------------------------------------------------------- |
689
+ | `Result<String, PathOperationError>` | `Ok(path)` containing the extension of the file path or `Err(err)` if the path is a directory path |
621
690
 
622
691
  Examples:
623
692
 
624
693
  ```grain
625
- extension(fromString("file.txt")) == Ok(".txt")
694
+ Path.extension(Path.fromString("file.txt")) == Ok(".txt")
626
695
  ```
627
696
 
628
697
  ```grain
629
- extension(fromString(".gitignore")) == Ok("")
698
+ Path.extension(Path.fromString(".gitignore")) == Ok("")
630
699
  ```
631
700
 
632
701
  ```grain
633
- extension(fromString(".a.tar.gz")) == Ok(".tar.gz")
702
+ Path.extension(Path.fromString(".a.tar.gz")) == Ok(".tar.gz")
634
703
  ```
635
704
 
636
705
  ```grain
637
- extension(fromString("/dir/")) == Err(IncompatiblePathType) // can only take extension of a file path
706
+ Path.extension(Path.fromString("/dir/")) == Err(Path.IncompatiblePathType) // can only take extension of a file path
638
707
  ```
639
708
 
640
709
  ### Path.**removeExtension**
@@ -652,32 +721,32 @@ Removes the extension from a path, if there is no extension, returns the path as
652
721
 
653
722
  Parameters:
654
723
 
655
- |param|type|description|
656
- |-----|----|-----------|
657
- |`path`|`Path`|The path to modify|
724
+ | param | type | description |
725
+ | ------ | ------ | ------------------ |
726
+ | `path` | `Path` | The path to modify |
658
727
 
659
728
  Returns:
660
729
 
661
- |type|description|
662
- |----|-----------|
663
- |`Path`|The path with the extension removed|
730
+ | type | description |
731
+ | ------ | ----------------------------------- |
732
+ | `Path` | The path with the extension removed |
664
733
 
665
734
  Examples:
666
735
 
667
736
  ```grain
668
- removeExtension(fromString("file.txt")) == fromString("file")
737
+ Path.removeExtension(Path.fromString("file.txt")) == Path.fromString("file")
669
738
  ```
670
739
 
671
740
  ```grain
672
- removeExtension(fromString(".gitignore")) == fromString(".gitignore")
741
+ Path.removeExtension(Path.fromString(".gitignore")) == Path.fromString(".gitignore")
673
742
  ```
674
743
 
675
744
  ```grain
676
- removeExtension(fromString("./dir/file")) == fromString("dir/file")
745
+ Path.removeExtension(Path.fromString("./dir/file")) == Path.fromString("dir/file")
677
746
  ```
678
747
 
679
748
  ```grain
680
- removeExtension(fromString("./dir/")) == fromString("dir/")
749
+ Path.removeExtension(Path.fromString("./dir/")) == Path.fromString("dir/")
681
750
  ```
682
751
 
683
752
  ### Path.**updateExtension**
@@ -695,37 +764,37 @@ Updates the file extension of the given path.
695
764
 
696
765
  Parameters:
697
766
 
698
- |param|type|description|
699
- |-----|----|-----------|
700
- |`path`|`Path`|The path to modify|
701
- |`extension`|`String`|The new extension|
767
+ | param | type | description |
768
+ | ----------- | -------- | ------------------ |
769
+ | `path` | `Path` | The path to modify |
770
+ | `extension` | `String` | The new extension |
702
771
 
703
772
  Returns:
704
773
 
705
- |type|description|
706
- |----|-----------|
707
- |`Path`|The modified path|
774
+ | type | description |
775
+ | ------ | ----------------- |
776
+ | `Path` | The modified path |
708
777
 
709
778
  Examples:
710
779
 
711
780
  ```grain
712
- updateExtension(fromString("file.txt"), "ext") == fromString("file.ext")
781
+ Path.updateExtension(Path.fromString("file.txt"), "ext") == Path.fromString("file.ext")
713
782
  ```
714
783
 
715
784
  ```grain
716
- updateExtension(fromString("file.txt"), "") == fromString("file.")
785
+ Path.updateExtension(Path.fromString("file.txt"), "") == Path.fromString("file.")
717
786
  ```
718
787
 
719
788
  ```grain
720
- updateExtension(fromString(".gitignore"), "ext") == fromString(".gitignore.ext")
789
+ Path.updateExtension(Path.fromString(".gitignore"), "ext") == Path.fromString(".gitignore.ext")
721
790
  ```
722
791
 
723
792
  ```grain
724
- updateExtension(fromString("./dir/file"), "ext") == fromString("dir/file.ext")
793
+ Path.updateExtension(Path.fromString("./dir/file"), "ext") == Path.fromString("dir/file.ext")
725
794
  ```
726
795
 
727
796
  ```grain
728
- updateExtension(fromString("./dir/"), "ext") == fromString("dir/")
797
+ Path.updateExtension(Path.fromString("./dir/"), "ext") == Path.fromString("dir/")
729
798
  ```
730
799
 
731
800
  ### Path.**root**
@@ -743,27 +812,27 @@ Retrieves the root of the absolute path.
743
812
 
744
813
  Parameters:
745
814
 
746
- |param|type|description|
747
- |-----|----|-----------|
748
- |`path`|`Path`|The path to inspect|
815
+ | param | type | description |
816
+ | ------ | ------ | ------------------- |
817
+ | `path` | `Path` | The path to inspect |
749
818
 
750
819
  Returns:
751
820
 
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|
821
+ | type | description |
822
+ | ------------------------------------------ | --------------------------------------------------------------------------------------- |
823
+ | `Result<AbsoluteRoot, PathOperationError>` | `Ok(root)` containing the root of the path or `Err(err)` if the path is a relative path |
755
824
 
756
825
  Examples:
757
826
 
758
827
  ```grain
759
- root(fromString("C:/Users/me/")) == Ok(Drive('C'))
828
+ Path.root(Path.fromString("C:/Users/me/")) == Ok(Path.Drive('C'))
760
829
  ```
761
830
 
762
831
  ```grain
763
- root(fromString("/home/me/")) == Ok(Root)
832
+ Path.root(Path.fromString("/home/me/")) == Ok(Path.Root)
764
833
  ```
765
834
 
766
835
  ```grain
767
- root(fromString("./file.txt")) == Err(IncompatiblePathType)
836
+ Path.root(Path.fromString("./file.txt")) == Err(Path.IncompatiblePathType)
768
837
  ```
769
838