/** * @author yutent * @date 2020/09/20 15:08:50 */ // var KEY_REGEXP = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/ const SPLIT_REGEXP = /; */ // var encode = encodeURIComponent const decode = decodeURIComponent /** * [parse 格式化字符串] */ export function parseCookie(str) { let obj = {} let pairs if (typeof str !== 'string') { return {} } pairs = str.split(SPLIT_REGEXP) for (let item of pairs) { item = item.split('=') if (item.length < 2) { continue } let key = item[0].trim() let val = item[1].trim() obj[key] = decode(val) } return obj }