@grain/stdlib 0.5.4 → 0.5.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.
- package/CHANGELOG.md +23 -0
- package/array.gr +60 -57
- package/array.md +24 -6
- package/buffer.gr +71 -1
- package/buffer.md +142 -0
- package/bytes.gr +52 -3
- package/bytes.md +117 -0
- package/char.gr +21 -18
- package/char.md +18 -3
- package/immutablepriorityqueue.gr +13 -13
- package/int32.gr +39 -37
- package/int32.md +6 -0
- package/int64.gr +39 -37
- package/int64.md +6 -0
- package/list.gr +31 -22
- package/list.md +39 -10
- package/map.gr +19 -28
- package/number.gr +81 -5
- package/number.md +64 -2
- package/option.gr +30 -26
- package/option.md +12 -0
- package/package.json +1 -1
- package/path.gr +787 -0
- package/path.md +727 -0
- package/pervasives.gr +3 -4
- package/pervasives.md +6 -1
- package/queue.gr +11 -9
- package/queue.md +2 -0
- package/regex.gr +76 -3
- package/regex.md +70 -0
- package/result.gr +24 -20
- package/result.md +12 -0
- package/runtime/atof/common.gr +198 -0
- package/runtime/atof/common.md +243 -0
- package/runtime/atof/decimal.gr +663 -0
- package/runtime/atof/decimal.md +59 -0
- package/runtime/atof/lemire.gr +264 -0
- package/runtime/atof/lemire.md +6 -0
- package/runtime/atof/parse.gr +615 -0
- package/runtime/atof/parse.md +12 -0
- package/runtime/atof/slow.gr +238 -0
- package/runtime/atof/slow.md +6 -0
- package/runtime/atof/table.gr +2016 -0
- package/runtime/atof/table.md +12 -0
- package/runtime/{stringUtils.gr → atoi/parse.gr} +1 -1
- package/runtime/{stringUtils.md → atoi/parse.md} +1 -1
- package/runtime/bigint.gr +3 -3
- package/runtime/equal.gr +1 -1
- package/runtime/numberUtils.gr +2 -2
- package/runtime/numberUtils.md +6 -0
- package/runtime/numbers.gr +4 -4
- package/runtime/unsafe/conv.gr +21 -41
- package/runtime/unsafe/conv.md +0 -3
- package/runtime/unsafe/printWasm.gr +4 -40
- package/runtime/utils/printing.gr +3 -3
- package/stack.gr +4 -2
- package/stack.md +2 -0
- package/string.gr +1 -1
- package/sys/time.gr +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
### [0.5.5](https://github.com/grain-lang/grain/compare/stdlib-v0.5.4...stdlib-v0.5.5) (2022-12-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **graindoc:** Add attribute for exceptions that may be thrown ([#1492](https://github.com/grain-lang/grain/issues/1492)) ([b2e75c7](https://github.com/grain-lang/grain/commit/b2e75c7452ef2544c768729c7a45e21ff31616d0))
|
|
9
|
+
* **graindoc:** Support deprecations on module docblocks ([#1498](https://github.com/grain-lang/grain/issues/1498)) ([b3dc85c](https://github.com/grain-lang/grain/commit/b3dc85c0fc311479de4e57774a075c3a922216ba))
|
|
10
|
+
* **stdlib:** Add `parse` function to Number module ([#1517](https://github.com/grain-lang/grain/issues/1517)) ([59e89d1](https://github.com/grain-lang/grain/commit/59e89d12b7fcf2626c8adb45c742a787171b7024))
|
|
11
|
+
* **stdlib:** Add `parseFloat` function to Number module ([#1288](https://github.com/grain-lang/grain/issues/1288)) ([e21f2b1](https://github.com/grain-lang/grain/commit/e21f2b137f7dcd67cccf9debf695db852dc2afc5))
|
|
12
|
+
* **stdlib:** Add `split` function to Regex module ([#1469](https://github.com/grain-lang/grain/issues/1469)) ([0c1eb73](https://github.com/grain-lang/grain/commit/0c1eb73d01e30f457138c6e3b603a9faddcf8e9b))
|
|
13
|
+
* **stdlib:** Add `splitAll` function to Regex module ([0c1eb73](https://github.com/grain-lang/grain/commit/0c1eb73d01e30f457138c6e3b603a9faddcf8e9b))
|
|
14
|
+
* **stdlib:** Add Path module for working with system paths ([#1452](https://github.com/grain-lang/grain/issues/1452)) ([900e976](https://github.com/grain-lang/grain/commit/900e976654565b3618e2215e9b7cefbda873d9a8))
|
|
15
|
+
* **stdlib:** Improve performance in Array & List modules ([#1487](https://github.com/grain-lang/grain/issues/1487)) ([2168f6a](https://github.com/grain-lang/grain/commit/2168f6ade151548bc655debeb8a1bc09ce87cb77))
|
|
16
|
+
* **stdlib:** Improve performance of `flatMap`, `some`, and `every` functions in Array module ([2168f6a](https://github.com/grain-lang/grain/commit/2168f6ade151548bc655debeb8a1bc09ce87cb77))
|
|
17
|
+
* **stdlib:** Improve performance of `some` and `every` functions in List module ([2168f6a](https://github.com/grain-lang/grain/commit/2168f6ade151548bc655debeb8a1bc09ce87cb77))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **grainfmt:** Add parentheses around some binops for precedence clarity ([#1514](https://github.com/grain-lang/grain/issues/1514)) ([3ac27cc](https://github.com/grain-lang/grain/commit/3ac27cc6e17b896dae0ef2cb5f5de510c7c2dd60))
|
|
23
|
+
* **grainfmt:** Handle multiple line items and comments better ([#1460](https://github.com/grain-lang/grain/issues/1460)) ([5395fd4](https://github.com/grain-lang/grain/commit/5395fd45b79fb3bcf3dd1ec52a1d5973a23a4bdc))
|
|
24
|
+
* **runtime:** Properly divide bigints in the number type ([59e89d1](https://github.com/grain-lang/grain/commit/59e89d12b7fcf2626c8adb45c742a787171b7024))
|
|
25
|
+
|
|
3
26
|
### [0.5.4](https://github.com/grain-lang/grain/compare/stdlib-v0.5.3...stdlib-v0.5.4) (2022-11-12)
|
|
4
27
|
|
|
5
28
|
|
package/array.gr
CHANGED
|
@@ -12,34 +12,27 @@ import WasmI32 from "runtime/unsafe/wasmi32"
|
|
|
12
12
|
import Memory from "runtime/unsafe/memory"
|
|
13
13
|
import { allocateArray, tagSimpleNumber } from "runtime/dataStructures"
|
|
14
14
|
import Exception from "runtime/exception"
|
|
15
|
+
import { coerceNumberToWasmI32 } from "runtime/numbers"
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* @section Values: Functions for working with the Array data type.
|
|
18
19
|
*/
|
|
19
20
|
|
|
20
|
-
@
|
|
21
|
-
let mut _ARRAY_LENGTH_OFFSET =
|
|
22
|
-
@
|
|
23
|
-
let mut _ARRAY_START_OFFSET =
|
|
21
|
+
@unsafe
|
|
22
|
+
let mut _ARRAY_LENGTH_OFFSET = 4n
|
|
23
|
+
@unsafe
|
|
24
|
+
let mut _ARRAY_START_OFFSET = 8n
|
|
24
25
|
|
|
25
|
-
@
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
initPtr()
|
|
31
|
-
|
|
32
|
-
@disableGC
|
|
33
|
-
let initLength = length => {
|
|
34
|
-
let length = WasmI32.fromGrain(length)
|
|
35
|
-
if (WasmI32.eqz(WasmI32.and(length, 1n))) {
|
|
26
|
+
@unsafe
|
|
27
|
+
let checkLength = length => {
|
|
28
|
+
let ptr = WasmI32.fromGrain(length)
|
|
29
|
+
if (WasmI32.eqz(WasmI32.and(ptr, 1n))) {
|
|
36
30
|
throw Exception.InvalidArgument("Length argument must be an integer")
|
|
37
31
|
}
|
|
38
|
-
let
|
|
39
|
-
if (WasmI32.ltS(
|
|
32
|
+
let len = WasmI32.shrS(ptr, 1n)
|
|
33
|
+
if (WasmI32.ltS(len, 0n)) {
|
|
40
34
|
throw Exception.InvalidArgument("Length argument must be non-negative")
|
|
41
35
|
}
|
|
42
|
-
length
|
|
43
36
|
}
|
|
44
37
|
|
|
45
38
|
/**
|
|
@@ -51,16 +44,12 @@ let initLength = length => {
|
|
|
51
44
|
* @example Array.length([> 1, 2, 3, 4, 5]) == 5
|
|
52
45
|
* @since v0.1.0
|
|
53
46
|
*/
|
|
54
|
-
@
|
|
55
|
-
export let
|
|
47
|
+
@unsafe
|
|
48
|
+
export let length = array => {
|
|
56
49
|
let ptr = WasmI32.fromGrain(array: Array<a>)
|
|
57
|
-
|
|
58
|
-
Memory.decRef(ptr)
|
|
59
|
-
Memory.decRef(WasmI32.fromGrain(length))
|
|
60
|
-
ret
|
|
50
|
+
tagSimpleNumber(WasmI32.load(ptr, _ARRAY_LENGTH_OFFSET))
|
|
61
51
|
}
|
|
62
52
|
|
|
63
|
-
// [FIXME] (#793) Type annotation breaks compiler
|
|
64
53
|
/**
|
|
65
54
|
* Creates a new array of the specified length with each element being
|
|
66
55
|
* initialized with the given value.
|
|
@@ -69,18 +58,18 @@ export let rec length = array => {
|
|
|
69
58
|
* @param item: The value to store at each index
|
|
70
59
|
* @returns The new array
|
|
71
60
|
*
|
|
61
|
+
* @throws InvalidArgument(String): When `length` is not an integer
|
|
62
|
+
* @throws InvalidArgument(String): When `length` is negative
|
|
63
|
+
*
|
|
72
64
|
* @example Array.make(5, "foo") // [> "foo", "foo", "foo", "foo", "foo"]
|
|
73
65
|
*
|
|
74
66
|
* @since v0.1.0
|
|
75
67
|
*/
|
|
76
|
-
@
|
|
77
|
-
export let
|
|
78
|
-
(
|
|
79
|
-
length: Number,
|
|
80
|
-
item: a,
|
|
81
|
-
) => {
|
|
68
|
+
@unsafe
|
|
69
|
+
export let make: (Number, a) -> Array<a> = (length: Number, item: a) => {
|
|
82
70
|
let lengthArg = length
|
|
83
|
-
|
|
71
|
+
checkLength(length)
|
|
72
|
+
let length = coerceNumberToWasmI32(length)
|
|
84
73
|
let byteLength = WasmI32.mul(length, 4n)
|
|
85
74
|
let array = allocateArray(length)
|
|
86
75
|
for (let mut i = 0n; WasmI32.ltS(i, byteLength); i = WasmI32.add(i, 4n)) {
|
|
@@ -90,11 +79,7 @@ export let rec make /*: (Number, a) -> Array<a>*/ =
|
|
|
90
79
|
_ARRAY_START_OFFSET
|
|
91
80
|
)
|
|
92
81
|
}
|
|
93
|
-
|
|
94
|
-
Memory.decRef(WasmI32.fromGrain(lengthArg))
|
|
95
|
-
Memory.decRef(WasmI32.fromGrain(item))
|
|
96
|
-
Memory.decRef(WasmI32.fromGrain(make))
|
|
97
|
-
ret
|
|
82
|
+
WasmI32.toGrain(array): Array<a>
|
|
98
83
|
}
|
|
99
84
|
|
|
100
85
|
/**
|
|
@@ -106,34 +91,34 @@ export let rec make /*: (Number, a) -> Array<a>*/ =
|
|
|
106
91
|
* @param fn: The initializer function to call with each index, where the value returned will be used to initialize the element
|
|
107
92
|
* @returns The new array
|
|
108
93
|
*
|
|
94
|
+
* @throws InvalidArgument(String): When `length` is not an integer
|
|
95
|
+
* @throws InvalidArgument(String): When `length` is negative
|
|
96
|
+
*
|
|
109
97
|
* @example Array.init(5, n => n + 3) // [> 3, 4, 5, 6, 7]
|
|
110
98
|
*
|
|
111
99
|
* @since v0.1.0
|
|
112
100
|
*/
|
|
113
|
-
@
|
|
114
|
-
export let
|
|
101
|
+
@unsafe
|
|
102
|
+
export let init: (Number, Number -> a) -> Array<a> =
|
|
115
103
|
(
|
|
116
104
|
length: Number,
|
|
117
105
|
fn: Number -> a,
|
|
118
106
|
) => {
|
|
119
|
-
|
|
107
|
+
checkLength(length)
|
|
108
|
+
let length = coerceNumberToWasmI32(length)
|
|
120
109
|
let byteLength = WasmI32.mul(length, 4n)
|
|
121
110
|
let array = allocateArray(length)
|
|
122
111
|
let mut index = 0n
|
|
123
112
|
for (let mut i = 0n; WasmI32.ltS(i, byteLength); i = WasmI32.add(i, 4n)) {
|
|
124
|
-
Memory.incRef(WasmI32.fromGrain(fn))
|
|
125
113
|
// [FIXME] This line fails the array/map test suite (#815)
|
|
126
|
-
//assert !WasmI32.eqz(WasmI32.and(WasmI32.fromGrain(index), 1n)) // must be a simple int for next line to be correct
|
|
114
|
+
// assert !WasmI32.eqz(WasmI32.and(WasmI32.fromGrain(index), 1n)) // must be a simple int for next line to be correct
|
|
127
115
|
WasmI32.store(
|
|
128
116
|
WasmI32.add(array, i),
|
|
129
|
-
WasmI32.fromGrain(fn(tagSimpleNumber(index))),
|
|
117
|
+
Memory.incRef(WasmI32.fromGrain(fn(tagSimpleNumber(index)))),
|
|
130
118
|
_ARRAY_START_OFFSET
|
|
131
119
|
)
|
|
132
|
-
//WasmI32.store(WasmI32.add(array, i), WasmI32.fromGrain(4), _ARRAY_START_OFFSET)
|
|
133
120
|
index = WasmI32.add(index, 1n)
|
|
134
121
|
}
|
|
135
|
-
Memory.decRef(WasmI32.fromGrain(fn))
|
|
136
|
-
Memory.decRef(WasmI32.fromGrain(init))
|
|
137
122
|
WasmI32.toGrain(array): Array<a>
|
|
138
123
|
}
|
|
139
124
|
|
|
@@ -425,7 +410,19 @@ export let reducei = (fn, initial, array) => {
|
|
|
425
410
|
* @since v0.3.0
|
|
426
411
|
*/
|
|
427
412
|
export let flatMap = (fn, array) => {
|
|
428
|
-
|
|
413
|
+
let nested = map(fn, array)
|
|
414
|
+
let arrLen = reduce((acc, arr) => acc + length(arr), 0, nested)
|
|
415
|
+
let mut outerI = 0
|
|
416
|
+
let mut innerI = 0
|
|
417
|
+
init(arrLen, i => {
|
|
418
|
+
if (innerI >= length(nested[outerI])) {
|
|
419
|
+
innerI = 0
|
|
420
|
+
outerI += 1
|
|
421
|
+
}
|
|
422
|
+
let res = nested[outerI][innerI]
|
|
423
|
+
innerI += 1
|
|
424
|
+
res
|
|
425
|
+
})
|
|
429
426
|
}
|
|
430
427
|
|
|
431
428
|
/**
|
|
@@ -439,9 +436,12 @@ export let flatMap = (fn, array) => {
|
|
|
439
436
|
* @since v0.3.0
|
|
440
437
|
*/
|
|
441
438
|
export let every = (fn, array) => {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
439
|
+
let len = length(array)
|
|
440
|
+
let mut all = true
|
|
441
|
+
for (let mut index = 0; all && index < len; index += 1) {
|
|
442
|
+
all = fn(array[index])
|
|
443
|
+
}
|
|
444
|
+
all
|
|
445
445
|
}
|
|
446
446
|
|
|
447
447
|
/**
|
|
@@ -455,9 +455,12 @@ export let every = (fn, array) => {
|
|
|
455
455
|
* @since v0.3.0
|
|
456
456
|
*/
|
|
457
457
|
export let some = (fn, array) => {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
458
|
+
let len = length(array)
|
|
459
|
+
let mut found = false
|
|
460
|
+
for (let mut index = 0; !found && index < len; index += 1) {
|
|
461
|
+
found = fn(array[index])
|
|
462
|
+
}
|
|
463
|
+
found
|
|
461
464
|
}
|
|
462
465
|
|
|
463
466
|
/**
|
|
@@ -799,12 +802,12 @@ export let unique = array => {
|
|
|
799
802
|
* The first tuple will contain the first item of each array, the second tuple
|
|
800
803
|
* will contain the second item of each array, and so on.
|
|
801
804
|
*
|
|
802
|
-
* Calling this function with arrays of different sizes will throw an error.
|
|
803
|
-
*
|
|
804
805
|
* @param array1: The array to provide values for the first tuple element
|
|
805
806
|
* @param array2: The array to provide values for the second tuple element
|
|
806
807
|
* @returns The new array containing indexed pairs of `(a, b)`
|
|
807
808
|
*
|
|
809
|
+
* @throws Failure(String): When the arrays have different sizes
|
|
810
|
+
*
|
|
808
811
|
* @since v0.4.0
|
|
809
812
|
*/
|
|
810
813
|
export let zip = (array1: Array<a>, array2: Array<b>) => {
|
|
@@ -824,7 +827,7 @@ export let zip = (array1: Array<a>, array2: Array<b>) => {
|
|
|
824
827
|
* applying the function to the first elements of each array, the second element
|
|
825
828
|
* will contain the result of applying the function to the second elements of
|
|
826
829
|
* each array, and so on.
|
|
827
|
-
*
|
|
830
|
+
*
|
|
828
831
|
* Calling this function with arrays of different sizes will cause the returned
|
|
829
832
|
* array to have the length of the smaller array.
|
|
830
833
|
*
|
|
@@ -835,7 +838,7 @@ export let zip = (array1: Array<a>, array2: Array<b>) => {
|
|
|
835
838
|
*
|
|
836
839
|
* @example Array.zipWith((a, b) => a + b, [> 1, 2, 3], [> 4, 5, 6]) // [> 5, 7, 9]
|
|
837
840
|
* @example Array.zipWith((a, b) => a * b, [> 1, 2, 3], [> 4, 5]) // [> 4, 10]
|
|
838
|
-
*
|
|
841
|
+
*
|
|
839
842
|
* @since v0.5.3
|
|
840
843
|
*/
|
|
841
844
|
export let zipWith = (fn, array1: Array<a>, array2: Array<b>) => {
|
package/array.md
CHANGED
|
@@ -83,6 +83,13 @@ Returns:
|
|
|
83
83
|
|----|-----------|
|
|
84
84
|
|`Array<a>`|The new array|
|
|
85
85
|
|
|
86
|
+
Throws:
|
|
87
|
+
|
|
88
|
+
`InvalidArgument(String)`
|
|
89
|
+
|
|
90
|
+
* When `length` is not an integer
|
|
91
|
+
* When `length` is negative
|
|
92
|
+
|
|
86
93
|
Examples:
|
|
87
94
|
|
|
88
95
|
```grain
|
|
@@ -117,6 +124,13 @@ Returns:
|
|
|
117
124
|
|----|-----------|
|
|
118
125
|
|`Array<a>`|The new array|
|
|
119
126
|
|
|
127
|
+
Throws:
|
|
128
|
+
|
|
129
|
+
`InvalidArgument(String)`
|
|
130
|
+
|
|
131
|
+
* When `length` is not an integer
|
|
132
|
+
* When `length` is negative
|
|
133
|
+
|
|
120
134
|
Examples:
|
|
121
135
|
|
|
122
136
|
```grain
|
|
@@ -550,7 +564,7 @@ No other changes yet.
|
|
|
550
564
|
</details>
|
|
551
565
|
|
|
552
566
|
```grain
|
|
553
|
-
flatMap : ((
|
|
567
|
+
flatMap : ((b -> Array<a>), Array<b>) -> Array<a>
|
|
554
568
|
```
|
|
555
569
|
|
|
556
570
|
Produces a new array by calling a function on each element
|
|
@@ -562,14 +576,14 @@ Parameters:
|
|
|
562
576
|
|
|
563
577
|
|param|type|description|
|
|
564
578
|
|-----|----|-----------|
|
|
565
|
-
|`fn`|`
|
|
566
|
-
|`array`|`Array<
|
|
579
|
+
|`fn`|`b -> Array<a>`|The function to be called on each element, where the value returned will be an array that gets appended to the new array|
|
|
580
|
+
|`array`|`Array<b>`|The array to iterate|
|
|
567
581
|
|
|
568
582
|
Returns:
|
|
569
583
|
|
|
570
584
|
|type|description|
|
|
571
585
|
|----|-----------|
|
|
572
|
-
|`Array<
|
|
586
|
+
|`Array<a>`|The new array|
|
|
573
587
|
|
|
574
588
|
### Array.**every**
|
|
575
589
|
|
|
@@ -999,8 +1013,6 @@ Produces a new array filled with tuples of elements from both given arrays.
|
|
|
999
1013
|
The first tuple will contain the first item of each array, the second tuple
|
|
1000
1014
|
will contain the second item of each array, and so on.
|
|
1001
1015
|
|
|
1002
|
-
Calling this function with arrays of different sizes will throw an error.
|
|
1003
|
-
|
|
1004
1016
|
Parameters:
|
|
1005
1017
|
|
|
1006
1018
|
|param|type|description|
|
|
@@ -1014,6 +1026,12 @@ Returns:
|
|
|
1014
1026
|
|----|-----------|
|
|
1015
1027
|
|`Array<(a, b)>`|The new array containing indexed pairs of `(a, b)`|
|
|
1016
1028
|
|
|
1029
|
+
Throws:
|
|
1030
|
+
|
|
1031
|
+
`Failure(String)`
|
|
1032
|
+
|
|
1033
|
+
* When the arrays have different sizes
|
|
1034
|
+
|
|
1017
1035
|
### Array.**zipWith**
|
|
1018
1036
|
|
|
1019
1037
|
<details disabled>
|
package/buffer.gr
CHANGED
|
@@ -66,7 +66,7 @@ let autogrow = (len, buf) => {
|
|
|
66
66
|
|
|
67
67
|
/* Memcopies bytes from a source byte sequence to a destination byte sequence via pointers */
|
|
68
68
|
@unsafe
|
|
69
|
-
let
|
|
69
|
+
let appendBytes = (srcOff, dstOff, len, src, dst) => {
|
|
70
70
|
let (+) = WasmI32.add
|
|
71
71
|
Memory.copy(dst + _VALUE_OFFSET + dstOff, src + _VALUE_OFFSET + srcOff, len)
|
|
72
72
|
}
|
|
@@ -114,6 +114,8 @@ let addInt32help = (value, buffer) => {
|
|
|
114
114
|
* @param initialSize: The initial size of the buffer
|
|
115
115
|
* @returns The new buffer
|
|
116
116
|
*
|
|
117
|
+
* @throws InvalidArgument(String): When the `initialSize` is a negative number
|
|
118
|
+
*
|
|
117
119
|
* @since v0.4.0
|
|
118
120
|
*/
|
|
119
121
|
export let make = initialSize => {
|
|
@@ -168,6 +170,9 @@ export let reset = buffer => {
|
|
|
168
170
|
* @param length: The number of bytes to truncate the buffer to
|
|
169
171
|
* @param buffer: The buffer to truncate
|
|
170
172
|
*
|
|
173
|
+
* @throws IndexOutOfBounds: When the `length` is negative
|
|
174
|
+
* @throws IndexOutOfBounds: When the `length` is greater than the buffer size
|
|
175
|
+
*
|
|
171
176
|
* @since v0.4.0
|
|
172
177
|
*/
|
|
173
178
|
@unsafe
|
|
@@ -202,6 +207,10 @@ export let toBytes = buffer => {
|
|
|
202
207
|
* @param buffer: The buffer to copy from
|
|
203
208
|
* @returns A byte sequence with bytes copied from the buffer
|
|
204
209
|
*
|
|
210
|
+
* @throws IndexOutOfBounds: When `start` is negative
|
|
211
|
+
* @throws IndexOutOfBounds: When `start` is greater than or equal to the buffer size
|
|
212
|
+
* @throws IndexOutOfBounds: When `start + length` is greater than the buffer size
|
|
213
|
+
*
|
|
205
214
|
* @since v0.4.0
|
|
206
215
|
*/
|
|
207
216
|
export let toBytesSlice = (start, length, buffer) => {
|
|
@@ -329,6 +338,11 @@ export let addStringSlice = (start: Number, end, string, buffer) => {
|
|
|
329
338
|
* @param bytes: The byte sequence to append
|
|
330
339
|
* @param buffer: The buffer to mutate
|
|
331
340
|
*
|
|
341
|
+
* @throws IndexOutOfBounds: When the `start` is negative
|
|
342
|
+
* @throws IndexOutOfBounds: When the `start` is greater than or equal to the `bytes` size
|
|
343
|
+
* @throws IndexOutOfBounds: When the `length` is negative
|
|
344
|
+
* @throws IndexOutOfBounds: When the `length` is greater than the `bytes` length minus `start`
|
|
345
|
+
*
|
|
332
346
|
* @since v0.4.0
|
|
333
347
|
*/
|
|
334
348
|
@unsafe
|
|
@@ -410,6 +424,10 @@ export let addBufferSlice = (start, length, srcBuffer, dstBuffer) => {
|
|
|
410
424
|
* @param buffer: The buffer to access
|
|
411
425
|
* @returns A 32-bit integer representing a signed 8-bit integer that starts at the given index
|
|
412
426
|
*
|
|
427
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
428
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
429
|
+
* @throws IndexOutOfBounds: When `index + 1` is greater than the buffer size
|
|
430
|
+
*
|
|
413
431
|
* @since v0.4.0
|
|
414
432
|
*/
|
|
415
433
|
export let getInt8S = (index, buffer) => {
|
|
@@ -424,6 +442,10 @@ export let getInt8S = (index, buffer) => {
|
|
|
424
442
|
* @param buffer: The buffer to access
|
|
425
443
|
* @returns A 32-bit integer representing an unsigned 8-bit integer that starts at the given index
|
|
426
444
|
*
|
|
445
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
446
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
447
|
+
* @throws IndexOutOfBounds: When `index + 1` is greater than the buffer size
|
|
448
|
+
*
|
|
427
449
|
* @since v0.4.0
|
|
428
450
|
*/
|
|
429
451
|
export let getInt8U = (index, buffer) => {
|
|
@@ -438,6 +460,10 @@ export let getInt8U = (index, buffer) => {
|
|
|
438
460
|
* @param value: The value to set
|
|
439
461
|
* @param buffer: The buffer to mutate
|
|
440
462
|
*
|
|
463
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
464
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
465
|
+
* @throws IndexOutOfBounds: When `index + 1` is greater than the buffer size
|
|
466
|
+
*
|
|
441
467
|
* @since v0.4.0
|
|
442
468
|
*/
|
|
443
469
|
export let setInt8 = (index, value, buffer) => {
|
|
@@ -464,6 +490,10 @@ export let addInt8 = (value, buffer) => {
|
|
|
464
490
|
* @param buffer: The buffer to access
|
|
465
491
|
* @returns A 32-bit integer representing a signed 16-bit integer that starts at the given index
|
|
466
492
|
*
|
|
493
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
494
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
495
|
+
* @throws IndexOutOfBounds: When `index + 2` is greater than the buffer size
|
|
496
|
+
*
|
|
467
497
|
* @since v0.4.0
|
|
468
498
|
*/
|
|
469
499
|
export let getInt16S = (index, buffer) => {
|
|
@@ -478,6 +508,10 @@ export let getInt16S = (index, buffer) => {
|
|
|
478
508
|
* @param buffer: The buffer to access
|
|
479
509
|
* @returns A 32-bit integer representing an unsigned 16-bit integer that starts at the given index
|
|
480
510
|
*
|
|
511
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
512
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
513
|
+
* @throws IndexOutOfBounds: When `index + 2` is greater than the buffer size
|
|
514
|
+
*
|
|
481
515
|
* @since v0.4.0
|
|
482
516
|
*/
|
|
483
517
|
export let getInt16U = (index, buffer) => {
|
|
@@ -492,6 +526,10 @@ export let getInt16U = (index, buffer) => {
|
|
|
492
526
|
* @param value: The value to set
|
|
493
527
|
* @param buffer: The buffer to mutate
|
|
494
528
|
*
|
|
529
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
530
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
531
|
+
* @throws IndexOutOfBounds: When `index + 2` is greater than the buffer size
|
|
532
|
+
*
|
|
495
533
|
* @since v0.4.0
|
|
496
534
|
*/
|
|
497
535
|
export let setInt16 = (index, value, buffer) => {
|
|
@@ -518,6 +556,10 @@ export let addInt16 = (value, buffer) => {
|
|
|
518
556
|
* @param buffer: The buffer to access
|
|
519
557
|
* @returns A signed 32-bit integer that starts at the given index
|
|
520
558
|
*
|
|
559
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
560
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
561
|
+
* @throws IndexOutOfBounds: When `index + 4` is greater than the buffer size
|
|
562
|
+
*
|
|
521
563
|
* @since v0.4.0
|
|
522
564
|
*/
|
|
523
565
|
export let getInt32 = (index, buffer) => {
|
|
@@ -532,6 +574,10 @@ export let getInt32 = (index, buffer) => {
|
|
|
532
574
|
* @param value: The value to set
|
|
533
575
|
* @param buffer: The buffer to mutate
|
|
534
576
|
*
|
|
577
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
578
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
579
|
+
* @throws IndexOutOfBounds: When `index + 4` is greater than the buffer size
|
|
580
|
+
*
|
|
535
581
|
* @since v0.4.0
|
|
536
582
|
*/
|
|
537
583
|
export let setInt32 = (index, value, buffer) => {
|
|
@@ -558,6 +604,10 @@ export let addInt32 = (value, buffer) => {
|
|
|
558
604
|
* @param buffer: The buffer to access
|
|
559
605
|
* @returns A 32-bit float that starts at the given index
|
|
560
606
|
*
|
|
607
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
608
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
609
|
+
* @throws IndexOutOfBounds: When `index + 4` is greater than the buffer size
|
|
610
|
+
*
|
|
561
611
|
* @since v0.4.0
|
|
562
612
|
*/
|
|
563
613
|
export let getFloat32 = (index, buffer) => {
|
|
@@ -572,6 +622,10 @@ export let getFloat32 = (index, buffer) => {
|
|
|
572
622
|
* @param value: The value to set
|
|
573
623
|
* @param buffer: The buffer to mutate
|
|
574
624
|
*
|
|
625
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
626
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
627
|
+
* @throws IndexOutOfBounds: When `index + 4` is greater than the buffer size
|
|
628
|
+
*
|
|
575
629
|
* @since v0.4.0
|
|
576
630
|
*/
|
|
577
631
|
export let setFloat32 = (index, value, buffer) => {
|
|
@@ -601,6 +655,10 @@ export let addFloat32 = (value, buffer) => {
|
|
|
601
655
|
* @param buffer: The buffer to access
|
|
602
656
|
* @returns A signed 64-bit integer that starts at the given index
|
|
603
657
|
*
|
|
658
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
659
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
660
|
+
* @throws IndexOutOfBounds: When `index + 8` is greater than the buffer size
|
|
661
|
+
*
|
|
604
662
|
* @since v0.4.0
|
|
605
663
|
*/
|
|
606
664
|
export let getInt64 = (index, buffer) => {
|
|
@@ -615,6 +673,10 @@ export let getInt64 = (index, buffer) => {
|
|
|
615
673
|
* @param value: The value to set
|
|
616
674
|
* @param buffer: The buffer to mutate
|
|
617
675
|
*
|
|
676
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
677
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
678
|
+
* @throws IndexOutOfBounds: When `index + 8` is greater than the buffer size
|
|
679
|
+
*
|
|
618
680
|
* @since v0.4.0
|
|
619
681
|
*/
|
|
620
682
|
export let setInt64 = (index, value, buffer) => {
|
|
@@ -644,6 +706,10 @@ export let addInt64 = (value, buffer) => {
|
|
|
644
706
|
* @param buffer: The buffer to access
|
|
645
707
|
* @returns A 64-bit float that starts at the given index
|
|
646
708
|
*
|
|
709
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
710
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
711
|
+
* @throws IndexOutOfBounds: When `index + 8` is greater than the buffer size
|
|
712
|
+
*
|
|
647
713
|
* @since v0.4.0
|
|
648
714
|
*/
|
|
649
715
|
export let getFloat64 = (index, buffer) => {
|
|
@@ -658,6 +724,10 @@ export let getFloat64 = (index, buffer) => {
|
|
|
658
724
|
* @param value: The value to set
|
|
659
725
|
* @param buffer: The buffer to mutate
|
|
660
726
|
*
|
|
727
|
+
* @throws IndexOutOfBounds: When `index` is negative
|
|
728
|
+
* @throws IndexOutOfBounds: When `index` is greater than or equal to the buffer size
|
|
729
|
+
* @throws IndexOutOfBounds: When `index + 8` is greater than the buffer size
|
|
730
|
+
*
|
|
661
731
|
* @since v0.4.0
|
|
662
732
|
*/
|
|
663
733
|
export let setFloat64 = (index, value, buffer) => {
|