import { takeSecondItem } from '@angular-ru/cdk/array';
import { isString } from '@angular-ru/cdk/string';
import { tryParseJson } from '@angular-ru/cdk/utils';

function decodeJwt(token) {
    let result = null;
    if (isString(token)) {
        const base64Url = takeSecondItem(token?.split('.')) ?? '';
        const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
        // eslint-disable-next-line deprecation/deprecation
        const decodedStringValue = decodeURIComponent(escape(window.atob(base64)));
        result = tryParseJson(decodedStringValue) ?? null;
    }
    return result;
}

function toBase64(pojo) {
    // eslint-disable-next-line deprecation/deprecation
    return window.btoa(unescape(encodeURIComponent(JSON.stringify(pojo))));
}

/**
 * Generated bundle index. Do not edit.
 */

export { decodeJwt, toBase64 };
//# sourceMappingURL=angular-ru-cdk-stream-jwt.mjs.map
