Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function encodeBinaryString(str) {
// first we use encodeURIComponent to get percent-encoded UTF-8,
// then we convert the percent encodings into raw bytes which
// can be fed into btoa.
const input = encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (m, p) => `0x${p}`);
return Base64.btoa(input);
}
/*
export function encodeBinaryString(str: string): string {
// first we use encodeURIComponent to get percent-encoded UTF-8,
// then we convert the percent encodings into raw bytes which
// can be fed into btoa.
const input = encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (m, p) => `0x${p}`);
return Base64.btoa(input);
}
export function isBase64(str: string) {
if (str === '' || str.trim() === '') { return false }
try {
return Base64.btoa(Base64.atob(str)) == str
} catch (err) {
return false
}
}
const JSONToNative = value => {
const input = encodeURIComponent(value).replace(/%([0-9A-F]{2})/g, (m, p) => `0x${p}`);
return Base64.btoa(input);
};
const nativeToJSON = value => {
function createAuthorizationHeaderValue(config) {
const {
authType, email, password, zendeskAdminToken,
} = config;
switch (authType) {
case AUTH_TYPES.BASIC_AUTH:
return `Basic ${Base64.btoa(`${email}:${password}`)}`;
case AUTH_TYPES.API_TOKEN:
return `Basic ${Base64.btoa(`${email}/token:${zendeskAdminToken}`)}`;
case AUTH_TYPES.API_TOKEN_BASE64_ENCODED:
return `Basic ${zendeskAdminToken}`;
default:
case AUTH_TYPES.OAUTH_ACCESS_TOKEN:
return `Bearer ${zendeskAdminToken}`;
}
}
export const b64encodeByte = (str) => {
return Base64.btoa(str)
}
toBase64(): string {
return Base64.btoa(this._binaryString);
}