@pothos/core
Version:
Pothos (formerly GiraphQL) is a plugin based schema builder for creating code-first GraphQL schemas in typescript
66 lines (65 loc) • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: Object.getOwnPropertyDescriptor(all, name).get
});
}
_export(exports, {
get decodeBase64 () {
return decodeBase64;
},
get encodeBase64 () {
return encodeBase64;
}
});
const _errors = require("../errors");
const getGlobalThis = ()=>{
if (typeof globalThis !== 'undefined') {
return globalThis;
}
// biome-ignore lint/style/noRestrictedGlobals: this is fine
if (typeof self !== 'undefined') {
// biome-ignore lint/style/noRestrictedGlobals: this is fine
return self;
}
// @ts-ignore
if (typeof window !== 'undefined') {
return window;
}
if (typeof global !== 'undefined') {
return global;
}
if (void 0 !== undefined) {
return void 0;
}
throw new Error('Unable to locate global `this`');
};
function encodeBase64(value) {
const localGlobalThis = getGlobalThis();
if (typeof localGlobalThis.Buffer === 'function') {
return localGlobalThis.Buffer.from(value).toString('base64');
}
if (typeof localGlobalThis.btoa === 'function') {
return localGlobalThis.btoa(value);
}
throw new Error('Unable to locate global `Buffer` or `btoa`');
}
const base64Regex = /^(?:[\d+/A-Za-z]{4})*(?:[\d+/A-Za-z]{2}==|[\d+/A-Za-z]{3}=)?$/;
function decodeBase64(value) {
if (!base64Regex.test(value)) {
throw new _errors.PothosValidationError('Invalid base64 string');
}
const localGlobalThis = getGlobalThis();
if (typeof localGlobalThis.Buffer === 'function') {
return localGlobalThis.Buffer.from(value, 'base64').toString();
}
if (typeof localGlobalThis.atob === 'function') {
return localGlobalThis.atob(value);
}
throw new Error('Unable to locate global `Buffer` or `atob`');
}
//# sourceMappingURL=base64.js.map