deno.land / std@0.224.0 / bytes / mod.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.
/** * Helper functions for working with * {@linkcode https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array | Uint8Array} * byte slices. * * ## Concatenate byte slices * * {@linkcode concat} concatenates an array of byte slices into a single slice. * * ```ts * import { concat } from "https://deno.land/std@$STD_VERSION/bytes/concat.ts"; * * const a = new Uint8Array([0, 1, 2]); * const b = new Uint8Array([3, 4, 5]); * concat([a, b]); // Uint8Array(6) [ 0, 1, 2, 3, 4, 5 ] * ``` * * ## Copy byte slices * * {@linkcode copy} copies bytes from the `src` array to the `dst` array and * returns the number of bytes copied. * * ```ts * import { copy } from "https://deno.land/std@$STD_VERSION/bytes/copy.ts"; * * const src = new Uint8Array([9, 8, 7]); * const dst = new Uint8Array([0, 1, 2, 3, 4, 5]); * * copy(src, dst); // 3 * dst; // Uint8Array(6) [9, 8, 7, 3, 4, 5] * ``` * * ## Check if a byte slice ends with another byte slice * * {@linkcode endsWith} returns `true` if the suffix array appears at the end of * the source array, `false` otherwise. * * ```ts * import { endsWith } from "https://deno.land/std@$STD_VERSION/bytes/ends_with.ts"; * * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]); * const suffix = new Uint8Array([1, 2, 3]); * * endsWith(source, suffix); // true * ``` * * ## Check if two byte slices are equal * * {@linkcode equals} checks whether byte slices are equal to each other. * * ```ts * import { equals } from "https://deno.land/std@$STD_VERSION/bytes/equals.ts"; * * const a = new Uint8Array([1, 2, 3]); * const b = new Uint8Array([1, 2, 3]); * const c = new Uint8Array([4, 5, 6]); * * equals(a, b); // true * equals(b, c); // false * ``` * * ## Check if a byte slice includes another byte slice * * {@linkcode includesNeedle} determines whether the source array contains the * needle array. * * ```ts * import { includesNeedle } from "https://deno.land/std@$STD_VERSION/bytes/includes_needle.ts"; * * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]); * const needle = new Uint8Array([1, 2]); * * includesNeedle(source, needle); // true * ``` * * ## Find the index of a byte slice in another byte slice * * {@linkcode indexOfNeedle} returns the index of the first occurrence of the * needle array in the source array, or -1 if it is not present. * * ```ts * import { indexOfNeedle } from "https://deno.land/std@$STD_VERSION/bytes/index_of_needle.ts"; * * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]); * const needle = new Uint8Array([1, 2]); * const notNeedle = new Uint8Array([5, 0]); * * indexOfNeedle(source, needle); // 1 * indexOfNeedle(source, notNeedle); // -1 * ``` * * ## Find the last index of a byte slice in another byte slice * * {@linkcode lastIndexOfNeedle} returns the index of the last occurrence of the * needle array in the source array, or -1 if it is not present. * * ```ts * import { lastIndexOfNeedle } from "https://deno.land/std@$STD_VERSION/bytes/last_index_of_needle.ts"; * * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]); * const needle = new Uint8Array([1, 2]); * const notNeedle = new Uint8Array([5, 0]); * * lastIndexOfNeedle(source, needle); // 5 * lastIndexOfNeedle(source, notNeedle); // -1 * ``` * * ## Repeat a byte slice * * {@linkcode repeat} returns a new byte slice composed of `count` repetitions * of the `source` array. * * ```ts * import { repeat } from "https://deno.land/std@$STD_VERSION/bytes/repeat.ts"; * * const source = new Uint8Array([0, 1, 2]); * * repeat(source, 3); // Uint8Array(9) [0, 1, 2, 0, 1, 2, 0, 1, 2] * * repeat(source, 0); // Uint8Array(0) [] * * repeat(source, -1); // Throws `RangeError` * ``` * * ## Check if a byte slice starts with another byte slice * * {@linkcode startsWith} returns `true` if the prefix array appears at the start * of the source array, `false` otherwise. * * ```ts * import { startsWith } from "https://deno.land/std@$STD_VERSION/bytes/starts_with.ts"; * * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]); * const prefix = new Uint8Array([0, 1, 2]); * * startsWith(source, prefix); // true * ``` * * @module */
export * from "./concat.ts";export * from "./copy.ts";export * from "./ends_with.ts";export * from "./equals.ts";export * from "./includes_needle.ts";export * from "./index_of_needle.ts";export * from "./last_index_of_needle.ts";export * from "./repeat.ts";export * from "./starts_with.ts";
std

Version Info

Tagged at
3 weeks ago