export default function(str, type) { if(type === 'compile') { //编译 return str.replace(/[&<>'"]/g, tag => ({ '&': '&', '<': '<', '>': '>', "'": ''', '"': '"' }[tag] || tag)); }else { str = str.replace(/&/g, '&'); str = str.replace(/</g, '<'); str = str.replace(/>/g, '>'); str = str.replace(/'/g, "'"); str = str.replace(/"/g, '"'); return str } }