@fedify/fedify 1.6.0-dev.778 → 1.6.0-dev.795
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/CHANGES.md +29 -0
- package/CONTRIBUTING.md +7 -0
- package/FEDERATION.md +6 -2
- package/README.md +1 -1
- package/SPONSORS.md +1 -1
- package/esm/deno.js +3 -1
- package/esm/deps/jsr.io/@std/crypto/1.0.4/timing_safe_equal.js +55 -0
- package/esm/federation/middleware.js +26 -1
- package/esm/federation/send.js +6 -7
- package/esm/runtime/docloader.js +4 -16
- package/esm/sig/http.js +528 -9
- package/esm/sig/key.js +4 -1
- package/esm/testing/fixtures/remote.domain/users/bob +20 -0
- package/esm/vocab/vocab.js +308 -176
- package/package.json +2 -1
- package/types/deno.d.ts +2 -0
- package/types/deps/jsr.io/@std/crypto/1.0.4/timing_safe_equal.d.ts +34 -0
- package/types/deps/jsr.io/@std/crypto/1.0.4/timing_safe_equal.d.ts.map +1 -0
- package/types/federation/middleware.d.ts +21 -3
- package/types/federation/middleware.d.ts.map +1 -1
- package/types/federation/send.d.ts +6 -0
- package/types/federation/send.d.ts.map +1 -1
- package/types/runtime/docloader.d.ts +17 -1
- package/types/runtime/docloader.d.ts.map +1 -1
- package/types/sig/http.d.ts +128 -0
- package/types/sig/http.d.ts.map +1 -1
- package/types/sig/key.d.ts.map +1 -1
- package/types/sig/mod.d.ts +1 -1
- package/types/sig/mod.d.ts.map +1 -1
- package/types/vocab/vocab.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/bytes/1.0.5/copy.js +0 -50
- package/esm/deps/jsr.io/@std/bytes/1.0.5/ends_with.js +0 -36
- package/esm/deps/jsr.io/@std/bytes/1.0.5/equals.js +0 -82
- package/esm/deps/jsr.io/@std/bytes/1.0.5/includes_needle.js +0 -42
- package/esm/deps/jsr.io/@std/bytes/1.0.5/index_of_needle.js +0 -68
- package/esm/deps/jsr.io/@std/bytes/1.0.5/last_index_of_needle.js +0 -65
- package/esm/deps/jsr.io/@std/bytes/1.0.5/mod.js +0 -34
- package/esm/deps/jsr.io/@std/bytes/1.0.5/repeat.js +0 -43
- package/esm/deps/jsr.io/@std/bytes/1.0.5/starts_with.js +0 -34
- package/types/deps/jsr.io/@std/bytes/1.0.5/copy.d.ts +0 -41
- package/types/deps/jsr.io/@std/bytes/1.0.5/copy.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/bytes/1.0.5/ends_with.d.ts +0 -24
- package/types/deps/jsr.io/@std/bytes/1.0.5/ends_with.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/bytes/1.0.5/equals.d.ts +0 -22
- package/types/deps/jsr.io/@std/bytes/1.0.5/equals.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/bytes/1.0.5/includes_needle.d.ts +0 -38
- package/types/deps/jsr.io/@std/bytes/1.0.5/includes_needle.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/bytes/1.0.5/index_of_needle.d.ts +0 -45
- package/types/deps/jsr.io/@std/bytes/1.0.5/index_of_needle.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/bytes/1.0.5/last_index_of_needle.d.ts +0 -42
- package/types/deps/jsr.io/@std/bytes/1.0.5/last_index_of_needle.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/bytes/1.0.5/mod.d.ts +0 -33
- package/types/deps/jsr.io/@std/bytes/1.0.5/mod.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/bytes/1.0.5/repeat.d.ts +0 -33
- package/types/deps/jsr.io/@std/bytes/1.0.5/repeat.d.ts.map +0 -1
- package/types/deps/jsr.io/@std/bytes/1.0.5/starts_with.d.ts +0 -24
- package/types/deps/jsr.io/@std/bytes/1.0.5/starts_with.d.ts.map +0 -1
@@ -1,50 +0,0 @@
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
2
|
-
// This module is browser compatible.
|
3
|
-
/**
|
4
|
-
* Copy bytes from the source array to the destination array and returns the
|
5
|
-
* number of bytes copied.
|
6
|
-
*
|
7
|
-
* If the source array is larger than what the `dst` array can hold, only the
|
8
|
-
* amount of bytes that fit in the `dst` array are copied.
|
9
|
-
*
|
10
|
-
* @param src Source array to copy from.
|
11
|
-
* @param dst Destination array to copy to.
|
12
|
-
* @param offset Offset in the destination array to start copying to. Defaults
|
13
|
-
* to 0.
|
14
|
-
* @returns Number of bytes copied.
|
15
|
-
*
|
16
|
-
* @example Basic usage
|
17
|
-
* ```ts
|
18
|
-
* import { copy } from "@std/bytes/copy";
|
19
|
-
* import { assertEquals } from "@std/assert";
|
20
|
-
*
|
21
|
-
* const src = new Uint8Array([9, 8, 7]);
|
22
|
-
* const dst = new Uint8Array([0, 1, 2, 3, 4, 5]);
|
23
|
-
*
|
24
|
-
* assertEquals(copy(src, dst), 3);
|
25
|
-
* assertEquals(dst, new Uint8Array([9, 8, 7, 3, 4, 5]));
|
26
|
-
* ```
|
27
|
-
*
|
28
|
-
* @example Copy with offset
|
29
|
-
* ```ts
|
30
|
-
* import { copy } from "@std/bytes/copy";
|
31
|
-
* import { assertEquals } from "@std/assert";
|
32
|
-
*
|
33
|
-
* const src = new Uint8Array([1, 1, 1, 1]);
|
34
|
-
* const dst = new Uint8Array([0, 0, 0, 0]);
|
35
|
-
*
|
36
|
-
* assertEquals(copy(src, dst, 1), 3);
|
37
|
-
* assertEquals(dst, new Uint8Array([0, 1, 1, 1]));
|
38
|
-
* ```
|
39
|
-
* Defining an offset will start copying at the specified index in the
|
40
|
-
* destination array.
|
41
|
-
*/
|
42
|
-
export function copy(src, dst, offset = 0) {
|
43
|
-
offset = Math.max(0, Math.min(offset, dst.byteLength));
|
44
|
-
const dstBytesAvailable = dst.byteLength - offset;
|
45
|
-
if (src.byteLength > dstBytesAvailable) {
|
46
|
-
src = src.subarray(0, dstBytesAvailable);
|
47
|
-
}
|
48
|
-
dst.set(src, offset);
|
49
|
-
return src.byteLength;
|
50
|
-
}
|
@@ -1,36 +0,0 @@
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
2
|
-
// This module is browser compatible.
|
3
|
-
/**
|
4
|
-
* Returns `true` if the suffix array appears at the end of the source array,
|
5
|
-
* `false` otherwise.
|
6
|
-
*
|
7
|
-
* The complexity of this function is `O(suffix.length)`.
|
8
|
-
*
|
9
|
-
* @param source Source array to check.
|
10
|
-
* @param suffix Suffix array to check for.
|
11
|
-
* @returns `true` if the suffix array appears at the end of the source array,
|
12
|
-
* `false` otherwise.
|
13
|
-
*
|
14
|
-
* @example Basic usage
|
15
|
-
* ```ts
|
16
|
-
* import { endsWith } from "@std/bytes/ends-with";
|
17
|
-
* import { assertEquals } from "@std/assert";
|
18
|
-
*
|
19
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
20
|
-
* const suffix = new Uint8Array([1, 2, 3]);
|
21
|
-
*
|
22
|
-
* assertEquals(endsWith(source, suffix), true);
|
23
|
-
* ```
|
24
|
-
*/
|
25
|
-
export function endsWith(source, suffix) {
|
26
|
-
const diff = source.length - suffix.length;
|
27
|
-
if (diff < 0) {
|
28
|
-
return false;
|
29
|
-
}
|
30
|
-
for (let i = suffix.length - 1; i >= 0; i--) {
|
31
|
-
if (source[diff + i] !== suffix[i]) {
|
32
|
-
return false;
|
33
|
-
}
|
34
|
-
}
|
35
|
-
return true;
|
36
|
-
}
|
@@ -1,82 +0,0 @@
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
2
|
-
// This module is browser compatible.
|
3
|
-
/**
|
4
|
-
* Check whether byte slices are equal to each other using 8-bit comparisons.
|
5
|
-
*
|
6
|
-
* @param a First array to check equality
|
7
|
-
* @param b Second array to check equality
|
8
|
-
* @returns `true` if the arrays are equal, `false` otherwise
|
9
|
-
*
|
10
|
-
* @private
|
11
|
-
*/
|
12
|
-
function equalsNaive(a, b) {
|
13
|
-
for (let i = 0; i < b.length; i++) {
|
14
|
-
if (a[i] !== b[i])
|
15
|
-
return false;
|
16
|
-
}
|
17
|
-
return true;
|
18
|
-
}
|
19
|
-
/** Check whether byte slices are equal to each other using 32-bit comparisons.
|
20
|
-
*
|
21
|
-
* @param a First array to check equality.
|
22
|
-
* @param b Second array to check equality.
|
23
|
-
* @returns `true` if the arrays are equal, `false` otherwise.
|
24
|
-
*
|
25
|
-
* @private
|
26
|
-
*/
|
27
|
-
function equals32Bit(a, b) {
|
28
|
-
const len = a.length;
|
29
|
-
const compactOffset = 3 - ((a.byteOffset + 3) % 4);
|
30
|
-
const compactLen = Math.floor((len - compactOffset) / 4);
|
31
|
-
const compactA = new Uint32Array(a.buffer, a.byteOffset + compactOffset, compactLen);
|
32
|
-
const compactB = new Uint32Array(b.buffer, b.byteOffset + compactOffset, compactLen);
|
33
|
-
for (let i = 0; i < compactOffset; i++) {
|
34
|
-
if (a[i] !== b[i])
|
35
|
-
return false;
|
36
|
-
}
|
37
|
-
for (let i = 0; i < compactA.length; i++) {
|
38
|
-
if (compactA[i] !== compactB[i])
|
39
|
-
return false;
|
40
|
-
}
|
41
|
-
for (let i = compactOffset + compactLen * 4; i < len; i++) {
|
42
|
-
if (a[i] !== b[i])
|
43
|
-
return false;
|
44
|
-
}
|
45
|
-
return true;
|
46
|
-
}
|
47
|
-
/**
|
48
|
-
* Byte length threshold for when to use 32-bit comparisons, based on
|
49
|
-
* benchmarks.
|
50
|
-
*
|
51
|
-
* @see {@link https://github.com/denoland/deno_std/pull/4635}
|
52
|
-
*/
|
53
|
-
const THRESHOLD_32_BIT = 160;
|
54
|
-
/**
|
55
|
-
* Check whether byte slices are equal to each other.
|
56
|
-
*
|
57
|
-
* @param a First array to check equality.
|
58
|
-
* @param b Second array to check equality.
|
59
|
-
* @returns `true` if the arrays are equal, `false` otherwise.
|
60
|
-
*
|
61
|
-
* @example Basic usage
|
62
|
-
* ```ts
|
63
|
-
* import { equals } from "@std/bytes/equals";
|
64
|
-
* import { assertEquals } from "@std/assert";
|
65
|
-
*
|
66
|
-
* const a = new Uint8Array([1, 2, 3]);
|
67
|
-
* const b = new Uint8Array([1, 2, 3]);
|
68
|
-
* const c = new Uint8Array([4, 5, 6]);
|
69
|
-
*
|
70
|
-
* assertEquals(equals(a, b), true);
|
71
|
-
* assertEquals(equals(a, c), false);
|
72
|
-
* ```
|
73
|
-
*/
|
74
|
-
export function equals(a, b) {
|
75
|
-
if (a.length !== b.length) {
|
76
|
-
return false;
|
77
|
-
}
|
78
|
-
return a.length >= THRESHOLD_32_BIT &&
|
79
|
-
(a.byteOffset % 4) === (b.byteOffset % 4)
|
80
|
-
? equals32Bit(a, b)
|
81
|
-
: equalsNaive(a, b);
|
82
|
-
}
|
@@ -1,42 +0,0 @@
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
2
|
-
// This module is browser compatible.
|
3
|
-
import { indexOfNeedle } from "./index_of_needle.js";
|
4
|
-
/**
|
5
|
-
* Determines whether the source array contains the needle array.
|
6
|
-
*
|
7
|
-
* The complexity of this function is `O(source.length * needle.length)`.
|
8
|
-
*
|
9
|
-
* @param source Source array to check.
|
10
|
-
* @param needle Needle array to check for.
|
11
|
-
* @param start Start index in the source array to begin the search. Defaults to
|
12
|
-
* 0.
|
13
|
-
* @returns `true` if the source array contains the needle array, `false`
|
14
|
-
* otherwise.
|
15
|
-
*
|
16
|
-
* @example Basic usage
|
17
|
-
* ```ts
|
18
|
-
* import { includesNeedle } from "@std/bytes/includes-needle";
|
19
|
-
* import { assertEquals } from "@std/assert";
|
20
|
-
*
|
21
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
22
|
-
* const needle = new Uint8Array([1, 2]);
|
23
|
-
*
|
24
|
-
* assertEquals(includesNeedle(source, needle), true);
|
25
|
-
* ```
|
26
|
-
*
|
27
|
-
* @example Start index
|
28
|
-
* ```ts
|
29
|
-
* import { includesNeedle } from "@std/bytes/includes-needle";
|
30
|
-
* import { assertEquals } from "@std/assert";
|
31
|
-
*
|
32
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
33
|
-
* const needle = new Uint8Array([1, 2]);
|
34
|
-
*
|
35
|
-
* assertEquals(includesNeedle(source, needle, 3), true);
|
36
|
-
* assertEquals(includesNeedle(source, needle, 6), false);
|
37
|
-
* ```
|
38
|
-
* The search will start at the specified index in the source array.
|
39
|
-
*/
|
40
|
-
export function includesNeedle(source, needle, start = 0) {
|
41
|
-
return indexOfNeedle(source, needle, start) !== -1;
|
42
|
-
}
|
@@ -1,68 +0,0 @@
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
2
|
-
// This module is browser compatible.
|
3
|
-
/**
|
4
|
-
* Returns the index of the first occurrence of the needle array in the source
|
5
|
-
* array, or -1 if it is not present.
|
6
|
-
*
|
7
|
-
* A start index can be specified as the third argument that begins the search
|
8
|
-
* at that given index. The start index defaults to the start of the array.
|
9
|
-
*
|
10
|
-
* The complexity of this function is `O(source.length * needle.length)`.
|
11
|
-
*
|
12
|
-
* @param source Source array to check.
|
13
|
-
* @param needle Needle array to check for.
|
14
|
-
* @param start Start index in the source array to begin the search. Defaults to
|
15
|
-
* 0.
|
16
|
-
* @returns Index of the first occurrence of the needle array in the source
|
17
|
-
* array, or -1 if it is not present.
|
18
|
-
*
|
19
|
-
* @example Basic usage
|
20
|
-
* ```ts
|
21
|
-
* import { indexOfNeedle } from "@std/bytes/index-of-needle";
|
22
|
-
* import { assertEquals } from "@std/assert";
|
23
|
-
*
|
24
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
25
|
-
* const needle = new Uint8Array([1, 2]);
|
26
|
-
* const notNeedle = new Uint8Array([5, 0]);
|
27
|
-
*
|
28
|
-
* assertEquals(indexOfNeedle(source, needle), 1);
|
29
|
-
* assertEquals(indexOfNeedle(source, notNeedle), -1);
|
30
|
-
* ```
|
31
|
-
*
|
32
|
-
* @example Start index
|
33
|
-
* ```ts
|
34
|
-
* import { indexOfNeedle } from "@std/bytes/index-of-needle";
|
35
|
-
* import { assertEquals } from "@std/assert";
|
36
|
-
*
|
37
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
38
|
-
* const needle = new Uint8Array([1, 2]);
|
39
|
-
*
|
40
|
-
* assertEquals(indexOfNeedle(source, needle, 2), 3);
|
41
|
-
* assertEquals(indexOfNeedle(source, needle, 6), -1);
|
42
|
-
* ```
|
43
|
-
* Defining a start index will begin the search at the specified index in the
|
44
|
-
* source array.
|
45
|
-
*/
|
46
|
-
export function indexOfNeedle(source, needle, start = 0) {
|
47
|
-
if (start < 0) {
|
48
|
-
start = Math.max(0, source.length + start);
|
49
|
-
}
|
50
|
-
if (needle.length > source.length - start) {
|
51
|
-
return -1;
|
52
|
-
}
|
53
|
-
const s = needle[0];
|
54
|
-
for (let i = start; i < source.length; i++) {
|
55
|
-
if (source[i] !== s)
|
56
|
-
continue;
|
57
|
-
let matched = 1;
|
58
|
-
let j = i + 1;
|
59
|
-
while (matched < needle.length && source[j] === needle[j - i]) {
|
60
|
-
matched++;
|
61
|
-
j++;
|
62
|
-
}
|
63
|
-
if (matched === needle.length) {
|
64
|
-
return i;
|
65
|
-
}
|
66
|
-
}
|
67
|
-
return -1;
|
68
|
-
}
|
@@ -1,65 +0,0 @@
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
2
|
-
// This module is browser compatible.
|
3
|
-
/**
|
4
|
-
* Returns the index of the last occurrence of the needle array in the source
|
5
|
-
* array, or -1 if it is not present.
|
6
|
-
*
|
7
|
-
* The complexity of this function is `O(source.length * needle.length)`.
|
8
|
-
*
|
9
|
-
* @param source Source array to check.
|
10
|
-
* @param needle Needle array to check for.
|
11
|
-
* @param start Start index in the source array to begin the search. Defaults to
|
12
|
-
* `source.length - 1`.
|
13
|
-
* @returns Index of the last occurrence of the needle array in the source
|
14
|
-
* array, or -1 if it is not present.
|
15
|
-
*
|
16
|
-
* @example Basic usage
|
17
|
-
* ```ts
|
18
|
-
* import { lastIndexOfNeedle } from "@std/bytes/last-index-of-needle";
|
19
|
-
* import { assertEquals } from "@std/assert";
|
20
|
-
*
|
21
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
22
|
-
* const needle = new Uint8Array([1, 2]);
|
23
|
-
* const notNeedle = new Uint8Array([5, 0]);
|
24
|
-
*
|
25
|
-
* assertEquals(lastIndexOfNeedle(source, needle), 5);
|
26
|
-
* assertEquals(lastIndexOfNeedle(source, notNeedle), -1);
|
27
|
-
* ```
|
28
|
-
*
|
29
|
-
* @example Start index
|
30
|
-
* ```ts
|
31
|
-
* import { lastIndexOfNeedle } from "@std/bytes/last-index-of-needle";
|
32
|
-
* import { assertEquals } from "@std/assert";
|
33
|
-
*
|
34
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
35
|
-
* const needle = new Uint8Array([1, 2]);
|
36
|
-
*
|
37
|
-
* assertEquals(lastIndexOfNeedle(source, needle, 2), 1);
|
38
|
-
* assertEquals(lastIndexOfNeedle(source, needle, 6), 5);
|
39
|
-
* ```
|
40
|
-
* Defining a start index will begin the search at the specified index in the
|
41
|
-
* source array.
|
42
|
-
*/
|
43
|
-
export function lastIndexOfNeedle(source, needle, start = source.length - 1) {
|
44
|
-
if (start < 0) {
|
45
|
-
return -1;
|
46
|
-
}
|
47
|
-
if (start >= source.length) {
|
48
|
-
start = source.length - 1;
|
49
|
-
}
|
50
|
-
const e = needle[needle.length - 1];
|
51
|
-
for (let i = start; i >= 0; i--) {
|
52
|
-
if (source[i] !== e)
|
53
|
-
continue;
|
54
|
-
let matched = 1;
|
55
|
-
let j = i;
|
56
|
-
while (matched < needle.length &&
|
57
|
-
source[--j] === needle[needle.length - 1 - (i - j)]) {
|
58
|
-
matched++;
|
59
|
-
}
|
60
|
-
if (matched === needle.length) {
|
61
|
-
return i - needle.length + 1;
|
62
|
-
}
|
63
|
-
}
|
64
|
-
return -1;
|
65
|
-
}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
2
|
-
// This module is browser compatible.
|
3
|
-
/**
|
4
|
-
* Helper functions for working with
|
5
|
-
* {@linkcode https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array | Uint8Array}
|
6
|
-
* byte slices.
|
7
|
-
*
|
8
|
-
* ```ts
|
9
|
-
* import { concat, indexOfNeedle, endsWith } from "@std/bytes";
|
10
|
-
* import { assertEquals } from "@std/assert";
|
11
|
-
*
|
12
|
-
* const a = new Uint8Array([0, 1, 2]);
|
13
|
-
* const b = new Uint8Array([3, 4, 5]);
|
14
|
-
*
|
15
|
-
* const c = concat([a, b]);
|
16
|
-
*
|
17
|
-
* assertEquals(c, new Uint8Array([0, 1, 2, 3, 4, 5]));
|
18
|
-
*
|
19
|
-
* assertEquals(indexOfNeedle(c, new Uint8Array([2, 3])), 2);
|
20
|
-
*
|
21
|
-
* assertEquals(endsWith(c, b), true);
|
22
|
-
* ```
|
23
|
-
*
|
24
|
-
* @module
|
25
|
-
*/
|
26
|
-
export * from "./concat.js";
|
27
|
-
export * from "./copy.js";
|
28
|
-
export * from "./ends_with.js";
|
29
|
-
export * from "./equals.js";
|
30
|
-
export * from "./includes_needle.js";
|
31
|
-
export * from "./index_of_needle.js";
|
32
|
-
export * from "./last_index_of_needle.js";
|
33
|
-
export * from "./repeat.js";
|
34
|
-
export * from "./starts_with.js";
|
@@ -1,43 +0,0 @@
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
2
|
-
// This module is browser compatible.
|
3
|
-
import { copy } from "./copy.js";
|
4
|
-
/**
|
5
|
-
* Returns a new byte slice composed of `count` repetitions of the `source`
|
6
|
-
* array.
|
7
|
-
*
|
8
|
-
* @param source Source array to repeat.
|
9
|
-
* @param count Number of times to repeat the source array.
|
10
|
-
* @returns A new byte slice composed of `count` repetitions of the `source`
|
11
|
-
* array.
|
12
|
-
*
|
13
|
-
* @example Basic usage
|
14
|
-
* ```ts
|
15
|
-
* import { repeat } from "@std/bytes/repeat";
|
16
|
-
* import { assertEquals } from "@std/assert";
|
17
|
-
*
|
18
|
-
* const source = new Uint8Array([0, 1, 2]);
|
19
|
-
*
|
20
|
-
* assertEquals(repeat(source, 3), new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1, 2]));
|
21
|
-
* ```
|
22
|
-
*
|
23
|
-
* @example Zero count
|
24
|
-
* ```ts
|
25
|
-
* import { repeat } from "@std/bytes/repeat";
|
26
|
-
* import { assertEquals } from "@std/assert";
|
27
|
-
*
|
28
|
-
* const source = new Uint8Array([0, 1, 2]);
|
29
|
-
*
|
30
|
-
* assertEquals(repeat(source, 0), new Uint8Array());
|
31
|
-
* ```
|
32
|
-
*/
|
33
|
-
export function repeat(source, count) {
|
34
|
-
if (count < 0 || !Number.isInteger(count)) {
|
35
|
-
throw new RangeError("Count must be a non-negative integer");
|
36
|
-
}
|
37
|
-
const repeated = new Uint8Array(source.length * count);
|
38
|
-
let offset = 0;
|
39
|
-
while (offset < repeated.length) {
|
40
|
-
offset += copy(source, repeated, offset);
|
41
|
-
}
|
42
|
-
return repeated;
|
43
|
-
}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
// Copyright 2018-2025 the Deno authors. MIT license.
|
2
|
-
// This module is browser compatible.
|
3
|
-
/**
|
4
|
-
* Returns `true` if the prefix array appears at the start of the source array,
|
5
|
-
* `false` otherwise.
|
6
|
-
*
|
7
|
-
* The complexity of this function is `O(prefix.length)`.
|
8
|
-
*
|
9
|
-
* @param source Source array to check.
|
10
|
-
* @param prefix Prefix array to check for.
|
11
|
-
* @returns `true` if the prefix array appears at the start of the source array,
|
12
|
-
* `false` otherwise.
|
13
|
-
*
|
14
|
-
* @example Basic usage
|
15
|
-
* ```ts
|
16
|
-
* import { startsWith } from "@std/bytes/starts-with";
|
17
|
-
* import { assertEquals } from "@std/assert";
|
18
|
-
*
|
19
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
20
|
-
* const prefix = new Uint8Array([0, 1, 2]);
|
21
|
-
*
|
22
|
-
* assertEquals(startsWith(source, prefix), true);
|
23
|
-
* ```
|
24
|
-
*/
|
25
|
-
export function startsWith(source, prefix) {
|
26
|
-
if (prefix.length > source.length) {
|
27
|
-
return false;
|
28
|
-
}
|
29
|
-
for (let i = 0; i < prefix.length; i++) {
|
30
|
-
if (source[i] !== prefix[i])
|
31
|
-
return false;
|
32
|
-
}
|
33
|
-
return true;
|
34
|
-
}
|
@@ -1,41 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copy bytes from the source array to the destination array and returns the
|
3
|
-
* number of bytes copied.
|
4
|
-
*
|
5
|
-
* If the source array is larger than what the `dst` array can hold, only the
|
6
|
-
* amount of bytes that fit in the `dst` array are copied.
|
7
|
-
*
|
8
|
-
* @param src Source array to copy from.
|
9
|
-
* @param dst Destination array to copy to.
|
10
|
-
* @param offset Offset in the destination array to start copying to. Defaults
|
11
|
-
* to 0.
|
12
|
-
* @returns Number of bytes copied.
|
13
|
-
*
|
14
|
-
* @example Basic usage
|
15
|
-
* ```ts
|
16
|
-
* import { copy } from "@std/bytes/copy";
|
17
|
-
* import { assertEquals } from "@std/assert";
|
18
|
-
*
|
19
|
-
* const src = new Uint8Array([9, 8, 7]);
|
20
|
-
* const dst = new Uint8Array([0, 1, 2, 3, 4, 5]);
|
21
|
-
*
|
22
|
-
* assertEquals(copy(src, dst), 3);
|
23
|
-
* assertEquals(dst, new Uint8Array([9, 8, 7, 3, 4, 5]));
|
24
|
-
* ```
|
25
|
-
*
|
26
|
-
* @example Copy with offset
|
27
|
-
* ```ts
|
28
|
-
* import { copy } from "@std/bytes/copy";
|
29
|
-
* import { assertEquals } from "@std/assert";
|
30
|
-
*
|
31
|
-
* const src = new Uint8Array([1, 1, 1, 1]);
|
32
|
-
* const dst = new Uint8Array([0, 0, 0, 0]);
|
33
|
-
*
|
34
|
-
* assertEquals(copy(src, dst, 1), 3);
|
35
|
-
* assertEquals(dst, new Uint8Array([0, 1, 1, 1]));
|
36
|
-
* ```
|
37
|
-
* Defining an offset will start copying at the specified index in the
|
38
|
-
* destination array.
|
39
|
-
*/
|
40
|
-
export declare function copy(src: Uint8Array, dst: Uint8Array, offset?: number): number;
|
41
|
-
//# sourceMappingURL=copy.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"copy.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/bytes/1.0.5/copy.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,SAAI,GAAG,MAAM,CAQzE"}
|
@@ -1,24 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Returns `true` if the suffix array appears at the end of the source array,
|
3
|
-
* `false` otherwise.
|
4
|
-
*
|
5
|
-
* The complexity of this function is `O(suffix.length)`.
|
6
|
-
*
|
7
|
-
* @param source Source array to check.
|
8
|
-
* @param suffix Suffix array to check for.
|
9
|
-
* @returns `true` if the suffix array appears at the end of the source array,
|
10
|
-
* `false` otherwise.
|
11
|
-
*
|
12
|
-
* @example Basic usage
|
13
|
-
* ```ts
|
14
|
-
* import { endsWith } from "@std/bytes/ends-with";
|
15
|
-
* import { assertEquals } from "@std/assert";
|
16
|
-
*
|
17
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
18
|
-
* const suffix = new Uint8Array([1, 2, 3]);
|
19
|
-
*
|
20
|
-
* assertEquals(endsWith(source, suffix), true);
|
21
|
-
* ```
|
22
|
-
*/
|
23
|
-
export declare function endsWith(source: Uint8Array, suffix: Uint8Array): boolean;
|
24
|
-
//# sourceMappingURL=ends_with.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ends_with.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/bytes/1.0.5/ends_with.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAWxE"}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Check whether byte slices are equal to each other.
|
3
|
-
*
|
4
|
-
* @param a First array to check equality.
|
5
|
-
* @param b Second array to check equality.
|
6
|
-
* @returns `true` if the arrays are equal, `false` otherwise.
|
7
|
-
*
|
8
|
-
* @example Basic usage
|
9
|
-
* ```ts
|
10
|
-
* import { equals } from "@std/bytes/equals";
|
11
|
-
* import { assertEquals } from "@std/assert";
|
12
|
-
*
|
13
|
-
* const a = new Uint8Array([1, 2, 3]);
|
14
|
-
* const b = new Uint8Array([1, 2, 3]);
|
15
|
-
* const c = new Uint8Array([4, 5, 6]);
|
16
|
-
*
|
17
|
-
* assertEquals(equals(a, b), true);
|
18
|
-
* assertEquals(equals(a, c), false);
|
19
|
-
* ```
|
20
|
-
*/
|
21
|
-
export declare function equals(a: Uint8Array, b: Uint8Array): boolean;
|
22
|
-
//# sourceMappingURL=equals.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"equals.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/bytes/1.0.5/equals.ts"],"names":[],"mappings":"AA6DA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAQ5D"}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Determines whether the source array contains the needle array.
|
3
|
-
*
|
4
|
-
* The complexity of this function is `O(source.length * needle.length)`.
|
5
|
-
*
|
6
|
-
* @param source Source array to check.
|
7
|
-
* @param needle Needle array to check for.
|
8
|
-
* @param start Start index in the source array to begin the search. Defaults to
|
9
|
-
* 0.
|
10
|
-
* @returns `true` if the source array contains the needle array, `false`
|
11
|
-
* otherwise.
|
12
|
-
*
|
13
|
-
* @example Basic usage
|
14
|
-
* ```ts
|
15
|
-
* import { includesNeedle } from "@std/bytes/includes-needle";
|
16
|
-
* import { assertEquals } from "@std/assert";
|
17
|
-
*
|
18
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
19
|
-
* const needle = new Uint8Array([1, 2]);
|
20
|
-
*
|
21
|
-
* assertEquals(includesNeedle(source, needle), true);
|
22
|
-
* ```
|
23
|
-
*
|
24
|
-
* @example Start index
|
25
|
-
* ```ts
|
26
|
-
* import { includesNeedle } from "@std/bytes/includes-needle";
|
27
|
-
* import { assertEquals } from "@std/assert";
|
28
|
-
*
|
29
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
30
|
-
* const needle = new Uint8Array([1, 2]);
|
31
|
-
*
|
32
|
-
* assertEquals(includesNeedle(source, needle, 3), true);
|
33
|
-
* assertEquals(includesNeedle(source, needle, 6), false);
|
34
|
-
* ```
|
35
|
-
* The search will start at the specified index in the source array.
|
36
|
-
*/
|
37
|
-
export declare function includesNeedle(source: Uint8Array, needle: Uint8Array, start?: number): boolean;
|
38
|
-
//# sourceMappingURL=includes_needle.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"includes_needle.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/bytes/1.0.5/includes_needle.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,UAAU,EAClB,KAAK,SAAI,GACR,OAAO,CAET"}
|
@@ -1,45 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Returns the index of the first occurrence of the needle array in the source
|
3
|
-
* array, or -1 if it is not present.
|
4
|
-
*
|
5
|
-
* A start index can be specified as the third argument that begins the search
|
6
|
-
* at that given index. The start index defaults to the start of the array.
|
7
|
-
*
|
8
|
-
* The complexity of this function is `O(source.length * needle.length)`.
|
9
|
-
*
|
10
|
-
* @param source Source array to check.
|
11
|
-
* @param needle Needle array to check for.
|
12
|
-
* @param start Start index in the source array to begin the search. Defaults to
|
13
|
-
* 0.
|
14
|
-
* @returns Index of the first occurrence of the needle array in the source
|
15
|
-
* array, or -1 if it is not present.
|
16
|
-
*
|
17
|
-
* @example Basic usage
|
18
|
-
* ```ts
|
19
|
-
* import { indexOfNeedle } from "@std/bytes/index-of-needle";
|
20
|
-
* import { assertEquals } from "@std/assert";
|
21
|
-
*
|
22
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
23
|
-
* const needle = new Uint8Array([1, 2]);
|
24
|
-
* const notNeedle = new Uint8Array([5, 0]);
|
25
|
-
*
|
26
|
-
* assertEquals(indexOfNeedle(source, needle), 1);
|
27
|
-
* assertEquals(indexOfNeedle(source, notNeedle), -1);
|
28
|
-
* ```
|
29
|
-
*
|
30
|
-
* @example Start index
|
31
|
-
* ```ts
|
32
|
-
* import { indexOfNeedle } from "@std/bytes/index-of-needle";
|
33
|
-
* import { assertEquals } from "@std/assert";
|
34
|
-
*
|
35
|
-
* const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
|
36
|
-
* const needle = new Uint8Array([1, 2]);
|
37
|
-
*
|
38
|
-
* assertEquals(indexOfNeedle(source, needle, 2), 3);
|
39
|
-
* assertEquals(indexOfNeedle(source, needle, 6), -1);
|
40
|
-
* ```
|
41
|
-
* Defining a start index will begin the search at the specified index in the
|
42
|
-
* source array.
|
43
|
-
*/
|
44
|
-
export declare function indexOfNeedle(source: Uint8Array, needle: Uint8Array, start?: number): number;
|
45
|
-
//# sourceMappingURL=index_of_needle.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index_of_needle.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/bytes/1.0.5/index_of_needle.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,UAAU,EAClB,KAAK,SAAI,GACR,MAAM,CAqBR"}
|