@grain/stdlib 0.5.12 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +200 -0
- package/LICENSE +1 -1
- package/README.md +25 -2
- package/array.gr +1512 -199
- package/array.md +2032 -94
- package/bigint.gr +239 -140
- package/bigint.md +450 -106
- package/buffer.gr +595 -102
- package/buffer.md +903 -145
- package/bytes.gr +401 -110
- package/bytes.md +551 -63
- package/char.gr +228 -49
- package/char.md +373 -7
- package/exception.gr +26 -12
- package/exception.md +29 -5
- package/float32.gr +130 -109
- package/float32.md +185 -57
- package/float64.gr +112 -99
- package/float64.md +185 -57
- package/hash.gr +47 -37
- package/hash.md +21 -3
- package/int16.gr +430 -0
- package/int16.md +618 -0
- package/int32.gr +200 -269
- package/int32.md +254 -289
- package/int64.gr +142 -225
- package/int64.md +254 -289
- package/int8.gr +511 -0
- package/int8.md +786 -0
- package/json.gr +2084 -0
- package/json.md +608 -0
- package/list.gr +120 -68
- package/list.md +125 -80
- package/map.gr +560 -57
- package/map.md +672 -56
- package/marshal.gr +239 -227
- package/marshal.md +36 -4
- package/number.gr +626 -676
- package/number.md +738 -153
- package/option.gr +33 -35
- package/option.md +58 -42
- package/package.json +2 -2
- package/path.gr +148 -187
- package/path.md +47 -96
- package/pervasives.gr +75 -416
- package/pervasives.md +85 -180
- package/priorityqueue.gr +433 -74
- package/priorityqueue.md +422 -54
- package/queue.gr +362 -80
- package/queue.md +433 -38
- package/random.gr +67 -75
- package/random.md +68 -40
- package/range.gr +135 -63
- package/range.md +198 -43
- package/rational.gr +284 -0
- package/rational.md +545 -0
- package/regex.gr +933 -1066
- package/regex.md +59 -60
- package/result.gr +23 -25
- package/result.md +54 -39
- package/runtime/atof/common.gr +78 -82
- package/runtime/atof/common.md +22 -10
- package/runtime/atof/decimal.gr +102 -127
- package/runtime/atof/decimal.md +28 -7
- package/runtime/atof/lemire.gr +56 -71
- package/runtime/atof/lemire.md +9 -1
- package/runtime/atof/parse.gr +83 -110
- package/runtime/atof/parse.md +12 -2
- package/runtime/atof/slow.gr +28 -35
- package/runtime/atof/slow.md +9 -1
- package/runtime/atof/table.gr +19 -18
- package/runtime/atof/table.md +10 -2
- package/runtime/atoi/parse.gr +153 -136
- package/runtime/atoi/parse.md +50 -1
- package/runtime/bigint.gr +410 -517
- package/runtime/bigint.md +71 -57
- package/runtime/compare.gr +176 -85
- package/runtime/compare.md +31 -1
- package/runtime/dataStructures.gr +144 -32
- package/runtime/dataStructures.md +267 -31
- package/runtime/debugPrint.gr +34 -15
- package/runtime/debugPrint.md +37 -5
- package/runtime/equal.gr +53 -52
- package/runtime/equal.md +30 -1
- package/runtime/exception.gr +38 -47
- package/runtime/exception.md +10 -8
- package/runtime/gc.gr +23 -152
- package/runtime/gc.md +13 -17
- package/runtime/malloc.gr +31 -31
- package/runtime/malloc.md +11 -3
- package/runtime/numberUtils.gr +191 -172
- package/runtime/numberUtils.md +17 -9
- package/runtime/numbers.gr +1695 -1021
- package/runtime/numbers.md +1098 -134
- package/runtime/string.gr +540 -242
- package/runtime/string.md +76 -6
- package/runtime/unsafe/constants.gr +30 -13
- package/runtime/unsafe/constants.md +80 -0
- package/runtime/unsafe/conv.gr +55 -28
- package/runtime/unsafe/conv.md +41 -9
- package/runtime/unsafe/memory.gr +10 -30
- package/runtime/unsafe/memory.md +15 -19
- package/runtime/unsafe/tags.gr +37 -21
- package/runtime/unsafe/tags.md +88 -8
- package/runtime/unsafe/wasmf32.gr +30 -36
- package/runtime/unsafe/wasmf32.md +64 -56
- package/runtime/unsafe/wasmf64.gr +30 -36
- package/runtime/unsafe/wasmf64.md +64 -56
- package/runtime/unsafe/wasmi32.gr +49 -66
- package/runtime/unsafe/wasmi32.md +102 -94
- package/runtime/unsafe/wasmi64.gr +52 -79
- package/runtime/unsafe/wasmi64.md +108 -100
- package/runtime/utils/printing.gr +13 -15
- package/runtime/utils/printing.md +11 -3
- package/runtime/wasi.gr +294 -295
- package/runtime/wasi.md +62 -42
- package/set.gr +574 -64
- package/set.md +634 -54
- package/stack.gr +181 -64
- package/stack.md +271 -42
- package/string.gr +453 -533
- package/string.md +241 -151
- package/uint16.gr +369 -0
- package/uint16.md +585 -0
- package/uint32.gr +470 -0
- package/uint32.md +737 -0
- package/uint64.gr +471 -0
- package/uint64.md +737 -0
- package/uint8.gr +369 -0
- package/uint8.md +585 -0
- package/uri.gr +1093 -0
- package/uri.md +477 -0
- package/{sys → wasi}/file.gr +914 -500
- package/{sys → wasi}/file.md +454 -50
- package/wasi/process.gr +292 -0
- package/{sys → wasi}/process.md +164 -6
- package/wasi/random.gr +77 -0
- package/wasi/random.md +80 -0
- package/{sys → wasi}/time.gr +15 -22
- package/{sys → wasi}/time.md +5 -5
- package/immutablearray.gr +0 -929
- package/immutablearray.md +0 -1038
- package/immutablemap.gr +0 -493
- package/immutablemap.md +0 -479
- package/immutablepriorityqueue.gr +0 -360
- package/immutablepriorityqueue.md +0 -291
- package/immutableset.gr +0 -498
- package/immutableset.md +0 -449
- package/runtime/debug.gr +0 -2
- package/runtime/debug.md +0 -6
- package/runtime/unsafe/errors.gr +0 -36
- package/runtime/unsafe/errors.md +0 -204
- package/sys/process.gr +0 -254
- package/sys/random.gr +0 -79
- package/sys/random.md +0 -66
package/string.md
CHANGED
|
@@ -18,7 +18,7 @@ Utilities for working with strings.
|
|
|
18
18
|
</details>
|
|
19
19
|
|
|
20
20
|
```grain
|
|
21
|
-
|
|
21
|
+
from "string" include String
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
## Types
|
|
@@ -41,7 +41,7 @@ Byte encodings
|
|
|
41
41
|
|
|
42
42
|
## Values
|
|
43
43
|
|
|
44
|
-
Functions
|
|
44
|
+
Functions and constants included in the String module.
|
|
45
45
|
|
|
46
46
|
### String.**concat**
|
|
47
47
|
|
|
@@ -51,7 +51,7 @@ No other changes yet.
|
|
|
51
51
|
</details>
|
|
52
52
|
|
|
53
53
|
```grain
|
|
54
|
-
concat : (String, String)
|
|
54
|
+
concat : (str1: String, str2: String) => String
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
Concatenate two strings.
|
|
@@ -83,7 +83,7 @@ No other changes yet.
|
|
|
83
83
|
</details>
|
|
84
84
|
|
|
85
85
|
```grain
|
|
86
|
-
length : String
|
|
86
|
+
length : (string: String) => Number
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
Returns the character length of the input string.
|
|
@@ -114,7 +114,7 @@ No other changes yet.
|
|
|
114
114
|
</details>
|
|
115
115
|
|
|
116
116
|
```grain
|
|
117
|
-
byteLength : String
|
|
117
|
+
byteLength : (string: String) => Number
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
Returns the byte length of the input string.
|
|
@@ -137,6 +137,31 @@ Examples:
|
|
|
137
137
|
String.byteLength("🌾") == 4
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
+
### String.**isEmpty**
|
|
141
|
+
|
|
142
|
+
<details disabled>
|
|
143
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
144
|
+
No other changes yet.
|
|
145
|
+
</details>
|
|
146
|
+
|
|
147
|
+
```grain
|
|
148
|
+
isEmpty : (string: String) => Bool
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Determines if the string contains no characters.
|
|
152
|
+
|
|
153
|
+
Parameters:
|
|
154
|
+
|
|
155
|
+
|param|type|description|
|
|
156
|
+
|-----|----|-----------|
|
|
157
|
+
|`string`|`String`|The string to inspect|
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
|
|
161
|
+
|type|description|
|
|
162
|
+
|----|-----------|
|
|
163
|
+
|`Bool`|`true` if the string is empty and `false` otherwise|
|
|
164
|
+
|
|
140
165
|
### String.**indexOf**
|
|
141
166
|
|
|
142
167
|
<details disabled>
|
|
@@ -145,7 +170,7 @@ No other changes yet.
|
|
|
145
170
|
</details>
|
|
146
171
|
|
|
147
172
|
```grain
|
|
148
|
-
indexOf : (String, String)
|
|
173
|
+
indexOf : (search: String, string: String) => Option<Number>
|
|
149
174
|
```
|
|
150
175
|
|
|
151
176
|
Finds the first position of a substring in the input string.
|
|
@@ -177,7 +202,7 @@ No other changes yet.
|
|
|
177
202
|
</details>
|
|
178
203
|
|
|
179
204
|
```grain
|
|
180
|
-
lastIndexOf : (String, String)
|
|
205
|
+
lastIndexOf : (search: String, string: String) => Option<Number>
|
|
181
206
|
```
|
|
182
207
|
|
|
183
208
|
Finds the last position of a substring in the input string.
|
|
@@ -209,7 +234,7 @@ No other changes yet.
|
|
|
209
234
|
</details>
|
|
210
235
|
|
|
211
236
|
```grain
|
|
212
|
-
charCodeAt : (Number, String)
|
|
237
|
+
charCodeAt : (position: Number, string: String) => Number
|
|
213
238
|
```
|
|
214
239
|
|
|
215
240
|
Get the Unicode code point at the position in the input string.
|
|
@@ -227,6 +252,16 @@ Returns:
|
|
|
227
252
|
|----|-----------|
|
|
228
253
|
|`Number`|The character code at the provided position|
|
|
229
254
|
|
|
255
|
+
Throws:
|
|
256
|
+
|
|
257
|
+
`Failure(String)`
|
|
258
|
+
|
|
259
|
+
* When the `position` is out of bounds
|
|
260
|
+
|
|
261
|
+
`MalformedUnicode`
|
|
262
|
+
|
|
263
|
+
* When the `string` is malformed
|
|
264
|
+
|
|
230
265
|
Examples:
|
|
231
266
|
|
|
232
267
|
```grain
|
|
@@ -241,7 +276,7 @@ No other changes yet.
|
|
|
241
276
|
</details>
|
|
242
277
|
|
|
243
278
|
```grain
|
|
244
|
-
charAt : (Number, String)
|
|
279
|
+
charAt : (position: Number, string: String) => Char
|
|
245
280
|
```
|
|
246
281
|
|
|
247
282
|
Get the character at the position in the input string.
|
|
@@ -259,6 +294,16 @@ Returns:
|
|
|
259
294
|
|----|-----------|
|
|
260
295
|
|`Char`|The character at the provided position|
|
|
261
296
|
|
|
297
|
+
Throws:
|
|
298
|
+
|
|
299
|
+
`Failure(String)`
|
|
300
|
+
|
|
301
|
+
* When the `position` is out of bounds
|
|
302
|
+
|
|
303
|
+
`MalformedUnicode`
|
|
304
|
+
|
|
305
|
+
* When the `string` is malformed
|
|
306
|
+
|
|
262
307
|
Examples:
|
|
263
308
|
|
|
264
309
|
```grain
|
|
@@ -273,7 +318,7 @@ No other changes yet.
|
|
|
273
318
|
</details>
|
|
274
319
|
|
|
275
320
|
```grain
|
|
276
|
-
explode : String
|
|
321
|
+
explode : (string: String) => Array<Char>
|
|
277
322
|
```
|
|
278
323
|
|
|
279
324
|
Split a string into its Unicode characters.
|
|
@@ -290,6 +335,12 @@ Returns:
|
|
|
290
335
|
|----|-----------|
|
|
291
336
|
|`Array<Char>`|An array containing all characters in the string|
|
|
292
337
|
|
|
338
|
+
Throws:
|
|
339
|
+
|
|
340
|
+
`MalformedUnicode`
|
|
341
|
+
|
|
342
|
+
* When the `string` is malformed
|
|
343
|
+
|
|
293
344
|
Examples:
|
|
294
345
|
|
|
295
346
|
```grain
|
|
@@ -304,7 +355,7 @@ No other changes yet.
|
|
|
304
355
|
</details>
|
|
305
356
|
|
|
306
357
|
```grain
|
|
307
|
-
implode : Array<Char>
|
|
358
|
+
implode : (arr: Array<Char>) => String
|
|
308
359
|
```
|
|
309
360
|
|
|
310
361
|
Create a string from an array of characters.
|
|
@@ -335,7 +386,7 @@ No other changes yet.
|
|
|
335
386
|
</details>
|
|
336
387
|
|
|
337
388
|
```grain
|
|
338
|
-
reverse : String
|
|
389
|
+
reverse : (string: String) => String
|
|
339
390
|
```
|
|
340
391
|
|
|
341
392
|
Create a string that is the given string reversed.
|
|
@@ -361,7 +412,7 @@ String.reverse("olleH") == "Hello"
|
|
|
361
412
|
### String.**split**
|
|
362
413
|
|
|
363
414
|
```grain
|
|
364
|
-
split : (String, String)
|
|
415
|
+
split : (separator: String, string: String) => Array<String>
|
|
365
416
|
```
|
|
366
417
|
|
|
367
418
|
Split a string by the given separator.
|
|
@@ -379,6 +430,12 @@ Returns:
|
|
|
379
430
|
|----|-----------|
|
|
380
431
|
|`Array<String>`|An array of substrings from the initial string|
|
|
381
432
|
|
|
433
|
+
Throws:
|
|
434
|
+
|
|
435
|
+
`MalformedUnicode`
|
|
436
|
+
|
|
437
|
+
* When the `string` is malformed
|
|
438
|
+
|
|
382
439
|
Examples:
|
|
383
440
|
|
|
384
441
|
```grain
|
|
@@ -387,13 +444,20 @@ String.split(" ", "Hello world") == [> "Hello", "world"]
|
|
|
387
444
|
|
|
388
445
|
### String.**slice**
|
|
389
446
|
|
|
390
|
-
<details
|
|
391
|
-
<summary
|
|
392
|
-
|
|
447
|
+
<details>
|
|
448
|
+
<summary>Added in <code>0.1.0</code></summary>
|
|
449
|
+
<table>
|
|
450
|
+
<thead>
|
|
451
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
452
|
+
</thead>
|
|
453
|
+
<tbody>
|
|
454
|
+
<tr><td><code>0.6.0</code></td><td>Default `end` to the String length</td></tr>
|
|
455
|
+
</tbody>
|
|
456
|
+
</table>
|
|
393
457
|
</details>
|
|
394
458
|
|
|
395
459
|
```grain
|
|
396
|
-
slice : (Number, Number, String)
|
|
460
|
+
slice : (start: Number, ?end: Number, string: String) => String
|
|
397
461
|
```
|
|
398
462
|
|
|
399
463
|
Get a portion of a string.
|
|
@@ -403,7 +467,7 @@ Parameters:
|
|
|
403
467
|
|param|type|description|
|
|
404
468
|
|-----|----|-----------|
|
|
405
469
|
|`start`|`Number`|The start position of the substring|
|
|
406
|
-
|
|
470
|
+
|`?end`|`Number`|The end position of the substring, exclusive|
|
|
407
471
|
|`string`|`String`|The input string|
|
|
408
472
|
|
|
409
473
|
Returns:
|
|
@@ -412,10 +476,27 @@ Returns:
|
|
|
412
476
|
|----|-----------|
|
|
413
477
|
|`String`|The substring from the initial string|
|
|
414
478
|
|
|
479
|
+
Throws:
|
|
480
|
+
|
|
481
|
+
`IndexOutOfBounds`
|
|
482
|
+
|
|
483
|
+
* When `start` is out of bounds
|
|
484
|
+
* When `end` is out of bounds
|
|
485
|
+
|
|
486
|
+
`InvalidArgument(String)`
|
|
487
|
+
|
|
488
|
+
* When the `start` index is not an integer
|
|
489
|
+
* When the `to` index is not an integer
|
|
490
|
+
* When `start` is greater than `end`
|
|
491
|
+
|
|
415
492
|
Examples:
|
|
416
493
|
|
|
417
494
|
```grain
|
|
418
|
-
String.slice(0, 5, "Hello world") == "Hello"
|
|
495
|
+
String.slice(0, end=5, "Hello world") == "Hello"
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
```grain
|
|
499
|
+
String.slice(0, "Hello world") == "Hello world"
|
|
419
500
|
```
|
|
420
501
|
|
|
421
502
|
### String.**contains**
|
|
@@ -426,7 +507,7 @@ No other changes yet.
|
|
|
426
507
|
</details>
|
|
427
508
|
|
|
428
509
|
```grain
|
|
429
|
-
contains : (String, String)
|
|
510
|
+
contains : (search: String, string: String) => Bool
|
|
430
511
|
```
|
|
431
512
|
|
|
432
513
|
Check if a string contains a substring.
|
|
@@ -458,7 +539,7 @@ No other changes yet.
|
|
|
458
539
|
</details>
|
|
459
540
|
|
|
460
541
|
```grain
|
|
461
|
-
startsWith : (String, String)
|
|
542
|
+
startsWith : (search: String, string: String) => Bool
|
|
462
543
|
```
|
|
463
544
|
|
|
464
545
|
Check if a string begins with another string.
|
|
@@ -490,7 +571,7 @@ No other changes yet.
|
|
|
490
571
|
</details>
|
|
491
572
|
|
|
492
573
|
```grain
|
|
493
|
-
endsWith : (String, String)
|
|
574
|
+
endsWith : (search: String, string: String) => Bool
|
|
494
575
|
```
|
|
495
576
|
|
|
496
577
|
Check if a string ends with another string.
|
|
@@ -522,7 +603,8 @@ No other changes yet.
|
|
|
522
603
|
</details>
|
|
523
604
|
|
|
524
605
|
```grain
|
|
525
|
-
replaceFirst :
|
|
606
|
+
replaceFirst :
|
|
607
|
+
(searchPattern: String, replacement: String, string: String) => String
|
|
526
608
|
```
|
|
527
609
|
|
|
528
610
|
Replaces the first appearance of the search pattern in the string with the replacement value.
|
|
@@ -555,7 +637,8 @@ No other changes yet.
|
|
|
555
637
|
</details>
|
|
556
638
|
|
|
557
639
|
```grain
|
|
558
|
-
replaceLast :
|
|
640
|
+
replaceLast :
|
|
641
|
+
(searchPattern: String, replacement: String, string: String) => String
|
|
559
642
|
```
|
|
560
643
|
|
|
561
644
|
Replaces the last appearance of the search pattern in the string with the replacement value.
|
|
@@ -588,7 +671,8 @@ No other changes yet.
|
|
|
588
671
|
</details>
|
|
589
672
|
|
|
590
673
|
```grain
|
|
591
|
-
replaceAll :
|
|
674
|
+
replaceAll :
|
|
675
|
+
(searchPattern: String, replacement: String, string: String) => String
|
|
592
676
|
```
|
|
593
677
|
|
|
594
678
|
Replaces every appearance of the search pattern in the string with the replacement value.
|
|
@@ -615,16 +699,25 @@ String.replaceAll("🌾", "🌎", "Hello 🌾🌾") == "Hello 🌎🌎"
|
|
|
615
699
|
|
|
616
700
|
### String.**encodeAt**
|
|
617
701
|
|
|
618
|
-
<details
|
|
619
|
-
<summary
|
|
620
|
-
|
|
702
|
+
<details>
|
|
703
|
+
<summary>Added in <code>0.4.0</code></summary>
|
|
704
|
+
<table>
|
|
705
|
+
<thead>
|
|
706
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
707
|
+
</thead>
|
|
708
|
+
<tbody>
|
|
709
|
+
<tr><td><code>0.6.0</code></td><td>Added `includeBom` default argument</td></tr>
|
|
710
|
+
</tbody>
|
|
711
|
+
</table>
|
|
621
712
|
</details>
|
|
622
713
|
|
|
623
714
|
```grain
|
|
624
|
-
encodeAt :
|
|
715
|
+
encodeAt :
|
|
716
|
+
(string: String, encoding: Encoding, dest: Bytes, destPos: Number,
|
|
717
|
+
?includeBom: Bool) => Bytes
|
|
625
718
|
```
|
|
626
719
|
|
|
627
|
-
Encodes the given string into a byte sequence at the supplied position
|
|
720
|
+
Encodes the given string into a byte sequence at the supplied position using the encoding scheme provided.
|
|
628
721
|
|
|
629
722
|
Parameters:
|
|
630
723
|
|
|
@@ -634,6 +727,7 @@ Parameters:
|
|
|
634
727
|
|`encoding`|`Encoding`|The encoding to use|
|
|
635
728
|
|`dest`|`Bytes`|The byte sequence that will be copied|
|
|
636
729
|
|`destPos`|`Number`|The location in the byte sequence to write the output|
|
|
730
|
+
|`?includeBom`|`Bool`|Whether or not to include a byte order marker (false by default)|
|
|
637
731
|
|
|
638
732
|
Returns:
|
|
639
733
|
|
|
@@ -641,72 +735,32 @@ Returns:
|
|
|
641
735
|
|----|-----------|
|
|
642
736
|
|`Bytes`|A copy of the input bytes with the encoded string replaced at the given position|
|
|
643
737
|
|
|
644
|
-
|
|
738
|
+
Throws:
|
|
645
739
|
|
|
646
|
-
|
|
647
|
-
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
648
|
-
No other changes yet.
|
|
649
|
-
</details>
|
|
650
|
-
|
|
651
|
-
```grain
|
|
652
|
-
encodeAtWithBom : (String, Encoding, Bytes, Number) -> Bytes
|
|
653
|
-
```
|
|
740
|
+
`InvalidArgument(String)`
|
|
654
741
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
Parameters:
|
|
658
|
-
|
|
659
|
-
|param|type|description|
|
|
660
|
-
|-----|----|-----------|
|
|
661
|
-
|`string`|`String`|The input string|
|
|
662
|
-
|`encoding`|`Encoding`|The encoding to use|
|
|
663
|
-
|`dest`|`Bytes`|The byte sequence that will be copied|
|
|
664
|
-
|`destPos`|`Number`|The location in the byte sequence to write the output|
|
|
665
|
-
|
|
666
|
-
Returns:
|
|
667
|
-
|
|
668
|
-
|type|description|
|
|
669
|
-
|----|-----------|
|
|
670
|
-
|`Bytes`|A copy of the input bytes with the encoded string replaced at the given position|
|
|
742
|
+
* When `destPos` is not an integer
|
|
743
|
+
* When `destPos` is negative
|
|
671
744
|
|
|
672
745
|
### String.**encode**
|
|
673
746
|
|
|
674
|
-
<details
|
|
675
|
-
<summary
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
Parameters:
|
|
686
|
-
|
|
687
|
-
|param|type|description|
|
|
688
|
-
|-----|----|-----------|
|
|
689
|
-
|`string`|`String`|The input string|
|
|
690
|
-
|`encoding`|`Encoding`|The encoding to use|
|
|
691
|
-
|
|
692
|
-
Returns:
|
|
693
|
-
|
|
694
|
-
|type|description|
|
|
695
|
-
|----|-----------|
|
|
696
|
-
|`Bytes`|The byte representation of the string in the given encoding|
|
|
697
|
-
|
|
698
|
-
### String.**encodeWithBom**
|
|
699
|
-
|
|
700
|
-
<details disabled>
|
|
701
|
-
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
702
|
-
No other changes yet.
|
|
747
|
+
<details>
|
|
748
|
+
<summary>Added in <code>0.4.0</code></summary>
|
|
749
|
+
<table>
|
|
750
|
+
<thead>
|
|
751
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
752
|
+
</thead>
|
|
753
|
+
<tbody>
|
|
754
|
+
<tr><td><code>0.6.0</code></td><td>Added `includeBom` default argument</td></tr>
|
|
755
|
+
</tbody>
|
|
756
|
+
</table>
|
|
703
757
|
</details>
|
|
704
758
|
|
|
705
759
|
```grain
|
|
706
|
-
|
|
760
|
+
encode : (string: String, encoding: Encoding, ?includeBom: Bool) => Bytes
|
|
707
761
|
```
|
|
708
762
|
|
|
709
|
-
Encodes the given string using the given encoding scheme
|
|
763
|
+
Encodes the given string using the given encoding scheme.
|
|
710
764
|
|
|
711
765
|
Parameters:
|
|
712
766
|
|
|
@@ -714,6 +768,7 @@ Parameters:
|
|
|
714
768
|
|-----|----|-----------|
|
|
715
769
|
|`string`|`String`|The input string|
|
|
716
770
|
|`encoding`|`Encoding`|The encoding to use|
|
|
771
|
+
|`?includeBom`|`Bool`|Whether or not to include a byte order marker (false by default)|
|
|
717
772
|
|
|
718
773
|
Returns:
|
|
719
774
|
|
|
@@ -723,16 +778,25 @@ Returns:
|
|
|
723
778
|
|
|
724
779
|
### String.**decodeRange**
|
|
725
780
|
|
|
726
|
-
<details
|
|
727
|
-
<summary
|
|
728
|
-
|
|
781
|
+
<details>
|
|
782
|
+
<summary>Added in <code>0.4.0</code></summary>
|
|
783
|
+
<table>
|
|
784
|
+
<thead>
|
|
785
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
786
|
+
</thead>
|
|
787
|
+
<tbody>
|
|
788
|
+
<tr><td><code>0.6.0</code></td><td>Added `keepBom` default argument</td></tr>
|
|
789
|
+
</tbody>
|
|
790
|
+
</table>
|
|
729
791
|
</details>
|
|
730
792
|
|
|
731
793
|
```grain
|
|
732
|
-
decodeRange :
|
|
794
|
+
decodeRange :
|
|
795
|
+
(bytes: Bytes, encoding: Encoding, start: Number, size: Number,
|
|
796
|
+
?keepBom: Bool) => String
|
|
733
797
|
```
|
|
734
798
|
|
|
735
|
-
Decodes the given byte sequence of the specified range into a string
|
|
799
|
+
Decodes the given byte sequence of the specified range into a string using the encoding scheme provided.
|
|
736
800
|
|
|
737
801
|
Parameters:
|
|
738
802
|
|
|
@@ -742,6 +806,7 @@ Parameters:
|
|
|
742
806
|
|`encoding`|`Encoding`|The encoding to use|
|
|
743
807
|
|`start`|`Number`|The byte offset to begin decoding from|
|
|
744
808
|
|`size`|`Number`|The maximum number of bytes to decode|
|
|
809
|
+
|`?keepBom`|`Bool`|Whether or not to include a byte order marker (false by default)|
|
|
745
810
|
|
|
746
811
|
Returns:
|
|
747
812
|
|
|
@@ -749,18 +814,34 @@ Returns:
|
|
|
749
814
|
|----|-----------|
|
|
750
815
|
|`String`|The decoded string|
|
|
751
816
|
|
|
752
|
-
|
|
817
|
+
Throws:
|
|
753
818
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
819
|
+
`InvalidArgument(String)`
|
|
820
|
+
|
|
821
|
+
* When `start` is not an integer
|
|
822
|
+
* When `start` is negative
|
|
823
|
+
* When `size` is not an integer
|
|
824
|
+
* When `size` is negative
|
|
825
|
+
|
|
826
|
+
### String.**decode**
|
|
827
|
+
|
|
828
|
+
<details>
|
|
829
|
+
<summary>Added in <code>0.4.0</code></summary>
|
|
830
|
+
<table>
|
|
831
|
+
<thead>
|
|
832
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
833
|
+
</thead>
|
|
834
|
+
<tbody>
|
|
835
|
+
<tr><td><code>0.6.0</code></td><td>Added `keepBom` default argument</td></tr>
|
|
836
|
+
</tbody>
|
|
837
|
+
</table>
|
|
757
838
|
</details>
|
|
758
839
|
|
|
759
840
|
```grain
|
|
760
|
-
|
|
841
|
+
decode : (bytes: Bytes, encoding: Encoding, ?keepBom: Bool) => String
|
|
761
842
|
```
|
|
762
843
|
|
|
763
|
-
Decodes the given byte sequence
|
|
844
|
+
Decodes the given byte sequence into a string using the given encoding scheme.
|
|
764
845
|
|
|
765
846
|
Parameters:
|
|
766
847
|
|
|
@@ -768,8 +849,7 @@ Parameters:
|
|
|
768
849
|
|-----|----|-----------|
|
|
769
850
|
|`bytes`|`Bytes`|The input bytes|
|
|
770
851
|
|`encoding`|`Encoding`|The encoding to use|
|
|
771
|
-
|
|
772
|
-
|`size`|`Number`|The maximum number of bytes to decode|
|
|
852
|
+
|`?keepBom`|`Bool`|Whether or not to include a byte order marker (false by default)|
|
|
773
853
|
|
|
774
854
|
Returns:
|
|
775
855
|
|
|
@@ -777,7 +857,7 @@ Returns:
|
|
|
777
857
|
|----|-----------|
|
|
778
858
|
|`String`|The decoded string|
|
|
779
859
|
|
|
780
|
-
### String.**
|
|
860
|
+
### String.**forEachCodePoint**
|
|
781
861
|
|
|
782
862
|
<details disabled>
|
|
783
863
|
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
@@ -785,25 +865,25 @@ No other changes yet.
|
|
|
785
865
|
</details>
|
|
786
866
|
|
|
787
867
|
```grain
|
|
788
|
-
|
|
868
|
+
forEachCodePoint : (fn: (Number => Void), str: String) => Void
|
|
789
869
|
```
|
|
790
870
|
|
|
791
|
-
|
|
871
|
+
Iterates over Unicode code points in a string.
|
|
792
872
|
|
|
793
873
|
Parameters:
|
|
794
874
|
|
|
795
875
|
|param|type|description|
|
|
796
876
|
|-----|----|-----------|
|
|
797
|
-
|`
|
|
798
|
-
|`
|
|
877
|
+
|`fn`|`Number => Void`|The iterator function|
|
|
878
|
+
|`str`|`String`|The string to iterate|
|
|
799
879
|
|
|
800
|
-
|
|
880
|
+
Examples:
|
|
801
881
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
882
|
+
```grain
|
|
883
|
+
String.forEachCodePoint(print, "Hello world")
|
|
884
|
+
```
|
|
805
885
|
|
|
806
|
-
### String.**
|
|
886
|
+
### String.**forEachCodePointi**
|
|
807
887
|
|
|
808
888
|
<details disabled>
|
|
809
889
|
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
@@ -811,79 +891,89 @@ No other changes yet.
|
|
|
811
891
|
</details>
|
|
812
892
|
|
|
813
893
|
```grain
|
|
814
|
-
|
|
894
|
+
forEachCodePointi : (fn: ((Number, Number) => Void), str: String) => Void
|
|
815
895
|
```
|
|
816
896
|
|
|
817
|
-
|
|
897
|
+
Iterates over Unicode code points in a string. This is the same as
|
|
898
|
+
`forEachCodePoint`, but provides the code point's index in the string
|
|
899
|
+
as the second argument to the iterator function.
|
|
818
900
|
|
|
819
901
|
Parameters:
|
|
820
902
|
|
|
821
903
|
|param|type|description|
|
|
822
904
|
|-----|----|-----------|
|
|
823
|
-
|`
|
|
824
|
-
|`
|
|
905
|
+
|`fn`|`(Number, Number) => Void`|The iterator function|
|
|
906
|
+
|`str`|`String`|The string to iterate|
|
|
825
907
|
|
|
826
|
-
|
|
908
|
+
Examples:
|
|
827
909
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
910
|
+
```grain
|
|
911
|
+
String.forEachCodePointi((codepoint, index) => print((codepoint, index)), "Hello world")
|
|
912
|
+
```
|
|
831
913
|
|
|
832
|
-
### String.**
|
|
914
|
+
### String.**trimStart**
|
|
833
915
|
|
|
834
916
|
<details disabled>
|
|
835
|
-
<summary tabindex="-1">Added in <code>0.4.
|
|
917
|
+
<summary tabindex="-1">Added in <code>0.4.2</code></summary>
|
|
836
918
|
No other changes yet.
|
|
837
919
|
</details>
|
|
838
920
|
|
|
839
921
|
```grain
|
|
840
|
-
|
|
922
|
+
trimStart : (string: String) => String
|
|
841
923
|
```
|
|
842
924
|
|
|
843
|
-
|
|
925
|
+
Trims the beginning of a string—removing any leading whitespace characters.
|
|
844
926
|
|
|
845
927
|
Parameters:
|
|
846
928
|
|
|
847
929
|
|param|type|description|
|
|
848
930
|
|-----|----|-----------|
|
|
849
|
-
|`
|
|
850
|
-
|
|
931
|
+
|`string`|`String`|The string to be trimmed|
|
|
932
|
+
|
|
933
|
+
Returns:
|
|
934
|
+
|
|
935
|
+
|type|description|
|
|
936
|
+
|----|-----------|
|
|
937
|
+
|`String`|The trimmed string|
|
|
851
938
|
|
|
852
939
|
Examples:
|
|
853
940
|
|
|
854
941
|
```grain
|
|
855
|
-
String.
|
|
942
|
+
String.trimStart(" Hello World") == "Hello World"
|
|
856
943
|
```
|
|
857
944
|
|
|
858
|
-
### String.**
|
|
945
|
+
### String.**trimEnd**
|
|
859
946
|
|
|
860
947
|
<details disabled>
|
|
861
|
-
<summary tabindex="-1">Added in <code>0.4.
|
|
948
|
+
<summary tabindex="-1">Added in <code>0.4.2</code></summary>
|
|
862
949
|
No other changes yet.
|
|
863
950
|
</details>
|
|
864
951
|
|
|
865
952
|
```grain
|
|
866
|
-
|
|
953
|
+
trimEnd : (string: String) => String
|
|
867
954
|
```
|
|
868
955
|
|
|
869
|
-
|
|
870
|
-
`forEachCodePoint`, but provides the code point's index in the string
|
|
871
|
-
as the second argument to the iterator function.
|
|
956
|
+
Trims the end of a string—removing any trailing whitespace characters.
|
|
872
957
|
|
|
873
958
|
Parameters:
|
|
874
959
|
|
|
875
960
|
|param|type|description|
|
|
876
961
|
|-----|----|-----------|
|
|
877
|
-
|`
|
|
878
|
-
|
|
962
|
+
|`string`|`String`|The string to be trimmed|
|
|
963
|
+
|
|
964
|
+
Returns:
|
|
965
|
+
|
|
966
|
+
|type|description|
|
|
967
|
+
|----|-----------|
|
|
968
|
+
|`String`|The trimmed string|
|
|
879
969
|
|
|
880
970
|
Examples:
|
|
881
971
|
|
|
882
972
|
```grain
|
|
883
|
-
String.
|
|
973
|
+
String.trimEnd("Hello World ") == "Hello World"
|
|
884
974
|
```
|
|
885
975
|
|
|
886
|
-
### String.**
|
|
976
|
+
### String.**trim**
|
|
887
977
|
|
|
888
978
|
<details disabled>
|
|
889
979
|
<summary tabindex="-1">Added in <code>0.4.2</code></summary>
|
|
@@ -891,10 +981,10 @@ No other changes yet.
|
|
|
891
981
|
</details>
|
|
892
982
|
|
|
893
983
|
```grain
|
|
894
|
-
|
|
984
|
+
trim : (string: String) => String
|
|
895
985
|
```
|
|
896
986
|
|
|
897
|
-
Trims
|
|
987
|
+
Trims a string—removing all leading and trailing whitespace characters.
|
|
898
988
|
|
|
899
989
|
Parameters:
|
|
900
990
|
|
|
@@ -911,68 +1001,68 @@ Returns:
|
|
|
911
1001
|
Examples:
|
|
912
1002
|
|
|
913
1003
|
```grain
|
|
914
|
-
String.
|
|
1004
|
+
String.trim(" Hello World ") == "Hello World"
|
|
915
1005
|
```
|
|
916
1006
|
|
|
917
|
-
### String.**
|
|
1007
|
+
### String.**toAsciiLowercase**
|
|
918
1008
|
|
|
919
1009
|
<details disabled>
|
|
920
|
-
<summary tabindex="-1">Added in <code>0.
|
|
1010
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
921
1011
|
No other changes yet.
|
|
922
1012
|
</details>
|
|
923
1013
|
|
|
924
1014
|
```grain
|
|
925
|
-
|
|
1015
|
+
toAsciiLowercase : (string: String) => String
|
|
926
1016
|
```
|
|
927
1017
|
|
|
928
|
-
|
|
1018
|
+
Converts all ASCII uppercase characters in the string to lowercase.
|
|
929
1019
|
|
|
930
1020
|
Parameters:
|
|
931
1021
|
|
|
932
1022
|
|param|type|description|
|
|
933
1023
|
|-----|----|-----------|
|
|
934
|
-
|`string`|`String`|The string to
|
|
1024
|
+
|`string`|`String`|The string to convert|
|
|
935
1025
|
|
|
936
1026
|
Returns:
|
|
937
1027
|
|
|
938
1028
|
|type|description|
|
|
939
1029
|
|----|-----------|
|
|
940
|
-
|`String`|The
|
|
1030
|
+
|`String`|The lowercased string|
|
|
941
1031
|
|
|
942
1032
|
Examples:
|
|
943
1033
|
|
|
944
1034
|
```grain
|
|
945
|
-
String.
|
|
1035
|
+
assert String.toAsciiLowercase("aBc123") == "abc123"
|
|
946
1036
|
```
|
|
947
1037
|
|
|
948
|
-
### String.**
|
|
1038
|
+
### String.**toAsciiUppercase**
|
|
949
1039
|
|
|
950
1040
|
<details disabled>
|
|
951
|
-
<summary tabindex="-1">Added in <code>0.
|
|
1041
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
952
1042
|
No other changes yet.
|
|
953
1043
|
</details>
|
|
954
1044
|
|
|
955
1045
|
```grain
|
|
956
|
-
|
|
1046
|
+
toAsciiUppercase : (string: String) => String
|
|
957
1047
|
```
|
|
958
1048
|
|
|
959
|
-
|
|
1049
|
+
Converts all ASCII lowercase characters in the string to uppercase.
|
|
960
1050
|
|
|
961
1051
|
Parameters:
|
|
962
1052
|
|
|
963
1053
|
|param|type|description|
|
|
964
1054
|
|-----|----|-----------|
|
|
965
|
-
|`string`|`String`|The string to
|
|
1055
|
+
|`string`|`String`|The string to convert|
|
|
966
1056
|
|
|
967
1057
|
Returns:
|
|
968
1058
|
|
|
969
1059
|
|type|description|
|
|
970
1060
|
|----|-----------|
|
|
971
|
-
|`String`|The
|
|
1061
|
+
|`String`|The uppercased string|
|
|
972
1062
|
|
|
973
1063
|
Examples:
|
|
974
1064
|
|
|
975
1065
|
```grain
|
|
976
|
-
String.
|
|
1066
|
+
assert String.toAsciiUppercase("aBc123") == "ABC123"
|
|
977
1067
|
```
|
|
978
1068
|
|