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

function decodeJwt(token) {
    var _a, _b;
    let result = null;
    if (isString(token)) {
        const base64Url = (_a = takeSecondItem(token === null || token === void 0 ? void 0 : token.split('.'))) !== null && _a !== void 0 ? _a : '';
        const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
        // eslint-disable-next-line deprecation/deprecation
        const decodedStringValue = decodeURIComponent(escape(window.atob(base64)));
        result = (_b = tryParseJson(decodedStringValue)) !== null && _b !== void 0 ? _b : 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
