@@ -6,67 +6,77 @@ bytes module is made to provide helpers to manipulation of bytes slice.
6
6
7
7
All the following functions are exposed in ` mod.ts ` .
8
8
9
- ## findIndex
9
+ ## indexOf
10
10
11
- Find first index of binary pattern from given binary array.
11
+ Find first index of binary pattern from given binary array, or -1 if it is not
12
+ present.
12
13
13
14
``` typescript
14
- import { findIndex } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
15
+ import { indexOf } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
15
16
16
- findIndex (
17
+ indexOf (
17
18
new Uint8Array ([1 , 2 , 0 , 1 , 2 , 0 , 1 , 2 , 0 , 1 , 3 ]),
18
19
new Uint8Array ([0 , 1 , 2 ]),
19
- );
20
+ ); // => returns 2
20
21
21
- // => returns 2
22
+ indexOf (
23
+ new Uint8Array ([1 , 2 , 0 , 1 , 2 , 0 , 1 , 2 , 0 , 1 , 3 ]),
24
+ new Uint8Array ([0 , 1 , 2 ]),
25
+ 3 ,
26
+ ); // => returns 5
22
27
```
23
28
24
- ## findLastIndex
29
+ ## lastIndexOf
25
30
26
- Find last index of binary pattern from given binary array.
31
+ Find last index of binary pattern from given binary array, or -1 if it is not
32
+ present.
27
33
28
34
``` typescript
29
- import { findLastIndex } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
35
+ import { lastIndexOf } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
30
36
31
- findLastIndex (
32
- new Uint8Array ([0 , 1 , 2 , 0 , 1 , 2 , 0 , 1 , 3 ]),
37
+ lastIndexOf (
38
+ new Uint8Array ([0 , 1 , 2 , 3 , 3 , 0 , 1 , 2 ]),
33
39
new Uint8Array ([0 , 1 , 2 ]),
34
- );
40
+ ); // => returns 5
35
41
36
- // => returns 3
42
+ lastIndexOf (
43
+ new Uint8Array ([0 , 1 , 2 , 3 , 3 , 0 , 1 , 2 ]),
44
+ new Uint8Array ([0 , 1 , 2 ]),
45
+ 3 ,
46
+ ); // => returns 0
37
47
```
38
48
39
- ## equal
49
+ ## equals
40
50
41
51
Check whether given binary arrays are equal to each other.
42
52
43
53
``` typescript
44
- import { equal } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
54
+ import { equals } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
45
55
46
- equal (new Uint8Array ([0 , 1 , 2 , 3 ]), new Uint8Array ([0 , 1 , 2 , 3 ])); // returns true
47
- equal (new Uint8Array ([0 , 1 , 2 , 3 ]), new Uint8Array ([0 , 1 , 2 , 4 ])); // returns false
56
+ equals (new Uint8Array ([0 , 1 , 2 , 3 ]), new Uint8Array ([0 , 1 , 2 , 3 ])); // returns true
57
+ equals (new Uint8Array ([0 , 1 , 2 , 3 ]), new Uint8Array ([0 , 1 , 2 , 4 ])); // returns false
48
58
```
49
59
50
- ## hasPrefix
60
+ ## startsWith
51
61
52
- Check whether binary array has binary prefix.
62
+ Check whether binary array starts with prefix.
53
63
54
64
``` typescript
55
- import { hasPrefix } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
65
+ import { startsWith } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
56
66
57
- hasPrefix (new Uint8Array ([0 , 1 , 2 ]), new Uint8Array ([0 , 1 ])); // returns true
58
- hasPrefix (new Uint8Array ([0 , 1 , 2 ]), new Uint8Array ([1 , 2 ])); // returns false
67
+ startsWith (new Uint8Array ([0 , 1 , 2 ]), new Uint8Array ([0 , 1 ])); // returns true
68
+ startsWith (new Uint8Array ([0 , 1 , 2 ]), new Uint8Array ([1 , 2 ])); // returns false
59
69
```
60
70
61
- ## hasSuffix
71
+ ## endsWith
62
72
63
73
Check whether binary array ends with suffix.
64
74
65
75
``` typescript
66
- import { hasSuffix } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
76
+ import { endsWith } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
67
77
68
- hasSuffix (new Uint8Array ([0 , 1 , 2 ]), new Uint8Array ([0 , 1 ])); // returns false
69
- hasSuffix (new Uint8Array ([0 , 1 , 2 ]), new Uint8Array ([1 , 2 ])); // returns true
78
+ endsWith (new Uint8Array ([0 , 1 , 2 ]), new Uint8Array ([0 , 1 ])); // returns false
79
+ endsWith (new Uint8Array ([0 , 1 , 2 ]), new Uint8Array ([1 , 2 ])); // returns true
70
80
```
71
81
72
82
## repeat
@@ -81,12 +91,19 @@ repeat(new Uint8Array([1]), 3); // returns Uint8Array(3) [ 1, 1, 1 ]
81
91
82
92
## concat
83
93
84
- Concatenate two binary arrays and return new one.
94
+ Concatenate multiple binary arrays and return new one.
85
95
86
96
``` typescript
87
97
import { concat } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
88
98
89
99
concat (new Uint8Array ([1 , 2 ]), new Uint8Array ([3 , 4 ])); // returns Uint8Array(4) [ 1, 2, 3, 4 ]
100
+
101
+ concat (
102
+ new Uint8Array ([1 , 2 ]),
103
+ new Uint8Array ([3 , 4 ]),
104
+ new Uint8Array ([5 , 6 ]),
105
+ new Uint8Array ([7 , 8 ]),
106
+ ); // => returns Uint8Array(8) [ 1, 2, 3, 4, 5, 6, 7, 8 ]
90
107
```
91
108
92
109
## contains
@@ -107,14 +124,14 @@ contains(
107
124
); // => returns false
108
125
```
109
126
110
- ## copyBytes
127
+ ## copy
111
128
112
129
Copy bytes from one binary array to another.
113
130
114
131
``` typescript
115
- import { copyBytes } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
132
+ import { copy } from " https://deno.land/std@$STD_VERSION/bytes/mod.ts" ;
116
133
117
134
const dst = new Uint8Array (4 );
118
135
const src = Uint8Array .of (1 , 2 , 3 , 4 );
119
- const len = copyBytes (src , dest ); // returns len = 4
136
+ const len = copy (src , dest ); // returns len = 4
120
137
```
0 commit comments