// Complete an existing partial identifier at the user's selected threshold. // Positions returned by the detector are Unicode code points, not UTF-16 units. const formats = [ ['EMAIL', /(?Number(s)<=255 && (s==='0' || !s.startsWith('0'))); if(label==='IBAN'){ const compact=text.toUpperCase().replace(/[ \u00a0]/g,''); let remainder=0; for(const digit of compact.slice(4)+'1314'+compact.slice(2,4)) remainder=(remainder*10+Number(digit))%97; return remainder===1; } return text.length<=254 && text.indexOf('@')<=64 && text.split('@')[1].split('.').every(x=>x.length<=63); } export function completeIdentifiers(text,groups){ if(!groups.length) return groups; const points=Array.from(text); const offsets=new Map([[0,0]]);let units=0; for(let i=0;ia.start-b.start||b.end-a.end); const out=[]; let i=0; for(const c of candidates){ if(i>=groups.length)break; while(ig.startc.end))continue; const matches=overlap.filter(g=>g.label===c.label && points.slice(g.start,g.end).filter(x=>/[\p{L}\p{N}]/u.test(x)).length>=2); if(!matches.length)continue; const best=matches.reduce((a,b)=>a.total/a.count>=b.total/b.count?a:b); out.push({...best,start:c.start,end:c.end,label:c.label});i=j; } return out.concat(groups.slice(i)); }