@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
38 lines • 1.47 kB
JavaScript
;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromBase64 = exports.toBase64 = void 0;
const error_1 = require("../../core/error.js");
const bytes_1 = require("./bytes.js");
const toBase64 = (data) => {
if (!data)
return '';
if (typeof globalThis.Buffer !== 'undefined') {
return globalThis.Buffer.from(data).toString('base64');
}
if (typeof data === 'string') {
data = (0, bytes_1.encodeUTF8)(data);
}
if (typeof btoa !== 'undefined') {
return btoa(String.fromCharCode.apply(null, data));
}
throw new error_1.AnthropicError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
};
exports.toBase64 = toBase64;
const fromBase64 = (str) => {
if (typeof globalThis.Buffer !== 'undefined') {
const buf = globalThis.Buffer.from(str, 'base64');
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
}
if (typeof atob !== 'undefined') {
const bstr = atob(str);
const buf = new Uint8Array(bstr.length);
for (let i = 0; i < bstr.length; i++) {
buf[i] = bstr.charCodeAt(i);
}
return buf;
}
throw new error_1.AnthropicError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
};
exports.fromBase64 = fromBase64;
//# sourceMappingURL=base64.js.map