@grain/stdlib 0.4.1 → 0.4.5

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 (57) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/LICENSE +21 -0
  3. package/README.md +34 -0
  4. package/array.gr +200 -89
  5. package/array.md +81 -5
  6. package/buffer.gr +93 -36
  7. package/bytes.gr +512 -407
  8. package/bytes.md +621 -0
  9. package/char.gr +119 -55
  10. package/char.md +200 -0
  11. package/hash.gr +42 -15
  12. package/hash.md +44 -0
  13. package/list.gr +121 -50
  14. package/map.gr +106 -110
  15. package/number.gr +37 -1
  16. package/number.md +66 -0
  17. package/option.gr +260 -53
  18. package/option.md +579 -0
  19. package/package.json +33 -29
  20. package/pervasives.gr +32 -20
  21. package/queue.gr +102 -30
  22. package/queue.md +191 -0
  23. package/range.gr +26 -26
  24. package/range.md +1 -1
  25. package/regex.gr +3055 -0
  26. package/regex.md +449 -0
  27. package/result.gr +216 -70
  28. package/result.md +446 -0
  29. package/runtime/dataStructures.gr +28 -29
  30. package/runtime/debug.gr +0 -1
  31. package/runtime/equal.gr +37 -16
  32. package/runtime/exception.gr +28 -15
  33. package/runtime/gc.gr +33 -20
  34. package/runtime/malloc.gr +19 -11
  35. package/runtime/numberUtils.gr +208 -105
  36. package/runtime/numbers.gr +217 -118
  37. package/runtime/string.gr +150 -59
  38. package/runtime/stringUtils.gr +176 -0
  39. package/runtime/unsafe/conv.gr +51 -8
  40. package/runtime/unsafe/memory.gr +14 -3
  41. package/runtime/unsafe/printWasm.gr +4 -4
  42. package/runtime/unsafe/tags.gr +2 -2
  43. package/runtime/unsafe/wasmf32.gr +9 -2
  44. package/runtime/unsafe/wasmf64.gr +9 -2
  45. package/runtime/unsafe/wasmi32.gr +65 -47
  46. package/runtime/unsafe/wasmi64.gr +78 -50
  47. package/runtime/wasi.gr +199 -45
  48. package/set.gr +281 -119
  49. package/set.md +502 -0
  50. package/stack.gr +26 -26
  51. package/stack.md +143 -0
  52. package/string.gr +697 -329
  53. package/string.md +815 -0
  54. package/sys/file.gr +356 -177
  55. package/sys/process.gr +10 -6
  56. package/sys/random.gr +3 -6
  57. package/sys/time.gr +3 -3
