UNPKG

@midwayjs/session

Version:

midway session component for koa and faas

35 lines 924 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ONE_DAY = exports.COOKIE_EXP_DATE = void 0; exports.decode = decode; exports.encode = encode; exports.hash = hash; const crc_1 = require("./crc"); /** * Decode the base64 cookie value to an object. * * @param {String} string * @return {Object} * @api private */ function decode(string) { const body = Buffer.from(string, 'base64').toString('utf8'); return JSON.parse(body); } /** * Encode an object into a base64-encoded JSON string. * * @param {Object} body * @return {String} * @api private */ function encode(body) { body = JSON.stringify(body); return Buffer.from(body).toString('base64'); } function hash(sess) { return (0, crc_1.crc32)(JSON.stringify(sess)); } exports.COOKIE_EXP_DATE = new Date('Thu, 01 Jan 1970 00:00:00 GMT'); exports.ONE_DAY = 24 * 60 * 60 * 1000; //# sourceMappingURL=util.js.map