@visulima/bytes 1.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.
@@ -0,0 +1,287 @@
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_ };
package/dist/index.mjs ADDED
@@ -0,0 +1,59 @@
1
+ import { Buffer } from 'node:buffer';
2
+ export { concat } from './packem_shared/concat-CrMUrqFR.mjs';
3
+ export { copy } from './packem_shared/copy-DrPnASpi.mjs';
4
+ export { endsWith } from './packem_shared/endsWith-0SUmpwo5.mjs';
5
+ export { equals } from './packem_shared/equals-QKFTA-PW.mjs';
6
+ export { includesNeedle } from './packem_shared/includesNeedle-DrBfDWAu.mjs';
7
+ export { indexOfNeedle } from './packem_shared/indexOfNeedle-DNPShVZm.mjs';
8
+ export { lastIndexOfNeedle } from './packem_shared/lastIndexOfNeedle-YY1XC9fo.mjs';
9
+ export { repeat } from './packem_shared/repeat-D9RZrtYr.mjs';
10
+ export { startsWith } from './packem_shared/startsWith-CC5eK1Xp.mjs';
11
+
12
+ var __defProp = Object.defineProperty;
13
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
+ const bufferToUint8Array = /* @__PURE__ */ __name((buf) => new Uint8Array(buf.buffer, buf.byteOffset, buf.length), "bufferToUint8Array");
15
+ const isUint8Array = typeof Buffer === "function" ? (x) => x instanceof Uint8Array || Buffer.isBuffer(x) : (x) => x instanceof Uint8Array;
16
+ const asciiToUint8Array = /* @__PURE__ */ __name((txt) => {
17
+ if (typeof txt === "string")
18
+ return asciiToUint8Array([txt]);
19
+ const [input] = Array.isArray(txt) ? txt : [String.raw(txt)];
20
+ const inputLength = input.length;
21
+ const result = new Uint8Array(inputLength);
22
+ for (let index = 0; index < inputLength; index += 1) {
23
+ result[index] = input.charCodeAt(index) & 255;
24
+ }
25
+ return result;
26
+ }, "asciiToUint8Array");
27
+ const utf8ToUint8Array = /* @__PURE__ */ __name((txt) => {
28
+ if (typeof txt === "string")
29
+ return utf8ToUint8Array([txt]);
30
+ const [input] = Array.isArray(txt) ? txt : [String.raw(txt)];
31
+ return bufferToUint8Array(Buffer.from(input, "utf8"));
32
+ }, "utf8ToUint8Array");
33
+ const toUint8Array = /* @__PURE__ */ __name((data) => {
34
+ if (typeof Buffer === "function" && Buffer.isBuffer(data)) {
35
+ return bufferToUint8Array(data);
36
+ }
37
+ if (data instanceof Uint8Array) {
38
+ return data;
39
+ }
40
+ if (data instanceof ArrayBuffer)
41
+ return new Uint8Array(data);
42
+ if (Array.isArray(data) && data.every((item) => typeof item === "number")) {
43
+ return new Uint8Array(data);
44
+ }
45
+ if (typeof Buffer === "function") {
46
+ if (Buffer.isBuffer(data)) {
47
+ return bufferToUint8Array(data);
48
+ }
49
+ if (typeof data === "string") {
50
+ try {
51
+ return bufferToUint8Array(Buffer.from(data));
52
+ } catch {
53
+ }
54
+ }
55
+ }
56
+ throw new Error("UINT8ARRAY_INCOMPATIBLE: Cannot convert data to Uint8Array");
57
+ }, "toUint8Array");
58
+
59
+ export { asciiToUint8Array, bufferToUint8Array, isUint8Array, toUint8Array, utf8ToUint8Array };
@@ -0,0 +1,18 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function concat(buffers) {
4
+ let length = 0;
5
+ for (const buffer of buffers) {
6
+ length += buffer.length;
7
+ }
8
+ const output = new Uint8Array(length);
9
+ let index = 0;
10
+ for (const buffer of buffers) {
11
+ output.set(buffer, index);
12
+ index += buffer.length;
13
+ }
14
+ return output;
15
+ }
16
+ __name(concat, "concat");
17
+
18
+ export { concat };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ function concat(buffers) {
8
+ let length = 0;
9
+ for (const buffer of buffers) {
10
+ length += buffer.length;
11
+ }
12
+ const output = new Uint8Array(length);
13
+ let index = 0;
14
+ for (const buffer of buffers) {
15
+ output.set(buffer, index);
16
+ index += buffer.length;
17
+ }
18
+ return output;
19
+ }
20
+ __name(concat, "concat");
21
+
22
+ exports.concat = concat;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ function copy(src, dst, offset = 0) {
8
+ offset = Math.max(0, Math.min(offset, dst.byteLength));
9
+ const dstBytesAvailable = dst.byteLength - offset;
10
+ if (src.byteLength > dstBytesAvailable) {
11
+ src = src.subarray(0, dstBytesAvailable);
12
+ }
13
+ dst.set(src, offset);
14
+ return src.byteLength;
15
+ }
16
+ __name(copy, "copy");
17
+
18
+ exports.copy = copy;
@@ -0,0 +1,14 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function copy(src, dst, offset = 0) {
4
+ offset = Math.max(0, Math.min(offset, dst.byteLength));
5
+ const dstBytesAvailable = dst.byteLength - offset;
6
+ if (src.byteLength > dstBytesAvailable) {
7
+ src = src.subarray(0, dstBytesAvailable);
8
+ }
9
+ dst.set(src, offset);
10
+ return src.byteLength;
11
+ }
12
+ __name(copy, "copy");
13
+
14
+ export { copy };
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function endsWith(source, suffix) {
4
+ const diff = source.length - suffix.length;
5
+ if (diff < 0) {
6
+ return false;
7
+ }
8
+ for (let i = suffix.length - 1; i >= 0; i--) {
9
+ if (source[diff + i] !== suffix[i]) {
10
+ return false;
11
+ }
12
+ }
13
+ return true;
14
+ }
15
+ __name(endsWith, "endsWith");
16
+
17
+ export { endsWith };
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ function endsWith(source, suffix) {
8
+ const diff = source.length - suffix.length;
9
+ if (diff < 0) {
10
+ return false;
11
+ }
12
+ for (let i = suffix.length - 1; i >= 0; i--) {
13
+ if (source[diff + i] !== suffix[i]) {
14
+ return false;
15
+ }
16
+ }
17
+ return true;
18
+ }
19
+ __name(endsWith, "endsWith");
20
+
21
+ exports.endsWith = endsWith;
@@ -0,0 +1,37 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function equalsNaive(a, b) {
4
+ for (let i = 0; i < b.length; i++) {
5
+ if (a[i] !== b[i]) return false;
6
+ }
7
+ return true;
8
+ }
9
+ __name(equalsNaive, "equalsNaive");
10
+ function equals32Bit(a, b) {
11
+ const len = a.length;
12
+ const compactOffset = 3 - (a.byteOffset + 3) % 4;
13
+ const compactLen = Math.floor((len - compactOffset) / 4);
14
+ const compactA = new Uint32Array(a.buffer, a.byteOffset + compactOffset, compactLen);
15
+ const compactB = new Uint32Array(b.buffer, b.byteOffset + compactOffset, compactLen);
16
+ for (let i = 0; i < compactOffset; i++) {
17
+ if (a[i] !== b[i]) return false;
18
+ }
19
+ for (let i = 0; i < compactA.length; i++) {
20
+ if (compactA[i] !== compactB[i]) return false;
21
+ }
22
+ for (let i = compactOffset + compactLen * 4; i < len; i++) {
23
+ if (a[i] !== b[i]) return false;
24
+ }
25
+ return true;
26
+ }
27
+ __name(equals32Bit, "equals32Bit");
28
+ const THRESHOLD_32_BIT = 160;
29
+ function equals(a, b) {
30
+ if (a.length !== b.length) {
31
+ return false;
32
+ }
33
+ return a.length >= THRESHOLD_32_BIT && a.byteOffset % 4 === b.byteOffset % 4 ? equals32Bit(a, b) : equalsNaive(a, b);
34
+ }
35
+ __name(equals, "equals");
36
+
37
+ export { equals };
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ function equalsNaive(a, b) {
8
+ for (let i = 0; i < b.length; i++) {
9
+ if (a[i] !== b[i]) return false;
10
+ }
11
+ return true;
12
+ }
13
+ __name(equalsNaive, "equalsNaive");
14
+ function equals32Bit(a, b) {
15
+ const len = a.length;
16
+ const compactOffset = 3 - (a.byteOffset + 3) % 4;
17
+ const compactLen = Math.floor((len - compactOffset) / 4);
18
+ const compactA = new Uint32Array(a.buffer, a.byteOffset + compactOffset, compactLen);
19
+ const compactB = new Uint32Array(b.buffer, b.byteOffset + compactOffset, compactLen);
20
+ for (let i = 0; i < compactOffset; i++) {
21
+ if (a[i] !== b[i]) return false;
22
+ }
23
+ for (let i = 0; i < compactA.length; i++) {
24
+ if (compactA[i] !== compactB[i]) return false;
25
+ }
26
+ for (let i = compactOffset + compactLen * 4; i < len; i++) {
27
+ if (a[i] !== b[i]) return false;
28
+ }
29
+ return true;
30
+ }
31
+ __name(equals32Bit, "equals32Bit");
32
+ const THRESHOLD_32_BIT = 160;
33
+ function equals(a, b) {
34
+ if (a.length !== b.length) {
35
+ return false;
36
+ }
37
+ return a.length >= THRESHOLD_32_BIT && a.byteOffset % 4 === b.byteOffset % 4 ? equals32Bit(a, b) : equalsNaive(a, b);
38
+ }
39
+ __name(equals, "equals");
40
+
41
+ exports.equals = equals;
@@ -0,0 +1,10 @@
1
+ import { indexOfNeedle } from './indexOfNeedle-DNPShVZm.mjs';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ function includesNeedle(source, needle, start = 0) {
6
+ return indexOfNeedle(source, needle, start) !== -1;
7
+ }
8
+ __name(includesNeedle, "includesNeedle");
9
+
10
+ export { includesNeedle };
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ const indexOfNeedle = require('./indexOfNeedle-ByhaFu9G.cjs');
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ function includesNeedle(source, needle, start = 0) {
10
+ return indexOfNeedle.indexOfNeedle(source, needle, start) !== -1;
11
+ }
12
+ __name(includesNeedle, "includesNeedle");
13
+
14
+ exports.includesNeedle = includesNeedle;
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ function indexOfNeedle(source, needle, start = 0) {
8
+ if (start < 0) {
9
+ start = Math.max(0, source.length + start);
10
+ }
11
+ if (needle.length > source.length - start) {
12
+ return -1;
13
+ }
14
+ const s = needle[0];
15
+ for (let i = start; i < source.length; i++) {
16
+ if (source[i] !== s) continue;
17
+ let matched = 1;
18
+ let j = i + 1;
19
+ while (matched < needle.length && source[j] === needle[j - i]) {
20
+ matched++;
21
+ j++;
22
+ }
23
+ if (matched === needle.length) {
24
+ return i;
25
+ }
26
+ }
27
+ return -1;
28
+ }
29
+ __name(indexOfNeedle, "indexOfNeedle");
30
+
31
+ exports.indexOfNeedle = indexOfNeedle;
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function indexOfNeedle(source, needle, start = 0) {
4
+ if (start < 0) {
5
+ start = Math.max(0, source.length + start);
6
+ }
7
+ if (needle.length > source.length - start) {
8
+ return -1;
9
+ }
10
+ const s = needle[0];
11
+ for (let i = start; i < source.length; i++) {
12
+ if (source[i] !== s) continue;
13
+ let matched = 1;
14
+ let j = i + 1;
15
+ while (matched < needle.length && source[j] === needle[j - i]) {
16
+ matched++;
17
+ j++;
18
+ }
19
+ if (matched === needle.length) {
20
+ return i;
21
+ }
22
+ }
23
+ return -1;
24
+ }
25
+ __name(indexOfNeedle, "indexOfNeedle");
26
+
27
+ export { indexOfNeedle };
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ function lastIndexOfNeedle(source, needle, start = source.length - 1) {
8
+ if (start < 0) {
9
+ return -1;
10
+ }
11
+ if (start >= source.length) {
12
+ start = source.length - 1;
13
+ }
14
+ const e = needle[needle.length - 1];
15
+ for (let i = start; i >= 0; i--) {
16
+ if (source[i] !== e) continue;
17
+ let matched = 1;
18
+ let j = i;
19
+ while (matched < needle.length && source[--j] === needle[needle.length - 1 - (i - j)]) {
20
+ matched++;
21
+ }
22
+ if (matched === needle.length) {
23
+ return i - needle.length + 1;
24
+ }
25
+ }
26
+ return -1;
27
+ }
28
+ __name(lastIndexOfNeedle, "lastIndexOfNeedle");
29
+
30
+ exports.lastIndexOfNeedle = lastIndexOfNeedle;
@@ -0,0 +1,26 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function lastIndexOfNeedle(source, needle, start = source.length - 1) {
4
+ if (start < 0) {
5
+ return -1;
6
+ }
7
+ if (start >= source.length) {
8
+ start = source.length - 1;
9
+ }
10
+ const e = needle[needle.length - 1];
11
+ for (let i = start; i >= 0; i--) {
12
+ if (source[i] !== e) continue;
13
+ let matched = 1;
14
+ let j = i;
15
+ while (matched < needle.length && source[--j] === needle[needle.length - 1 - (i - j)]) {
16
+ matched++;
17
+ }
18
+ if (matched === needle.length) {
19
+ return i - needle.length + 1;
20
+ }
21
+ }
22
+ return -1;
23
+ }
24
+ __name(lastIndexOfNeedle, "lastIndexOfNeedle");
25
+
26
+ export { lastIndexOfNeedle };