@deno/kv
Version:
A Deno KV client library optimized for Node.js.
31 lines (30 loc) • 952 B
JavaScript
;
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateBinaryLike = void 0;
const encoder = new TextEncoder();
function getTypeName(value) {
const type = typeof value;
if (type !== "object") {
return type;
}
else if (value === null) {
return "null";
}
else {
return value?.constructor?.name ?? "object";
}
}
function validateBinaryLike(source) {
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)}.`);
}
exports.validateBinaryLike = validateBinaryLike;