@visulima/bytes 2.0.3 → 2.0.4

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 CHANGED
@@ -1,3 +1,14 @@
1
+ ## @visulima/bytes [2.0.4](https://github.com/visulima/visulima/compare/@visulima/bytes@2.0.3...@visulima/bytes@2.0.4) (2025-11-12)
2
+
3
+ ### Bug Fixes
4
+
5
+ * update package configurations and TypeScript definitions ([b59aa59](https://github.com/visulima/visulima/commit/b59aa59dac1508216b944f4b917fb4a7ab1f70a4))
6
+
7
+ ### Miscellaneous Chores
8
+
9
+ * Add jsr file to all packages for release ([#565](https://github.com/visulima/visulima/issues/565)) ([ec91652](https://github.com/visulima/visulima/commit/ec91652b4e4112adf14ba152c1239a7703ba425a))
10
+ * update license files and clean up TypeScript definitions ([fe668cc](https://github.com/visulima/visulima/commit/fe668cc26de23591d4df54a0954455ebbe31b22d))
11
+
1
12
  ## @visulima/bytes [2.0.3](https://github.com/visulima/visulima/compare/@visulima/bytes@2.0.2...@visulima/bytes@2.0.3) (2025-11-07)
2
13
 
3
14
  ### Bug Fixes
package/LICENSE.md CHANGED
@@ -55,10 +55,12 @@ The published @visulima/bytes artifact additionally contains code with the follo
55
55
  <!-- TYPE_DEPENDENCIES -->
56
56
 
57
57
  # Licenses of bundled types
58
+
58
59
  The published @visulima/bytes artifact additionally contains code with the following licenses:
59
60
 
60
61
  # Bundled types:
61
- ## @jsr/std__bytes
62
+
63
+ ## @jsr/std\_\_bytes
62
64
 
63
65
  > MIT License
64
66
  >
package/dist/index.d.ts CHANGED
@@ -1,287 +1,40 @@
1
- import { Buffer } from 'node:buffer';
2
-
3
- /**
4
- * Concatenate an array of byte slices into a single slice.
5
- *
6
- * @param buffers Array of byte slices to concatenate.
7
- * @returns A new byte slice containing all the input slices concatenated.
8
- *
9
- * @example Basic usage
10
- * ```ts
11
- * import { concat } from "@std/bytes/concat";
12
- * import { assertEquals } from "@std/assert";
13
- *
14
- * const a = new Uint8Array([0, 1, 2]);
15
- * const b = new Uint8Array([3, 4, 5]);
16
- *
17
- * assertEquals(concat([a, b]), new Uint8Array([0, 1, 2, 3, 4, 5]));
18
- * ```
19
- */ declare function concat(buffers: readonly Uint8Array[]): Uint8Array_;
20
-
21
- /**
22
- * Copy bytes from the source array to the destination array and returns the
23
- * number of bytes copied.
24
- *
25
- * If the source array is larger than what the `dst` array can hold, only the
26
- * amount of bytes that fit in the `dst` array are copied.
27
- *
28
- * @param src Source array to copy from.
29
- * @param dst Destination array to copy to.
30
- * @param offset Offset in the destination array to start copying to. Defaults
31
- * to 0.
32
- * @returns Number of bytes copied.
33
- *
34
- * @example Basic usage
35
- * ```ts
36
- * import { copy } from "@std/bytes/copy";
37
- * import { assertEquals } from "@std/assert";
38
- *
39
- * const src = new Uint8Array([9, 8, 7]);
40
- * const dst = new Uint8Array([0, 1, 2, 3, 4, 5]);
41
- *
42
- * assertEquals(copy(src, dst), 3);
43
- * assertEquals(dst, new Uint8Array([9, 8, 7, 3, 4, 5]));
44
- * ```
45
- *
46
- * @example Copy with offset
47
- * ```ts
48
- * import { copy } from "@std/bytes/copy";
49
- * import { assertEquals } from "@std/assert";
50
- *
51
- * const src = new Uint8Array([1, 1, 1, 1]);
52
- * const dst = new Uint8Array([0, 0, 0, 0]);
53
- *
54
- * assertEquals(copy(src, dst, 1), 3);
55
- * assertEquals(dst, new Uint8Array([0, 1, 1, 1]));
56
- * ```
57
- * Defining an offset will start copying at the specified index in the
58
- * destination array.
59
- */ declare function copy(src: Uint8Array, dst: Uint8Array, offset?: number): number;
60
-
61
- /**
62
- * Returns `true` if the suffix array appears at the end of the source array,
63
- * `false` otherwise.
64
- *
65
- * The complexity of this function is `O(suffix.length)`.
66
- *
67
- * @param source Source array to check.
68
- * @param suffix Suffix array to check for.
69
- * @returns `true` if the suffix array appears at the end of the source array,
70
- * `false` otherwise.
71
- *
72
- * @example Basic usage
73
- * ```ts
74
- * import { endsWith } from "@std/bytes/ends-with";
75
- * import { assertEquals } from "@std/assert";
76
- *
77
- * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
78
- * const suffix = new Uint8Array([1, 2, 3]);
79
- *
80
- * assertEquals(endsWith(source, suffix), true);
81
- * ```
82
- */ declare function endsWith(source: Uint8Array, suffix: Uint8Array): boolean;
83
-
84
- /**
85
- * Check whether byte slices are equal to each other.
86
- *
87
- * @param a First array to check equality.
88
- * @param b Second array to check equality.
89
- * @returns `true` if the arrays are equal, `false` otherwise.
90
- *
91
- * @example Basic usage
92
- * ```ts
93
- * import { equals } from "@std/bytes/equals";
94
- * import { assertEquals } from "@std/assert";
95
- *
96
- * const a = new Uint8Array([1, 2, 3]);
97
- * const b = new Uint8Array([1, 2, 3]);
98
- * const c = new Uint8Array([4, 5, 6]);
99
- *
100
- * assertEquals(equals(a, b), true);
101
- * assertEquals(equals(a, c), false);
102
- * ```
103
- */ declare function equals(a: Uint8Array, b: Uint8Array): boolean;
104
-
105
- /**
106
- * Determines whether the source array contains the needle array.
107
- *
108
- * The complexity of this function is `O(source.length * needle.length)`.
109
- *
110
- * @param source Source array to check.
111
- * @param needle Needle array to check for.
112
- * @param start Start index in the source array to begin the search. Defaults to
113
- * 0.
114
- * @returns `true` if the source array contains the needle array, `false`
115
- * otherwise.
116
- *
117
- * @example Basic usage
118
- * ```ts
119
- * import { includesNeedle } from "@std/bytes/includes-needle";
120
- * import { assertEquals } from "@std/assert";
121
- *
122
- * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
123
- * const needle = new Uint8Array([1, 2]);
124
- *
125
- * assertEquals(includesNeedle(source, needle), true);
126
- * ```
127
- *
128
- * @example Start index
129
- * ```ts
130
- * import { includesNeedle } from "@std/bytes/includes-needle";
131
- * import { assertEquals } from "@std/assert";
132
- *
133
- * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
134
- * const needle = new Uint8Array([1, 2]);
135
- *
136
- * assertEquals(includesNeedle(source, needle, 3), true);
137
- * assertEquals(includesNeedle(source, needle, 6), false);
138
- * ```
139
- * The search will start at the specified index in the source array.
140
- */ declare function includesNeedle(source: Uint8Array, needle: Uint8Array, start?: number): boolean;
141
-
142
- /**
143
- * Returns the index of the first occurrence of the needle array in the source
144
- * array, or -1 if it is not present.
145
- *
146
- * A start index can be specified as the third argument that begins the search
147
- * at that given index. The start index defaults to the start of the array.
148
- *
149
- * The complexity of this function is `O(source.length * needle.length)`.
150
- *
151
- * @param source Source array to check.
152
- * @param needle Needle array to check for.
153
- * @param start Start index in the source array to begin the search. Defaults to
154
- * 0.
155
- * @returns Index of the first occurrence of the needle array in the source
156
- * array, or -1 if it is not present.
157
- *
158
- * @example Basic usage
159
- * ```ts
160
- * import { indexOfNeedle } from "@std/bytes/index-of-needle";
161
- * import { assertEquals } from "@std/assert";
162
- *
163
- * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
164
- * const needle = new Uint8Array([1, 2]);
165
- * const notNeedle = new Uint8Array([5, 0]);
166
- *
167
- * assertEquals(indexOfNeedle(source, needle), 1);
168
- * assertEquals(indexOfNeedle(source, notNeedle), -1);
169
- * ```
170
- *
171
- * @example Start index
172
- * ```ts
173
- * import { indexOfNeedle } from "@std/bytes/index-of-needle";
174
- * import { assertEquals } from "@std/assert";
175
- *
176
- * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
177
- * const needle = new Uint8Array([1, 2]);
178
- *
179
- * assertEquals(indexOfNeedle(source, needle, 2), 3);
180
- * assertEquals(indexOfNeedle(source, needle, 6), -1);
181
- * ```
182
- * Defining a start index will begin the search at the specified index in the
183
- * source array.
184
- */ declare function indexOfNeedle(source: Uint8Array, needle: Uint8Array, start?: number): number;
185
-
186
- /**
187
- * Returns the index of the last occurrence of the needle array in the source
188
- * array, or -1 if it is not present.
189
- *
190
- * The complexity of this function is `O(source.length * needle.length)`.
191
- *
192
- * @param source Source array to check.
193
- * @param needle Needle array to check for.
194
- * @param start Start index in the source array to begin the search. Defaults to
195
- * `source.length - 1`.
196
- * @returns Index of the last occurrence of the needle array in the source
197
- * array, or -1 if it is not present.
198
- *
199
- * @example Basic usage
200
- * ```ts
201
- * import { lastIndexOfNeedle } from "@std/bytes/last-index-of-needle";
202
- * import { assertEquals } from "@std/assert";
203
- *
204
- * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
205
- * const needle = new Uint8Array([1, 2]);
206
- * const notNeedle = new Uint8Array([5, 0]);
207
- *
208
- * assertEquals(lastIndexOfNeedle(source, needle), 5);
209
- * assertEquals(lastIndexOfNeedle(source, notNeedle), -1);
210
- * ```
211
- *
212
- * @example Start index
213
- * ```ts
214
- * import { lastIndexOfNeedle } from "@std/bytes/last-index-of-needle";
215
- * import { assertEquals } from "@std/assert";
216
- *
217
- * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
218
- * const needle = new Uint8Array([1, 2]);
219
- *
220
- * assertEquals(lastIndexOfNeedle(source, needle, 2), 1);
221
- * assertEquals(lastIndexOfNeedle(source, needle, 6), 5);
222
- * ```
223
- * Defining a start index will begin the search at the specified index in the
224
- * source array.
225
- */ declare function lastIndexOfNeedle(source: Uint8Array, needle: Uint8Array, start?: number): number;
226
-
227
- /**
228
- * Returns a new byte slice composed of `count` repetitions of the `source`
229
- * array.
230
- *
231
- * @param source Source array to repeat.
232
- * @param count Number of times to repeat the source array.
233
- * @returns A new byte slice composed of `count` repetitions of the `source`
234
- * array.
235
- *
236
- * @example Basic usage
237
- * ```ts
238
- * import { repeat } from "@std/bytes/repeat";
239
- * import { assertEquals } from "@std/assert";
240
- *
241
- * const source = new Uint8Array([0, 1, 2]);
242
- *
243
- * assertEquals(repeat(source, 3), new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1, 2]));
244
- * ```
245
- *
246
- * @example Zero count
247
- * ```ts
248
- * import { repeat } from "@std/bytes/repeat";
249
- * import { assertEquals } from "@std/assert";
250
- *
251
- * const source = new Uint8Array([0, 1, 2]);
252
- *
253
- * assertEquals(repeat(source, 0), new Uint8Array());
254
- * ```
255
- */ declare function repeat(source: Uint8Array, count: number): Uint8Array_;
256
-
257
- /**
258
- * Returns `true` if the prefix array appears at the start of the source array,
259
- * `false` otherwise.
260
- *
261
- * The complexity of this function is `O(prefix.length)`.
262
- *
263
- * @param source Source array to check.
264
- * @param prefix Prefix array to check for.
265
- * @returns `true` if the prefix array appears at the start of the source array,
266
- * `false` otherwise.
267
- *
268
- * @example Basic usage
269
- * ```ts
270
- * import { startsWith } from "@std/bytes/starts-with";
271
- * import { assertEquals } from "@std/assert";
272
- *
273
- * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
274
- * const prefix = new Uint8Array([0, 1, 2]);
275
- *
276
- * assertEquals(startsWith(source, prefix), true);
277
- * ```
278
- */ declare function startsWith(source: Uint8Array, prefix: Uint8Array): boolean;
279
-
280
- declare const bufferToUint8Array: (buf: Buffer) => Uint8Array;
281
- declare const isUint8Array: (x: unknown) => x is Uint8Array;
282
- declare const asciiToUint8Array: (txt: TemplateStringsArray | string | [string]) => Uint8Array;
283
- declare const utf8ToUint8Array: (txt: TemplateStringsArray | [string] | string) => Uint8Array;
284
- declare const toUint8Array: (data: unknown) => Uint8Array;
285
-
286
- export { asciiToUint8Array, bufferToUint8Array, concat, copy, endsWith, equals, includesNeedle, indexOfNeedle, isUint8Array, lastIndexOfNeedle, repeat, startsWith, toUint8Array, utf8ToUint8Array };
287
- export type { Uint8Array_ };
1
+ import { Buffer } from "node:buffer";
2
+ /**
3
+ * Converts a Node.js Buffer to a Uint8Array.
4
+ * Note: While Buffer instances are Uint8Array instances, this function
5
+ * creates a new Uint8Array view on the Buffer's underlying ArrayBuffer,
6
+ * ensuring correct byteOffset and length.
7
+ * @param buf The Buffer to convert.
8
+ * @returns A Uint8Array view of the Buffer.
9
+ */
10
+ export declare const bufferToUint8Array: (buf: Buffer) => Uint8Array;
11
+ /**
12
+ * Checks if a value is a Uint8Array or, in a Node.js environment, a Buffer.
13
+ * @param x The value to check.
14
+ * @returns True if x is a Uint8Array or Buffer, false otherwise.
15
+ */
16
+ export declare const isUint8Array: (x: unknown) => x is Uint8Array;
17
+ /**
18
+ * Converts an ASCII string, array of strings, or template literal to a Uint8Array.
19
+ * Each character is converted to its ASCII byte value (0-255). Characters outside this range will be truncated.
20
+ * @param txt The input string, array of strings, or template strings array.
21
+ * @returns A Uint8Array representing the ASCII encoded string.
22
+ */
23
+ export declare const asciiToUint8Array: (txt: TemplateStringsArray | string | [string]) => Uint8Array;
24
+ /**
25
+ * Converts a UTF-8 string, array of strings, or template literal to a Uint8Array.
26
+ * Requires Node.js Buffer support.
27
+ * @param txt The input string, array of strings, or template strings array.
28
+ * @returns A Uint8Array representing the UTF-8 encoded string.
29
+ */
30
+ export declare const utf8ToUint8Array: (txt: TemplateStringsArray | [string] | string) => Uint8Array;
31
+ /**
32
+ * Attempts to convert various data types to a Uint8Array.
33
+ * Supports Uint8Array (returns as is), ArrayBuffer, Array of numbers.
34
+ * In Node.js, also supports Buffer (returns as is or converts from other types via Buffer.from).
35
+ * @param data The data to convert.
36
+ * @returns A Uint8Array representation of the input data.
37
+ * @throws Error 'UINT8ARRAY_INCOMPATIBLE' if the data cannot be converted and Buffer is not available for fallback.
38
+ */
39
+ export declare const toUint8Array: (data: unknown) => Uint8Array;
40
+ export * from "@std/bytes";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/bytes",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Utility functions to make dealing with Uint8Arrays easier",
5
5
  "keywords": [
6
6
  "visulima",