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

@kokr/text

v0.4.1

Published

A utility to help handle investigations in Korean sentences. / 한국어 문장의 조사 처리를 도와주는 유틸리티입니다. 은/는/이/가 등의 조사를 적절하게 처리합니다.

Downloads

306

Readme

koKR - text

설치

npm install @kokr/text

만약, Deno를 사용한다면 아래와 같이 import 할 수 있습니다.

import text from "https://deno.land/x/kokr/text/mod.ts";

사용법

조사

은/는/이/가와 같은 조사를 자동으로 붙여주는 기능을 템플릿 리터럴(Template Literal)을 통해 제공합니다.

import text from "@kokr/text";

let name1 = "사과";
let name2 = "코코넛";

// 은/는
console.log(text`${name1}는 코딩 합니다.`); // 사과는 코딩 합니다.
console.log(text`${name1}은 코딩 합니다.`); // 사과는 코딩 합니다.
console.log(text`${name2}는 코딩 합니다.`); // 코코넛은 코딩 합니다.
console.log(text`${name2}은 코딩 합니다.`); // 코코넛은 코딩 합니다.

// 이/가
console.log(text`${name1}가 코딩 했습니다.`); // 사과가 코딩 했습니다.
console.log(text`${name1}이 코딩 했습니다.`); // 사과가 코딩 했습니다.
console.log(text`${name2}가 코딩 했습니다.`); // 코코넛이 코딩 했습니다.
console.log(text`${name2}이 코딩 했습니다.`); // 코코넛이 코딩 했습니다.

// 을/를
console.log(text`${name1}을 가르쳤습니다.`); // 사과를 가르쳤습니다.
console.log(text`${name1}를 가르쳤습니다.`); // 사과를 가르쳤습니다.
console.log(text`${name2}을 가르쳤습니다.`); // 코코넛을 가르쳤습니다.
console.log(text`${name2}를 가르쳤습니다.`); // 코코넛을 가르쳤습니다.

// 로/으로
let place = "대구";
console.log(text`${place}으로 갑시다.`); // 대구로 갑시다.
console.log(text`${place}로 갑시다.`); // 대구로 갑시다.

place = "부산";
console.log(text`${place}으로 갑시다.`); // 부산으로 갑시다.
console.log(text`${place}로 갑시다.`); // 부산으로 갑시다.

place = "서울"; // 예외케이스 (ㄹ로 끝나는 경우)
console.log(text`${place}으로 갑시다.`); // 서울로 갑시다.
console.log(text`${place}로 갑시다.`); // 서울로 갑시다.

제공하는 조사는 다음과 같습니다.

  • 은/는
  • 이/가
  • 을/를
  • 과/와
  • 아/야 (모호한 케이스, 하단 설명 참고)
  • 이나/나
  • 이다/다
  • 이든/든
  • 이라/라
  • 이란/란
  • 이랑/랑
  • 으로/로
  • 이며/며
  • 이셨/셨
  • 이시/시
  • 이야/야 (모호한 케이스, 하단 설명 참고)
  • 이여/여
  • 이었/였
  • 이어요/여요
  • 이에요/예요

모호한 케이스

"아/야"와 "이야/야"는 모호한 케이스가 있습니다. "야"로 끝나는 경우에는 "이야/야" 규칙이 우선적으로 적용됩니다. 명확하게 사용하려면 "이야", "아"를 사용해야 합니다.

// 명확한 케이스
console.log(text`${"완두"}아!`); // "완두야!"
console.log(text`${"완삼"}아!`); // "완삼아!"

console.log(text`${"완두"}이야!`); // "완두야!"
console.log(text`${"완삼"}이야!`); // "완삼이야!"

// 모호한 케이스
console.log(text`${"완두"}야!`); // "완두야!"
console.log(text`${"완삼"}야!`); // "완삼이야!" // "완삼아!"를 원했지만 "이야/야" 규칙이 우선.

숫자 판단 및 영어

숫자의 경우 한국어 발음 기준으로 변환하여 제공합니다.

console.log(text`정답은 ${"100"}과 같다.`); // 정답은 100과 같다.
console.log(text`정답은 ${"100"}와 같다.`); // 정답은 100과 같다.

console.log(text`정답은 ${"72"}과 같다.`); // 정답은 72와 같다.
console.log(text`정답은 ${"72"}와 같다.`); // 정답은 72와 같다.

영어 또한 한국어 발음 기준으로 변환하여 제공합니다.

console.log(text`${"Apple"}는 코딩 합니다.`); // Apple은 코딩 합니다.
console.log(text`${"Apple"}은 코딩 합니다.`); // Apple은 코딩 합니다.

console.log(text`${"Banana"}는 코딩 합니다.`); // Banana는 코딩 합니다.
console.log(text`${"Banana"}은 코딩 합니다.`); // Banana는 코딩 합니다.

괄호 무시

괄호가 포함된 경우, 괄호안의 텍스트는 무시합니다.

console.log(text`${"코코넛(바나나)"}은 코딩 합니다.`); // 코코넛(바나나)은 코딩 합니다.
console.log(text`${"코코넛(바나나)"}는 코딩 합니다.`); // 코코넛(바나나)은 코딩 합니다.

Dedent

여러 줄의 문자열을 입력할 때, 들여쓰기를 제거해주는 기능을 제공합니다.

function printResult(winner: string, loser: string) {
  return text`
    결과는 다음과 같습니다.

    - 승: ${winner}
    - 패: ${loser}

    ${winner}님 축하드립니다!
  `;
}

조사 변환 없이 그대로 사용하기

조사 변환없이 그대로 사용하려면 다음과 같이 사용하면 됩니다.

console.log(text`${name}는 가나다라..`); // 이렇게 되면 '는'은 '은/는'으로 변환됩니다.

console.log(text`${name}{'는'} 가나다라..`); // 이렇게 되면 '는'은 변환 없이 그대로 출력됩니다.

API

API 문서 보기

함께 보면 좋아요

  • Hangul.js 한글 문장의 자/모음을 분리하는 라이브러리
  • inko 영타를 한글로, 혹은 한타를 영어로 변환해주는 라이브러리
  • josa-complete String.prototype을 확장해서 조사를 깔끔하게 붙여주는 라이브러리