Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function convertToBuffer(data: SourceData): Uint8Array {
if (typeof data === 'string') {
return fromUtf8(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(
data.buffer,
data.byteOffset,
data.byteLength / Uint8Array.BYTES_PER_ELEMENT
);
}
return new Uint8Array(data);
}
function toArrayBufferView(data: SourceData): Uint8Array {
if (typeof data === 'string') {
return fromUtf8(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(
data.buffer,
data.byteOffset,
data.byteLength / Uint8Array.BYTES_PER_ELEMENT
);
}
return new Uint8Array(data);
}
function convertToBuffer(data: SourceData): Uint8Array {
if (typeof data === 'string') {
return fromUtf8(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(
data.buffer,
data.byteOffset,
data.byteLength / Uint8Array.BYTES_PER_ELEMENT
);
}
return new Uint8Array(data);
}
function convertToBuffer(data: SourceData): Uint8Array {
if (typeof data === "string") {
return fromUtf8(data);
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(
data.buffer,
data.byteOffset,
data.byteLength / Uint8Array.BYTES_PER_ELEMENT
);
}
return new Uint8Array(data);
}
export function toUtf8(input: Uint8Array): string {
if (isNode()) {
return nodeToUtf8(input);
}
return browserToUtf8(input);
}