deno.land / std@0.224.0 / encoding / _util.ts

View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
const encoder = new TextEncoder();
function getTypeName(value: unknown): string { const type = typeof value; if (type !== "object") { return type; } else if (value === null) { return "null"; } else { return value?.constructor?.name ?? "object"; }}
export function validateBinaryLike(source: unknown): Uint8Array { if (typeof source === "string") { return encoder.encode(source); } else if (source instanceof Uint8Array) { return source; } else if (source instanceof ArrayBuffer) { return new Uint8Array(source); } throw new TypeError( `The input must be a Uint8Array, a string, or an ArrayBuffer. Received a value of the type ${ getTypeName(source) }.`, );}
std

Version Info

Tagged at
6 months ago