export function parseToken(tokenValue) {
    var parts = tokenValue.split('.');
    if (parts.length !== 3) {
        throw new Error('JWT encoded value must have 3 parts');
    }
    var decodedHeader = base64Decode(parts[0]);
    if (!decodedHeader) {
        throw new Error('Cannot decode the token header');
    }
    var decodedClaims = base64Decode(parts[1]);
    if (!decodedClaims) {
        throw new Error('Cannot decode the token claims');
    }
    var decodedSignature = base64Decode(parts[2]);
    if (!decodedSignature) {
        throw new Error('Cannot decode the token claims');
    }
    var token = {
        header: JSON.parse(decodedHeader),
        claims: JSON.parse(decodedClaims)
    };
    return token;
}
function base64Decode(encodedValue) {
    var output = encodedValue.replace(/-/g, '+').replace(/_/g, '/');
    switch (output.length % 4) {
        case 0:
            break;
        case 2:
            output += '==';
            break;
        case 3:
            output += '=';
            break;
        default:
            throw 'Illegal base64Url string!';
    }
    return window.atob(output);
}
//# sourceMappingURL=jwt-helper.js.map