npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hangul-searcher

v1.0.4

Published

A module for searching and auto completing Hangul.

Downloads

75

Readme

Hangul Searcher

Hangul-Searcher는 한글 검색 및 자동 완성을 위한 JS 모듈입니다. 텍스트 배열을 받아 생성한 인스턴스를 통해 검색 및 자동 완성을 수행합니다. 자동 완성은 초성 검색도 가능하며, 기타 옵션을 통해 원하는 방식의 자동 완성을 구현할 수 있습니다. 아래의 데모 웹사이트를 통해 기능들을 한눈에 확인할 수 있습니다.

Test the Hangul-Searcher on this Demo Website!

Hangul-Searcher is a search and automatic completion module for Hangul. It is based on es-hangul, korean-regexp, and minisearch modules.

Installation

$ npm install hangul-searcher

Usage

import HangulSearcher from 'hangul-searcher';
const stringArr = ['한글', '검색', '자동', '오이', '완성', '완제품', '왕', '여왕', 'foo', 'bar', '한글 검색'];
const hangulSearcher = new HangulSearcher(stringArr);

The strings do not have to be all Hangul.

Search

hangulSearcher.search('한글'); // ['한글']

When the query is exactly matched, it returns an array with the query itself.

hangulSearcher.search('한');
/* [{ original: '한글', score: 13.xx, ... },
    { original: '한글 검색', score: 11.xx, ... },
     ...
    { original: '자동', score: 1.xx, ... }] */

When the query is not matched, it returns an array with the result objects. Each object has original and score keys (It has other keys, but it would not be meaningful for Hangul.). The original value is the result text, and the score value is the score measured by how much the query and result text are matched.

The search function can receive the minisearch options as an argument.

hangulSearcher.search('한글', { fuzzy: 2 });

Or the option can be set when instantiating the hangulSearcher.

const hangulSearcher = new HangulSearcher(stringArr, { fuzzy: 3 });

Hangul searcher searches words by formatting Hangul words (i.e., one Hangul character is converted to more than three characters). Therefore, the fuzzy option would not be effective. In other words, the fuzzy option is already applied to the Hangul searcher by default.

Auto Completion

hangulSearcher.autoComplete('와'); // ['완성', '완제품', '왕', '여왕', '오이']

Auto completion has two options: startsWithQuery and alwaysUsesChoseong. These options can be set in two ways below like the search options.

const hangulSearcher = new HangulSearcher(stringArr, { fuzzy: 3 }, { startsWithQuery: true });
// To set the auto completion option while instantiating, the search option must be in front of the auto completion option. If you do not need the search options, just set an empty object.
hangulSearcher.autoComplete('와', { alwaysUsesChoseong: false });

If startsWithQuery is true, the results always start with the query. The default is true.

  • startsWithQuery: true & query: 안 --> result: 아나운서, 경, ...
  • startsWithQuery: false & query: 안 --> result: 그동, 달아나다, ...

If alwaysUsesChoseong is true, both the query and the choseong of the query will be the input of auto completion. If the option is false, only the query will be the input. The default is true.

  • alwaysUsesChoseong: true & query: 안녕 --> result: 안녕, 안녕하다, 아내, 아니, ...
  • alwaysUsesChoseong: false & query: 안녕 --> result: 안녕, 안녕하다, ...

You can test it on Demo Website. It would help understand how the options work.