'use strict'; /* 앞말의 끝소리에 맞춰 조사를 고른다(과/와 · 을/를 · 은/는 · 이/가 · 으로/로). * 근무 이름과 일정 제목처럼 바뀌는 말 뒤에 조사를 고정하면 "일반근무과"처럼 틀린다. * 숫자는 읽는 소리로 본다(0 영 · 1 일 · 3 삼 · 6 육 · 7 칠 · 8 팔은 받침 있음). 끝의 괄호와 따옴표는 건너뛴다. * 앱(Korean.kt)과 서버(korean.py)도 같은 규칙이다. */ function josa(word, withBatchim, without) { const text = String(word ?? ''); const last = text.replace(/[\s)\]}"'.」』]+$/u, '').slice(-1); let batchim = false, rieul = false; if (last >= '가' && last <= '힣') { const tail = (last.charCodeAt(0) - 0xac00) % 28; batchim = tail !== 0; rieul = tail === 8; } else if (/^[0-9]$/.test(last)) { batchim = '013678'.includes(last); rieul = '178'.includes(last); } if (withBatchim === '으로') return text + (batchim && !rieul ? '으로' : '로'); return text + (batchim ? withBatchim : without); } if (typeof module !== 'undefined') module.exports = { josa };