export default { install(Vue) { // 빈값체크 Vue.config.globalProperties.$isEmpty = function (data) { if (data === undefined || data === null || data === "" || data.length === 0 || (data.constructor == Object && Object.keys(data).length === 0)) { if ((typeof data) === "number") { return false } else { return true; } } else { return false; } } /** * FROM: 2025-03-25 13:32 * TO : 2025.03.25 */ Vue.config.globalProperties.$dotFormatDate = (dateString) => { if (!dateString) return ''; const dateOnly = dateString.split(' ')[0]; return dateOnly.replace(/-/g, '.'); } // 정규식을 사용하여 모든 HTML 태그 제거 Vue.config.globalProperties.$stripHtml = (html) => { if (!html) return ''; // 환경 확인 (브라우저 vs 서버) if (typeof window !== 'undefined' && window.DOMParser) { try { // 브라우저 환경에서는 DOMParser 사용 const doc = new DOMParser().parseFromString(html, 'text/html'); let text = doc.body.textContent || ''; return text.replace(/\s+/g, ' ').trim(); } catch (e) { // DOMParser 실패시 정규식 방식으로 폴백 console.warn('DOMParser failed, falling back to regex', e); } } // 서버 환경이거나 DOMParser 실패 시 정규식 사용 let text = html.replace(/<[^>]*>/g, ''); // 일반적인 HTML 엔티티 처리 const entityMap = { ' ': ' ', '&': '&', '<': '<', '>': '>', '"': '"', ''': "'", '—': '—', '–': '–', '°': '°' }; // 정의된 엔티티 변환 Object.keys(entityMap).forEach(entity => { const regex = new RegExp(entity, 'g'); text = text.replace(regex, entityMap[entity]); }); // 남은 숫자 엔티티 제거 ({ 형식) text = text.replace(/&#[0-9]+;/g, ''); // 남은 이름 있는 엔티티 제거 (… 등) text = text.replace(/&[a-zA-Z]+;/g, ''); // 연속된 공백 문자 하나로 처리 text = text.replace(/\s+/g, ' ').trim(); return text; }; } }