impl startswith
This commit is contained in:
@@ -59,6 +59,17 @@ DataView.prototype.writeString = function (str) {
|
|||||||
const bytes = [...str].map((_, i) => str.charCodeAt(i));
|
const bytes = [...str].map((_, i) => str.charCodeAt(i));
|
||||||
return this.writeByteArray(bytes);
|
return this.writeByteArray(bytes);
|
||||||
};
|
};
|
||||||
|
DataView.prototype.startsWith = function (arr) {
|
||||||
|
if (this.byteLength < arr.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < arr.length; i++) {
|
||||||
|
if (this.add(i).readU8() != arr[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface DataView {
|
interface DataView {
|
||||||
@@ -77,6 +88,7 @@ declare global {
|
|||||||
writeU32(n: number): void;
|
writeU32(n: number): void;
|
||||||
writeU64(n: bigint): void;
|
writeU64(n: bigint): void;
|
||||||
writeU8(n: number): void;
|
writeU8(n: number): void;
|
||||||
|
startsWith(arr: number[]): boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default global;
|
export default global;
|
||||||
|
|||||||
Reference in New Issue
Block a user