@visulima/bytes 1.0.0 → 2.0.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 +24 -0
- package/README.md +29 -19
- package/dist/index.js +1 -0
- package/dist/packem_shared/concat-Duja_Ciy.js +1 -0
- package/dist/packem_shared/copy-CnXBfu7-.js +1 -0
- package/dist/packem_shared/endsWith-BAFUPkAB.js +1 -0
- package/dist/packem_shared/equals-CWGyNSTK.js +1 -0
- package/dist/packem_shared/includesNeedle-hNG5BH2U.js +1 -0
- package/dist/packem_shared/indexOfNeedle-C-5C1j-5.js +1 -0
- package/dist/packem_shared/lastIndexOfNeedle-wezgBke2.js +1 -0
- package/dist/packem_shared/repeat-BdWX5U9j.js +1 -0
- package/dist/packem_shared/startsWith-DXk4IAVe.js +1 -0
- package/package.json +4 -21
- package/dist/index.cjs +0 -76
- package/dist/index.d.cts +0 -287
- package/dist/index.d.mts +0 -287
- package/dist/index.mjs +0 -59
- package/dist/packem_shared/concat-CrMUrqFR.mjs +0 -18
- package/dist/packem_shared/concat-DO5DD91d.cjs +0 -22
- package/dist/packem_shared/copy-Bx6bRT8N.cjs +0 -18
- package/dist/packem_shared/copy-DrPnASpi.mjs +0 -14
- package/dist/packem_shared/endsWith-0SUmpwo5.mjs +0 -17
- package/dist/packem_shared/endsWith-D8qAxWS-.cjs +0 -21
- package/dist/packem_shared/equals-QKFTA-PW.mjs +0 -37
- package/dist/packem_shared/equals-lBip8nIE.cjs +0 -41
- package/dist/packem_shared/includesNeedle-DrBfDWAu.mjs +0 -10
- package/dist/packem_shared/includesNeedle-rD-vGkdN.cjs +0 -14
- package/dist/packem_shared/indexOfNeedle-ByhaFu9G.cjs +0 -31
- package/dist/packem_shared/indexOfNeedle-DNPShVZm.mjs +0 -27
- package/dist/packem_shared/lastIndexOfNeedle-Bw_wLjkK.cjs +0 -30
- package/dist/packem_shared/lastIndexOfNeedle-YY1XC9fo.mjs +0 -26
- package/dist/packem_shared/repeat-BBMZqtbD.cjs +0 -22
- package/dist/packem_shared/repeat-D9RZrtYr.mjs +0 -18
- package/dist/packem_shared/startsWith-BOQEkHrk.cjs +0 -18
- package/dist/packem_shared/startsWith-CC5eK1Xp.mjs +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## @visulima/bytes [2.0.0](https://github.com/visulima/visulima/compare/@visulima/bytes@1.0.1...@visulima/bytes@2.0.0) (2025-10-15)
|
|
2
|
+
|
|
3
|
+
### ⚠ BREAKING CHANGES
|
|
4
|
+
|
|
5
|
+
* Adjusted the node engine requirement to support versions 20.19 and above
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* Adjusted the node engine requirement to support versions 20.19 and above ([e07d813](https://github.com/visulima/visulima/commit/e07d813093c1d731fc775cfecb6c19868c08671f))
|
|
10
|
+
* update @visulima/packem to 2.0.0-alpha.30 across multiple packages for improved compatibility ([27b346e](https://github.com/visulima/visulima/commit/27b346eaa1c0fb0e420d9a9824482028307f4249))
|
|
11
|
+
|
|
12
|
+
### Miscellaneous Chores
|
|
13
|
+
|
|
14
|
+
* add Prettier configuration and update ESLint ignore patterns ([a9ba959](https://github.com/visulima/visulima/commit/a9ba959fae02a08b158b3b81a634a8fba8326b92))
|
|
15
|
+
* **deps:** update build scripts and remove cross-env dependency ([7510e82](https://github.com/visulima/visulima/commit/7510e826b9235a0013fe61c82a7eb333bc4cbb78))
|
|
16
|
+
* update package dependencies across multiple packages for improved compatibility and performance ([9567591](https://github.com/visulima/visulima/commit/9567591c415da3002f3a4fe08f8caf7ce01ca5f7))
|
|
17
|
+
* update package.json and pnpm-lock.yaml to include publint@0.3.12 and adjust build/test commands to exclude shared-utils ([1f7b3c0](https://github.com/visulima/visulima/commit/1f7b3c0381d77edfeec80ea1bf57b3469e929414))
|
|
18
|
+
|
|
19
|
+
## @visulima/bytes [1.0.1](https://github.com/visulima/visulima/compare/@visulima/bytes@1.0.0...@visulima/bytes@1.0.1) (2025-09-10)
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* **bytes:** restore require exports in package.json and add validation to packem.config.ts ([762b1f5](https://github.com/visulima/visulima/commit/762b1f5789398617032ef23f06763c4fd9f41eda))
|
|
24
|
+
|
|
1
25
|
## @visulima/bytes 1.0.0 (2025-06-03)
|
|
2
26
|
|
|
3
27
|
### Features
|
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ assert.deepStrictEqual(concat([a, b]), new Uint8Array([0, 1, 2, 3, 4, 5]));
|
|
|
62
62
|
Copies bytes from the source array to the destination array.
|
|
63
63
|
|
|
64
64
|
**Basic usage:**
|
|
65
|
+
|
|
65
66
|
```typescript
|
|
66
67
|
import { copy } from "@visulima/bytes";
|
|
67
68
|
import assert from "node:assert";
|
|
@@ -74,6 +75,7 @@ assert.deepStrictEqual(dst, new Uint8Array([9, 8, 7, 3, 4, 5]));
|
|
|
74
75
|
```
|
|
75
76
|
|
|
76
77
|
**Copy with offset:**
|
|
78
|
+
|
|
77
79
|
```typescript
|
|
78
80
|
import { copy } from "@visulima/bytes";
|
|
79
81
|
import assert from "node:assert";
|
|
@@ -120,6 +122,7 @@ assert.deepStrictEqual(equals(a, c), false);
|
|
|
120
122
|
Determines whether a byte slice contains a specific sequence of bytes.
|
|
121
123
|
|
|
122
124
|
**Basic usage:**
|
|
125
|
+
|
|
123
126
|
```typescript
|
|
124
127
|
import { includesNeedle } from "@visulima/bytes";
|
|
125
128
|
import assert from "node:assert";
|
|
@@ -131,6 +134,7 @@ assert.deepStrictEqual(includesNeedle(source, needle), true);
|
|
|
131
134
|
```
|
|
132
135
|
|
|
133
136
|
**With start index:**
|
|
137
|
+
|
|
134
138
|
```typescript
|
|
135
139
|
import { includesNeedle } from "@visulima/bytes";
|
|
136
140
|
import assert from "node:assert";
|
|
@@ -147,6 +151,7 @@ assert.deepStrictEqual(includesNeedle(source, needle, 6), false);
|
|
|
147
151
|
Finds the first index of a specific sequence of bytes within a byte slice.
|
|
148
152
|
|
|
149
153
|
**Basic usage:**
|
|
154
|
+
|
|
150
155
|
```typescript
|
|
151
156
|
import { indexOfNeedle } from "@visulima/bytes";
|
|
152
157
|
import assert from "node:assert";
|
|
@@ -160,6 +165,7 @@ assert.deepStrictEqual(indexOfNeedle(source, notNeedle), -1);
|
|
|
160
165
|
```
|
|
161
166
|
|
|
162
167
|
**With start index:**
|
|
168
|
+
|
|
163
169
|
```typescript
|
|
164
170
|
import { indexOfNeedle } from "@visulima/bytes";
|
|
165
171
|
import assert from "node:assert";
|
|
@@ -176,6 +182,7 @@ assert.deepStrictEqual(indexOfNeedle(source, needle, 6), -1);
|
|
|
176
182
|
Finds the last index of a specific sequence of bytes within a byte slice.
|
|
177
183
|
|
|
178
184
|
**Basic usage:**
|
|
185
|
+
|
|
179
186
|
```typescript
|
|
180
187
|
import { lastIndexOfNeedle } from "@visulima/bytes";
|
|
181
188
|
import assert from "node:assert";
|
|
@@ -189,6 +196,7 @@ assert.deepStrictEqual(lastIndexOfNeedle(source, notNeedle), -1);
|
|
|
189
196
|
```
|
|
190
197
|
|
|
191
198
|
**With start index:**
|
|
199
|
+
|
|
192
200
|
```typescript
|
|
193
201
|
import { lastIndexOfNeedle } from "@visulima/bytes";
|
|
194
202
|
import assert from "node:assert";
|
|
@@ -205,6 +213,7 @@ assert.deepStrictEqual(lastIndexOfNeedle(source, needle, 6), 5);
|
|
|
205
213
|
Repeats a byte slice a specified number of times.
|
|
206
214
|
|
|
207
215
|
**Basic usage:**
|
|
216
|
+
|
|
208
217
|
```typescript
|
|
209
218
|
import { repeat } from "@visulima/bytes";
|
|
210
219
|
import assert from "node:assert";
|
|
@@ -215,6 +224,7 @@ assert.deepStrictEqual(repeat(source, 3), new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1
|
|
|
215
224
|
```
|
|
216
225
|
|
|
217
226
|
**Zero count:**
|
|
227
|
+
|
|
218
228
|
```typescript
|
|
219
229
|
import { repeat } from "@visulima/bytes";
|
|
220
230
|
import assert from "node:assert";
|
|
@@ -242,20 +252,20 @@ assert.deepStrictEqual(startsWith(source, prefix), true);
|
|
|
242
252
|
|
|
243
253
|
This package provides the following utility functions for working with `Uint8Array`s, similar to the Deno standard library module [`@std/bytes`](https://github.com/denoland/std/tree/main/bytes):
|
|
244
254
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
255
|
+
- **`concat`**: Concatenate an array of byte slices into a single slice.
|
|
256
|
+
- **`copy`**: Copy bytes from the source array to the destination array and returns the number of bytes copied.
|
|
257
|
+
- **`endsWith`**: Returns true if the suffix array appears at the end of the source array, false otherwise.
|
|
258
|
+
- **`equals`**: Check whether byte slices are equal to each other.
|
|
259
|
+
- **`includesNeedle`**: Determines whether the source array contains the needle array.
|
|
260
|
+
- **`indexOfNeedle`**: Returns the index of the first occurrence of the needle array in the source array, or -1 if it is not present.
|
|
261
|
+
- **`lastIndexOfNeedle`**: Returns the index of the last occurrence of the needle array in the source array, or -1 if it is not present.
|
|
262
|
+
- **`repeat`**: Returns a new byte slice composed of count repetitions of the source array.
|
|
263
|
+
- **`startsWith`**: Returns true if the prefix array appears at the start of the source array, false otherwise.
|
|
264
|
+
- **`bufferToUint8Array(buf: Buffer): Uint8Array`**: Converts a Node.js `Buffer` to a `Uint8Array`.
|
|
265
|
+
- **`isUint8Array(x: unknown): x is Uint8Array`**: Checks if a value is a `Uint8Array` or (in Node.js) a `Buffer`.
|
|
266
|
+
- **`asciiToUint8Array(txt: TemplateStringsArray | string | [string]): Uint8Array`**: Converts an ASCII string to a `Uint8Array`.
|
|
267
|
+
- **`utf8ToUint8Array(txt: TemplateStringsArray | string | [string]): Uint8Array`**: Converts a UTF-8 string to a `Uint8Array` (requires Node.js `Buffer` support).
|
|
268
|
+
- **`toUint8Array(data: unknown): Uint8Array`**: Attempts to convert various data types (like `ArrayBuffer`, `Array` of numbers, `Buffer`, strings via `Buffer.from`) to a `Uint8Array`.
|
|
259
269
|
|
|
260
270
|
## Related
|
|
261
271
|
|
|
@@ -309,7 +319,7 @@ assert.deepStrictEqual(templateAscii, new Uint8Array([87, 111, 114, 108, 100]));
|
|
|
309
319
|
|
|
310
320
|
Converts a UTF-8 string to a `Uint8Array`.
|
|
311
321
|
|
|
312
|
-
|
|
322
|
+
````typescript
|
|
313
323
|
import { utf8ToUint8Array } from "@visulima/bytes";
|
|
314
324
|
import assert from "node:assert";
|
|
315
325
|
|
|
@@ -351,7 +361,7 @@ try {
|
|
|
351
361
|
} catch (e: any) {
|
|
352
362
|
assert.strictEqual(e.message, "UINT8ARRAY_INCOMPATIBLE: Cannot convert data to Uint8Array");
|
|
353
363
|
}
|
|
354
|
-
|
|
364
|
+
````
|
|
355
365
|
|
|
356
366
|
## Supported Node.js Versions
|
|
357
367
|
|
|
@@ -366,9 +376,9 @@ If you would like to help take a look at the [list of issues](https://github.com
|
|
|
366
376
|
|
|
367
377
|
## Credits
|
|
368
378
|
|
|
369
|
-
-
|
|
370
|
-
-
|
|
371
|
-
-
|
|
379
|
+
- The Deno Standard Library authors and contributors for their work on `@std/bytes`.
|
|
380
|
+
- [Daniel Bannert](https://github.com/prisis)
|
|
381
|
+
- [All Contributors](https://github.com/visulima/visulima/graphs/contributors)
|
|
372
382
|
|
|
373
383
|
## License
|
|
374
384
|
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var y=Object.defineProperty;var s=(r,e)=>y(r,"name",{value:e,configurable:!0});import{createRequire as c}from"node:module";import{concat as h}from"./packem_shared/concat-Duja_Ciy.js";import{copy as w}from"./packem_shared/copy-CnXBfu7-.js";import{endsWith as j}from"./packem_shared/endsWith-BAFUPkAB.js";import{equals as O}from"./packem_shared/equals-CWGyNSTK.js";import{includesNeedle as I}from"./packem_shared/includesNeedle-hNG5BH2U.js";import{indexOfNeedle as C}from"./packem_shared/indexOfNeedle-C-5C1j-5.js";import{lastIndexOfNeedle as P}from"./packem_shared/lastIndexOfNeedle-wezgBke2.js";import{repeat as S}from"./packem_shared/repeat-BdWX5U9j.js";import{startsWith as L}from"./packem_shared/startsWith-DXk4IAVe.js";const p=c(import.meta.url),o=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,A=s(r=>{if(typeof o<"u"&&o.versions&&o.versions.node){const[e,n]=o.versions.node.split(".").map(Number);if(e>22||e===22&&n>=3||e===20&&n>=16)return o.getBuiltinModule(r)}return p(r)},"__cjs_getBuiltinModule"),{Buffer:t}=A("node:buffer");var l=Object.defineProperty,a=s((r,e)=>l(r,"name",{value:e,configurable:!0}),"i");const f=a(r=>new Uint8Array(r.buffer,r.byteOffset,r.length),"bufferToUint8Array"),_=typeof t=="function"?r=>r instanceof Uint8Array||t.isBuffer(r):r=>r instanceof Uint8Array,d=a(r=>{if(typeof r=="string")return d([r]);const[e]=Array.isArray(r)?r:[String.raw(r)],n=e.length,u=new Uint8Array(n);for(let i=0;i<n;i+=1)u[i]=e.charCodeAt(i)&255;return u},"asciiToUint8Array"),m=a(r=>{if(typeof r=="string")return m([r]);const[e]=Array.isArray(r)?r:[String.raw(r)];return f(t.from(e,"utf8"))},"utf8ToUint8Array"),b=a(r=>{if(typeof t=="function"&&t.isBuffer(r))return f(r);if(r instanceof Uint8Array)return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(Array.isArray(r)&&r.every(e=>typeof e=="number"))return new Uint8Array(r);if(typeof t=="function"){if(t.isBuffer(r))return f(r);if(typeof r=="string")try{return f(t.from(r))}catch{}}throw new Error("UINT8ARRAY_INCOMPATIBLE: Cannot convert data to Uint8Array")},"toUint8Array");export{d as asciiToUint8Array,f as bufferToUint8Array,h as concat,w as copy,j as endsWith,O as equals,I as includesNeedle,C as indexOfNeedle,_ as isUint8Array,P as lastIndexOfNeedle,S as repeat,L as startsWith,b as toUint8Array,m as utf8ToUint8Array};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=Object.defineProperty;var o=(e,n)=>a(e,"name",{value:n,configurable:!0});var f=Object.defineProperty,l=o((e,n)=>f(e,"name",{value:n,configurable:!0}),"f");function u(e){let n=0;for(const t of e)n+=t.length;const r=new Uint8Array(n);let c=0;for(const t of e)r.set(t,c),c+=t.length;return r}o(u,"concat");l(u,"concat");export{u as concat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var y=Object.defineProperty;var r=(e,t)=>y(e,"name",{value:t,configurable:!0});var b=Object.defineProperty,o=r((e,t)=>b(e,"name",{value:t,configurable:!0}),"y");function c(e,t,a=0){a=Math.max(0,Math.min(a,t.byteLength));const n=t.byteLength-a;return e.byteLength>n&&(e=e.subarray(0,n)),t.set(e,a),e.byteLength}r(c,"copy");o(c,"copy");export{c as copy};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.defineProperty;var t=(r,e)=>l(r,"name",{value:e,configurable:!0});var u=Object.defineProperty,a=t((r,e)=>u(r,"name",{value:e,configurable:!0}),"l");function i(r,e){const f=r.length-e.length;if(f<0)return!1;for(let n=e.length-1;n>=0;n--)if(r[f+n]!==e[n])return!1;return!0}t(i,"endsWith");a(i,"endsWith");export{i as endsWith};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var c=Object.defineProperty;var l=(e,f)=>c(e,"name",{value:f,configurable:!0});var h=Object.defineProperty,a=l((e,f)=>h(e,"name",{value:f,configurable:!0}),"l");function o(e,f){for(let t=0;t<f.length;t++)if(e[t]!==f[t])return!1;return!0}l(o,"i");a(o,"equalsNaive");function i(e,f){const t=e.length,n=3-(e.byteOffset+3)%4,u=Math.floor((t-n)/4),s=new Uint32Array(e.buffer,e.byteOffset+n,u),b=new Uint32Array(f.buffer,f.byteOffset+n,u);for(let r=0;r<n;r++)if(e[r]!==f[r])return!1;for(let r=0;r<s.length;r++)if(s[r]!==b[r])return!1;for(let r=n+u*4;r<t;r++)if(e[r]!==f[r])return!1;return!0}l(i,"a");a(i,"equals32Bit");const y=160;function g(e,f){return e.length!==f.length?!1:e.length>=y&&e.byteOffset%4===f.byteOffset%4?i(e,f):o(e,f)}l(g,"equals");a(g,"equals");export{g as equals};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=Object.defineProperty;var n=(e,r)=>d(e,"name",{value:r,configurable:!0});import{indexOfNeedle as l}from"./indexOfNeedle-C-5C1j-5.js";var t=Object.defineProperty,u=n((e,r)=>t(e,"name",{value:r,configurable:!0}),"r");function o(e,r,i=0){return l(e,r,i)!==-1}n(o,"includesNeedle");u(o,"includesNeedle");export{o as includesNeedle};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var g=(e,n)=>o(e,"name",{value:n,configurable:!0});var u=Object.defineProperty,a=g((e,n)=>u(e,"name",{value:n,configurable:!0}),"g");function c(e,n,t=0){if(t<0&&(t=Math.max(0,e.length+t)),n.length>e.length-t)return-1;const h=n[0];for(let r=t;r<e.length;r++){if(e[r]!==h)continue;let l=1,f=r+1;for(;l<n.length&&e[f]===n[f-r];)l++,f++;if(l===n.length)return r}return-1}g(c,"indexOfNeedle");a(c,"indexOfNeedle");export{c as indexOfNeedle};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var f=(l,e)=>o(l,"name",{value:e,configurable:!0});var u=Object.defineProperty,a=f((l,e)=>u(l,"name",{value:e,configurable:!0}),"f");function g(l,e,t=l.length-1){if(t<0)return-1;t>=l.length&&(t=l.length-1);const i=e[e.length-1];for(let n=t;n>=0;n--){if(l[n]!==i)continue;let r=1,h=n;for(;r<e.length&&l[--h]===e[e.length-1-(n-h)];)r++;if(r===e.length)return n-e.length+1}return-1}f(g,"lastIndexOfNeedle");a(g,"lastIndexOfNeedle");export{g as lastIndexOfNeedle};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=Object.defineProperty;var o=(r,e)=>a(r,"name",{value:e,configurable:!0});import{copy as i}from"./copy-CnXBfu7-.js";var u=Object.defineProperty,g=o((r,e)=>u(r,"name",{value:e,configurable:!0}),"i");function f(r,e){if(e<0||!Number.isInteger(e))throw new RangeError("Count must be a non-negative integer");const n=new Uint8Array(r.length*e);let t=0;for(;t<n.length;)t+=i(r,n,t);return n}o(f,"repeat");g(f,"repeat");export{f as repeat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=Object.defineProperty;var n=(r,e)=>a(r,"name",{value:e,configurable:!0});var l=Object.defineProperty,f=n((r,e)=>l(r,"name",{value:e,configurable:!0}),"r");function u(r,e){if(e.length>r.length)return!1;for(let t=0;t<e.length;t++)if(r[t]!==e[t])return!1;return!0}n(u,"startsWith");f(u,"startsWith");export{u as startsWith};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/bytes",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Utility functions to make dealing with Uint8Arrays easier",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"visulima",
|
|
@@ -34,35 +34,18 @@
|
|
|
34
34
|
"type": "module",
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
"default": "./dist/index.cjs"
|
|
40
|
-
},
|
|
41
|
-
"import": {
|
|
42
|
-
"types": "./dist/index.d.mts",
|
|
43
|
-
"default": "./dist/index.mjs"
|
|
44
|
-
}
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"default": "./dist/index.js"
|
|
45
39
|
},
|
|
46
40
|
"./package.json": "./package.json"
|
|
47
41
|
},
|
|
48
|
-
"main": "dist/index.cjs",
|
|
49
|
-
"module": "dist/index.mjs",
|
|
50
|
-
"browser": "./dist/index.mjs",
|
|
51
|
-
"types": "dist/index.d.ts",
|
|
52
|
-
"typesVersions": {
|
|
53
|
-
">=5.0": {
|
|
54
|
-
".": [
|
|
55
|
-
"./dist/index.d.ts"
|
|
56
|
-
]
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
42
|
"files": [
|
|
60
43
|
"dist",
|
|
61
44
|
"README.md",
|
|
62
45
|
"CHANGELOG.md"
|
|
63
46
|
],
|
|
64
47
|
"engines": {
|
|
65
|
-
"node": ">=20.
|
|
48
|
+
"node": ">=20.19 <=24.x"
|
|
66
49
|
},
|
|
67
50
|
"publishConfig": {
|
|
68
51
|
"access": "public",
|
package/dist/index.cjs
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
-
|
|
5
|
-
const node_buffer = require('node:buffer');
|
|
6
|
-
const concat = require('./packem_shared/concat-DO5DD91d.cjs');
|
|
7
|
-
const copy = require('./packem_shared/copy-Bx6bRT8N.cjs');
|
|
8
|
-
const endsWith = require('./packem_shared/endsWith-D8qAxWS-.cjs');
|
|
9
|
-
const equals = require('./packem_shared/equals-lBip8nIE.cjs');
|
|
10
|
-
const includesNeedle = require('./packem_shared/includesNeedle-rD-vGkdN.cjs');
|
|
11
|
-
const indexOfNeedle = require('./packem_shared/indexOfNeedle-ByhaFu9G.cjs');
|
|
12
|
-
const lastIndexOfNeedle = require('./packem_shared/lastIndexOfNeedle-Bw_wLjkK.cjs');
|
|
13
|
-
const repeat = require('./packem_shared/repeat-BBMZqtbD.cjs');
|
|
14
|
-
const startsWith = require('./packem_shared/startsWith-BOQEkHrk.cjs');
|
|
15
|
-
|
|
16
|
-
var __defProp = Object.defineProperty;
|
|
17
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
18
|
-
const bufferToUint8Array = /* @__PURE__ */ __name((buf) => new Uint8Array(buf.buffer, buf.byteOffset, buf.length), "bufferToUint8Array");
|
|
19
|
-
const isUint8Array = typeof node_buffer.Buffer === "function" ? (x) => x instanceof Uint8Array || node_buffer.Buffer.isBuffer(x) : (x) => x instanceof Uint8Array;
|
|
20
|
-
const asciiToUint8Array = /* @__PURE__ */ __name((txt) => {
|
|
21
|
-
if (typeof txt === "string")
|
|
22
|
-
return asciiToUint8Array([txt]);
|
|
23
|
-
const [input] = Array.isArray(txt) ? txt : [String.raw(txt)];
|
|
24
|
-
const inputLength = input.length;
|
|
25
|
-
const result = new Uint8Array(inputLength);
|
|
26
|
-
for (let index = 0; index < inputLength; index += 1) {
|
|
27
|
-
result[index] = input.charCodeAt(index) & 255;
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}, "asciiToUint8Array");
|
|
31
|
-
const utf8ToUint8Array = /* @__PURE__ */ __name((txt) => {
|
|
32
|
-
if (typeof txt === "string")
|
|
33
|
-
return utf8ToUint8Array([txt]);
|
|
34
|
-
const [input] = Array.isArray(txt) ? txt : [String.raw(txt)];
|
|
35
|
-
return bufferToUint8Array(node_buffer.Buffer.from(input, "utf8"));
|
|
36
|
-
}, "utf8ToUint8Array");
|
|
37
|
-
const toUint8Array = /* @__PURE__ */ __name((data) => {
|
|
38
|
-
if (typeof node_buffer.Buffer === "function" && node_buffer.Buffer.isBuffer(data)) {
|
|
39
|
-
return bufferToUint8Array(data);
|
|
40
|
-
}
|
|
41
|
-
if (data instanceof Uint8Array) {
|
|
42
|
-
return data;
|
|
43
|
-
}
|
|
44
|
-
if (data instanceof ArrayBuffer)
|
|
45
|
-
return new Uint8Array(data);
|
|
46
|
-
if (Array.isArray(data) && data.every((item) => typeof item === "number")) {
|
|
47
|
-
return new Uint8Array(data);
|
|
48
|
-
}
|
|
49
|
-
if (typeof node_buffer.Buffer === "function") {
|
|
50
|
-
if (node_buffer.Buffer.isBuffer(data)) {
|
|
51
|
-
return bufferToUint8Array(data);
|
|
52
|
-
}
|
|
53
|
-
if (typeof data === "string") {
|
|
54
|
-
try {
|
|
55
|
-
return bufferToUint8Array(node_buffer.Buffer.from(data));
|
|
56
|
-
} catch {
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
throw new Error("UINT8ARRAY_INCOMPATIBLE: Cannot convert data to Uint8Array");
|
|
61
|
-
}, "toUint8Array");
|
|
62
|
-
|
|
63
|
-
exports.concat = concat.concat;
|
|
64
|
-
exports.copy = copy.copy;
|
|
65
|
-
exports.endsWith = endsWith.endsWith;
|
|
66
|
-
exports.equals = equals.equals;
|
|
67
|
-
exports.includesNeedle = includesNeedle.includesNeedle;
|
|
68
|
-
exports.indexOfNeedle = indexOfNeedle.indexOfNeedle;
|
|
69
|
-
exports.lastIndexOfNeedle = lastIndexOfNeedle.lastIndexOfNeedle;
|
|
70
|
-
exports.repeat = repeat.repeat;
|
|
71
|
-
exports.startsWith = startsWith.startsWith;
|
|
72
|
-
exports.asciiToUint8Array = asciiToUint8Array;
|
|
73
|
-
exports.bufferToUint8Array = bufferToUint8Array;
|
|
74
|
-
exports.isUint8Array = isUint8Array;
|
|
75
|
-
exports.toUint8Array = toUint8Array;
|
|
76
|
-
exports.utf8ToUint8Array = utf8ToUint8Array;
|
package/dist/index.d.cts
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
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_ };
|