UNPKG

korean-search-utils

Version:

한글 초성 검색 및 React 훅 지원 라이브러리

36 lines (35 loc) 1.54 kB
/** * 문자열 전체를 자모로 분리 (공백 제거) */ export declare const disassembleHangul: (str: string) => string; /** * 한글 문자열이 다른 문자열을 포함하는지 확인 (초성/자모 fuzzy 검색 지원) */ export declare const isMatch: (source: string, target: string) => boolean; /** * 검색어가 문자열에서 매칭되는 시작 위치 인덱스를 반환 (자모 기준, 매칭 실패 시 -1) */ export declare const getMatchStartIndex: (source: string, target: string) => number; /** * 매칭 품질 점수를 반환 (낮을수록 상위, 매칭되지 않으면 Infinity) * 매칭 시작 위치가 빠를수록, 원본 문자열이 짧을수록 높은 우선순위 */ export declare const getMatchScore: (source: string, target: string) => number; export type MatchSegment = { text: string; matched: boolean; }; /** * 검색어와 매칭되는 구간을 세그먼트 배열로 반환 — UI 하이라이팅에 활용 * @example * getMatchSegments("홍길동", "길") * // → [{text:"홍", matched:false}, {text:"길", matched:true}, {text:"동", matched:false}] */ export declare const getMatchSegments: (source: string, target: string) => MatchSegment[]; /** * React 없이 사용 가능한 필터+정렬 유틸리티 * @param items 검색 대상 배열 * @param target 검색어 * @param getField 각 아이템에서 검색할 문자열을 반환하는 함수 */ export declare const filterAndSort: <T>(items: T[], target: string, getField: (item: T) => string) => T[];