package/bytes.md ADDED
@@ -0,0 +1,621 @@
1
+ ---
2
+ title: Bytes
3
+ ---
4
+
5
+ Utilities for working with byte sequences.
6
+
7
+ <details disabled>
8
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
9
+ No other changes yet.
10
+ </details>
11
+
12
+ ```grain
13
+ import Bytes from "bytes"
14
+ ```
15
+
16
+ ## Values
17
+
18
+ Functions for working with the Bytes data type.
19
+
20
+ ### Bytes.**make**
21
+
22
+ <details disabled>
23
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
24
+ No other changes yet.
25
+ </details>
26
+
27
+ ```grain
28
+ make : Number -> Bytes
29
+ ```
30
+
31
+ Creates a new byte sequence of the input size.
32
+
33
+ Parameters:
34
+
35
+ |param|type|description|
36
+ |-----|----|-----------|
37
+ |`size`|`Number`|The number of bytes to store|
38
+
39
+ Returns:
40
+
41
+ |type|description|
42
+ |----|-----------|
43
+ |`Bytes`|The new byte sequence|
44
+
45
+ ### Bytes.**empty**
46
+
47
+ <details disabled>
48
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
49
+ No other changes yet.
50
+ </details>
51
+
52
+ ```grain
53
+ empty : Bytes
54
+ ```
55
+
56
+ An empty byte sequence.
57
+
58
+ ### Bytes.**fromString**
59
+
60
+ <details disabled>
61
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
62
+ No other changes yet.
63
+ </details>
64
+
65
+ ```grain
66
+ fromString : String -> Bytes
67
+ ```
68
+
69
+ Creates a new byte sequence from the input string.
70
+
71
+ Parameters:
72
+
73
+ |param|type|description|
74
+ |-----|----|-----------|
75
+ |`string`|`String`|The string to copy into a byte sequence|
76
+
77
+ Returns:
78
+
79
+ |type|description|
80
+ |----|-----------|
81
+ |`Bytes`|The new byte sequence|
82
+
83
+ ### Bytes.**toString**
84
+
85
+ <details disabled>
86
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
87
+ No other changes yet.
88
+ </details>
89
+
90
+ ```grain
91
+ toString : Bytes -> String
92
+ ```
93
+
94
+ Creates a new string from the input bytes.
95
+
96
+ Parameters:
97
+
98
+ |param|type|description|
99
+ |-----|----|-----------|
100
+ |`bytes`|`Bytes`|The source byte sequence|
101
+
102
+ Returns:
103
+
104
+ |type|description|
105
+ |----|-----------|
106
+ |`String`|The string representation of the bytes|
107
+
108
+ ### Bytes.**length**
109
+
110
+ <details disabled>
111
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
112
+ No other changes yet.
113
+ </details>
114
+
115
+ ```grain
116
+ length : Bytes -> Number
117
+ ```
118
+
119
+ Returns the length of a byte sequence.
120
+
121
+ Parameters:
122
+
123
+ |param|type|description|
124
+ |-----|----|-----------|
125
+ |`bytes`|`Bytes`|The byte sequence to inspect|
126
+
127
+ Returns:
128
+
129
+ |type|description|
130
+ |----|-----------|
131
+ |`Number`|The number of bytes|
132
+
133
+ ### Bytes.**copy**
134
+
135
+ <details disabled>
136
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
137
+ No other changes yet.
138
+ </details>
139
+
140
+ ```grain
141
+ copy : Bytes -> Bytes
142
+ ```
143
+
144
+ Creates a new byte sequence that contains the same bytes as the input byte sequence.
145
+
146
+ Parameters:
147
+
148
+ |param|type|description|
149
+ |-----|----|-----------|
150
+ |`bytes`|`Bytes`|The byte sequence to copy|
151
+
152
+ Returns:
153
+
154
+ |type|description|
155
+ |----|-----------|
156
+ |`Bytes`|The new byte sequence|
157
+
158
+ ### Bytes.**slice**
159
+
160
+ <details disabled>
161
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
162
+ No other changes yet.
163
+ </details>
164
+
165
+ ```grain
166
+ slice : (Number, Number, Bytes) -> Bytes
167
+ ```
168
+
169
+ Returns a copy of a subset of the input byte sequence.
170
+
171
+ Parameters:
172
+
173
+ |param|type|description|
174
+ |-----|----|-----------|
175
+ |`start`|`Number`|The start index|
176
+ |`length`|`Number`|The number of bytes to include after the starting index|
177
+ |`bytes`|`Bytes`|The byte sequence to copy from|
178
+
179
+ Returns:
180
+
181
+ |type|description|
182
+ |----|-----------|
183
+ |`Bytes`|A byte sequence with of the copied bytes|
184
+
185
+ ### Bytes.**resize**
186
+
187
+ <details disabled>
188
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
189
+ No other changes yet.
190
+ </details>
191
+
192
+ ```grain
193
+ resize : (Number, Number, Bytes) -> Bytes
194
+ ```
195
+
196
+ Returns a copy of a byte sequence with bytes added or removed from the beginning and/or end.
197
+
198
+ A positive number represents bytes to add, while a negative number represents bytes to remove.
199
+
200
+ Parameters:
201
+
202
+ |param|type|description|
203
+ |-----|----|-----------|
204
+ |`left`|`Number`|The number of uninitialized bytes to prepend|
205
+ |`right`|`Number`|The number of uninitialized bytes to append|
206
+ |`bytes`|`Bytes`|The byte sequence get a subset of bytes from|
207
+
208
+ Returns:
209
+
210
+ |type|description|
211
+ |----|-----------|
212
+ |`Bytes`|A resized byte sequence|
213
+
214
+ ### Bytes.**move**
215
+
216
+ <details disabled>
217
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
218
+ No other changes yet.
219
+ </details>
220
+
221
+ ```grain
222
+ move : (Number, Number, Number, Bytes, Bytes) -> Void
223
+ ```
224
+
225
+ Copies a range of bytes from a source byte sequence to a given location
226
+ in a destination byte sequence.
227
+
228
+ Parameters:
229
+
230
+ |param|type|description|
231
+ |-----|----|-----------|
232
+ |`srcIndex`|`Number`|The starting index to copy bytes from|
233
+ |`dstIndex`|`Number`|The starting index to copy bytes into|
234
+ |`length`|`Number`|The amount of bytes to copy from the source buffer|
235
+ |`src`|`Bytes`|The source byte sequence|
236
+ |`dst`|`Bytes`|The destination byte sequence|
237
+
238
+ ### Bytes.**concat**
239
+
240
+ <details disabled>
241
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
242
+ No other changes yet.
243
+ </details>
244
+
245
+ ```grain
246
+ concat : (Bytes, Bytes) -> Bytes
247
+ ```
248
+
249
+ Creates a new byte sequence that contains the bytes of both byte sequences.
250
+
251
+ Parameters:
252
+
253
+ |param|type|description|
254
+ |-----|----|-----------|
255
+ |`bytes1`|`Bytes`|The beginning byte sequence|
256
+ |`bytes2`|`Bytes`|The ending byte sequence|
257
+
258
+ Returns:
259
+
260
+ |type|description|
261
+ |----|-----------|
262
+ |`Bytes`|The new byte sequence|
263
+
264
+ ### Bytes.**fill**
265
+
266
+ <details disabled>
267
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
268
+ No other changes yet.
269
+ </details>
270
+
271
+ ```grain
272
+ fill : (Int32, Bytes) -> Void
273
+ ```
274
+
275
+ Replaces all bytes in a byte sequnce with the new value provided.
276
+
277
+ Parameters:
278
+
279
+ |param|type|description|
280
+ |-----|----|-----------|
281
+ |`value`|`Int32`|The value replacing each byte|
282
+ |`bytes`|`Bytes`|The byte sequence to update|
283
+
284
+ ## Binary operations on integers
285
+
286
+ Functions for encoding and decoding integers stored in a byte sequence.
287
+
288
+ ### Bytes.**getInt8S**
289
+
290
+ <details disabled>
291
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
292
+ No other changes yet.
293
+ </details>
294
+
295
+ ```grain
296
+ getInt8S : (Number, Bytes) -> Int32
297
+ ```
298
+
299
+ Gets a signed 8-bit integer starting at the given byte index.
300
+
301
+ Parameters:
302
+
303
+ |param|type|description|
304
+ |-----|----|-----------|
305
+ |`index`|`Number`|The byte index to access|
306
+ |`bytes`|`Bytes`|The byte sequence to access|
307
+
308
+ Returns:
309
+
310
+ |type|description|
311
+ |----|-----------|
312
+ |`Int32`|A 32-bit integer representing a signed 8-bit integer that starts at the given index|
313
+
314
+ ### Bytes.**getInt8U**
315
+
316
+ <details disabled>
317
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
318
+ No other changes yet.
319
+ </details>
320
+
321
+ ```grain
322
+ getInt8U : (Number, Bytes) -> Int32
323
+ ```
324
+
325
+ Gets an unsigned 8-bit integer starting at the given byte index.
326
+
327
+ Parameters:
328
+
329
+ |param|type|description|
330
+ |-----|----|-----------|
331
+ |`index`|`Number`|The byte index to access|
332
+ |`bytes`|`Bytes`|The byte sequence to access|
333
+
334
+ Returns:
335
+
336
+ |type|description|
337
+ |----|-----------|
338
+ |`Int32`|A 32-bit integer representing an unsigned 8-bit integer that starts at the given index|
339
+
340
+ ### Bytes.**setInt8**
341
+
342
+ <details disabled>
343
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
344
+ No other changes yet.
345
+ </details>
346
+
347
+ ```grain
348
+ setInt8 : (Number, Int32, Bytes) -> Void
349
+ ```
350
+
351
+ Sets a signed 8-bit integer starting at the given byte index.
352
+
353
+ Parameters:
354
+
355
+ |param|type|description|
356
+ |-----|----|-----------|
357
+ |`index`|`Number`|The byte index to update|
358
+ |`value`|`Int32`|The value to set|
359
+ |`bytes`|`Bytes`|The byte sequence to mutate|
360
+
361
+ ### Bytes.**getInt16S**
362
+
363
+ <details disabled>
364
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
365
+ No other changes yet.
366
+ </details>
367
+
368
+ ```grain
369
+ getInt16S : (Number, Bytes) -> Int32
370
+ ```
371
+
372
+ Gets a signed 16-bit integer starting at the given byte index.
373
+
374
+ Parameters:
375
+
376
+ |param|type|description|
377
+ |-----|----|-----------|
378
+ |`index`|`Number`|The byte index to access|
379
+ |`bytes`|`Bytes`|The byte sequence to access|
380
+
381
+ Returns:
382
+
383
+ |type|description|
384
+ |----|-----------|
385
+ |`Int32`|A 32-bit integer representing a signed 16-bit integer that starts at the given index|
386
+
387
+ ### Bytes.**getInt16U**
388
+
389
+ <details disabled>
390
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
391
+ No other changes yet.
392
+ </details>
393
+
394
+ ```grain
395
+ getInt16U : (Number, Bytes) -> Int32
396
+ ```
397
+
398
+ Gets an unsigned 16-bit integer starting at the given byte index.
399
+
400
+ Parameters:
401
+
402
+ |param|type|description|
403
+ |-----|----|-----------|
404
+ |`index`|`Number`|The byte index to access|
405
+ |`bytes`|`Bytes`|The byte sequence to access|
406
+
407
+ Returns:
408
+
409
+ |type|description|
410
+ |----|-----------|
411
+ |`Int32`|A 32-bit integer representing an unsigned 16-bit integer that starts at the given index|
412
+
413
+ ### Bytes.**setInt16**
414
+
415
+ <details disabled>
416
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
417
+ No other changes yet.
418
+ </details>
419
+
420
+ ```grain
421
+ setInt16 : (Number, Int32, Bytes) -> Void
422
+ ```
423
+
424
+ Sets a signed 16-bit integer starting at the given byte index.
425
+
426
+ Parameters:
427
+
428
+ |param|type|description|
429
+ |-----|----|-----------|
430
+ |`index`|`Number`|The byte index to update|
431
+ |`value`|`Int32`|The value to set|
432
+ |`bytes`|`Bytes`|The byte sequence to mutate|
433
+
434
+ ### Bytes.**getInt32**
435
+
436
+ <details disabled>
437
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
438
+ No other changes yet.
439
+ </details>
440
+
441
+ ```grain
442
+ getInt32 : (Number, Bytes) -> Int32
443
+ ```
444
+
445
+ Gets a signed 32-bit integer starting at the given byte index.
446
+
447
+ Parameters:
448
+
449
+ |param|type|description|
450
+ |-----|----|-----------|
451
+ |`index`|`Number`|The byte index to access|
452
+ |`bytes`|`Bytes`|The byte sequence to access|
453
+
454
+ Returns:
455
+
456
+ |type|description|
457
+ |----|-----------|
458
+ |`Int32`|A signed 32-bit integer that starts at the given index|
459
+
460
+ ### Bytes.**setInt32**
461
+
462
+ <details disabled>
463
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
464
+ No other changes yet.
465
+ </details>
466
+
467
+ ```grain
468
+ setInt32 : (Number, Int32, Bytes) -> Void
469
+ ```
470
+
471
+ Sets a signed 32-bit integer starting at the given byte index.
472
+
473
+ Parameters:
474
+
475
+ |param|type|description|
476
+ |-----|----|-----------|
477
+ |`index`|`Number`|The byte index to update|
478
+ |`value`|`Int32`|The value to set|
479
+ |`bytes`|`Bytes`|The byte sequence to mutate|
480
+
481
+ ### Bytes.**getFloat32**
482
+
483
+ <details disabled>
484
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
485
+ No other changes yet.
486
+ </details>
487
+
488
+ ```grain
489
+ getFloat32 : (Number, Bytes) -> Float32
490
+ ```
491
+
492
+ Gets a 32-bit float starting at the given byte index.
493
+
494
+ Parameters:
495
+
496
+ |param|type|description|
497
+ |-----|----|-----------|
498
+ |`index`|`Number`|The byte index to access|
499
+ |`bytes`|`Bytes`|The byte sequence to access|
500
+
501
+ Returns:
502
+
503
+ |type|description|
504
+ |----|-----------|
505
+ |`Float32`|A 32-bit float that starts at the given index|
506
+
507
+ ### Bytes.**setFloat32**
508
+
509
+ <details disabled>
510
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
511
+ No other changes yet.
512
+ </details>
513
+
514
+ ```grain
515
+ setFloat32 : (Number, Float32, Bytes) -> Void
516
+ ```
517
+
518
+ Sets a 32-bit float starting at the given byte index.
519
+
520
+ Parameters:
521
+
522
+ |param|type|description|
523
+ |-----|----|-----------|
524
+ |`index`|`Number`|The byte index to update|
525
+ |`value`|`Float32`|The value to set|
526
+ |`bytes`|`Bytes`|The byte sequence to mutate|
527
+
528
+ ### Bytes.**getInt64**
529
+
530
+ <details disabled>
531
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
532
+ No other changes yet.
533
+ </details>
534
+
535
+ ```grain
536
+ getInt64 : (Number, Bytes) -> Int64
537
+ ```
538
+
539
+ Gets a signed 64-bit integer starting at the given byte index.
540
+
541
+ Parameters:
542
+
543
+ |param|type|description|
544
+ |-----|----|-----------|
545
+ |`index`|`Number`|The byte index to access|
546
+ |`bytes`|`Bytes`|The byte sequence to access|
547
+
548
+ Returns:
549
+
550
+ |type|description|
551
+ |----|-----------|
552
+ |`Int64`|A signed 64-bit integer that starts at the given index|
553
+
554
+ ### Bytes.**setInt64**
555
+
556
+ <details disabled>
557
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
558
+ No other changes yet.
559
+ </details>
560
+
561
+ ```grain
562
+ setInt64 : (Number, Int64, Bytes) -> Void
563
+ ```
564
+
565
+ Sets a signed 64-bit integer starting at the given byte index.
566
+
567
+ Parameters:
568
+
569
+ |param|type|description|
570
+ |-----|----|-----------|
571
+ |`index`|`Number`|The byte index to update|
572
+ |`value`|`Int64`|The value to set|
573
+ |`bytes`|`Bytes`|The byte sequence to mutate|
574
+
575
+ ### Bytes.**getFloat64**
576
+
577
+ <details disabled>
578
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
579
+ No other changes yet.
580
+ </details>
581
+
582
+ ```grain
583
+ getFloat64 : (Number, Bytes) -> Float64
584
+ ```
585
+
586
+ Gets a 64-bit float starting at the given byte index.
587
+
588
+ Parameters:
589
+
590
+ |param|type|description|
591
+ |-----|----|-----------|
592
+ |`index`|`Number`|The byte index to access|
593
+ |`bytes`|`Bytes`|The byte sequence to access|
594
+
595
+ Returns:
596
+
597
+ |type|description|
598
+ |----|-----------|
599
+ |`Float64`|A 64-bit float that starts at the given index|
600
+
601
+ ### Bytes.**setFloat64**
602
+
603
+ <details disabled>
604
+ <summary tabindex="-1">Added in <code>0.3.2</code></summary>
605
+ No other changes yet.
606
+ </details>
607
+
608
+ ```grain
609
+ setFloat64 : (Number, Float64, Bytes) -> Void
610
+ ```
611
+
612
+ Sets a 64-bit float starting at the given byte index.
613
+
614
+ Parameters:
615
+
616
+ |param|type|description|
617
+ |-----|----|-----------|
618
+ |`index`|`Number`|The byte index to update|
619
+ |`value`|`Float64`|The value to set|
620
+ |`bytes`|`Bytes`|The byte sequence to mutate|
621
+