UNPKG

@splitsoftware/splitio-commons

Version:
18 lines (17 loc) 735 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeJWTtoken = void 0; var base64_1 = require("../base64"); /** * Decode a JWT token. */ function decodeJWTtoken(token) { var base64Url = token.split('.')[1]; var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); // no need to check availability of `encodeURIComponent`, since it is a function highly supported in browsers, node and other platforms. var jsonPayload = decodeURIComponent((0, base64_1.decodeFromBase64)(base64).split('').map(function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); return JSON.parse(jsonPayload); } exports.decodeJWTtoken = decodeJWTtoken;