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

kor-to-number

v1.1.5

Published

한글로 적힌 한국어 수사를 숫자로 변환하는 자바스크립트 라이브러리

Downloads

22

Readme

kor-to-number.js

한글로 적힌 한국어 수사를 숫자로 변환하는 자바스크립트 라이브러리입니다.

설치

npm install kor-to-number

사용법

const { extractNumber } = require('kor-to-number');

// 숫자
extractNumber('42');  // [42, '']
extractNumber('36.5도');  // [36.5, '도']

// 한자어 수사
extractNumber('삼백육십오');  // [365, '']
extractNumber('이천이십일년');  // [2021, '년']

// 숫자 혼용
extractNumber('1만2천 봉');  // [12000, '봉']
extractNumber('21억 4748만 3648');  // [2147483648, '']

// 순우리말 수사
extractNumber('아흔아홉');  // [99, '']
extractNumber('스무 날');  // [20, '날']
extractNumber('백한 마리');  // [101, '마리']

API

extractNumber(word: string, format?: formatType[]): [number, string]

문자열의 앞부분에서 한자어 수사, 고유어 수사, 숫자 등이 포함된 부분을 떼어냅니다.

반환값은 해석된 수 및 나머지 부분으로 이루어진 길이 2의 배열입니다.

해석에 실패한 경우 반환값의 첫번째 요소는 NaN이 되고 두번째 요소는 입력 문자열이 됩니다.

format 배열로 사용할 형식을 지정할 수 있습니다. format 인수를 비워두는 경우 모든 형식을 전부 사용합니다.

type formatType = "숫자" | "숫자혼용" | "한자어" | "순우리말"

지원되는 형식은 다음과 같습니다.

  • "숫자"
    • 쉼표로 구분된 인도-아라비아 숫자
      • 예: 0.12, +12,345,678.900
    • 지수 표기법
      • 예: −1.602e−19
  • "한자어"
    • 예: 일억 이천삼백사십오만 육천칠백팔십구
  • "숫자혼용"
    • 십의 자리
      • 예: 1억 2천3백4십5만 6천7백8십9
    • 만의 자리
      • 예: 1억 2345만 6789
  • "순우리말"
    • 명사
      • 예: 하나, 둘, 셋, 열, 스물셋, 천이백서른넷
    • 관형사
      • 예: 한 명, 열두 명, 백육십세 명

한자어 수사에 부호(+, -)를 표시하려면 '플러스' 또는 '마이너스'를 앞에 붙입니다.

  • 예: 플러스 만 원, 마이너스 삼십 도

extractAndProcessNumber<T>(word: string, mapper: Mapper<T>, format?: formatType[]): T | null

문자열의 앞부분에서 한자어 수사, 고유어 수사, 숫자 등이 포함된 부분과 나머지 부분으로 분리하여 가공합니다.

분석이 성공하면 분석 중간 결과 중 남은 문자열이 가장 짧은 것을 최종 분석으로 채택하고, 그것을 mapper로 가공한 결과를 반환합니다.

분석에 실패한 경우는 null이 반환됩니다.

type Mapper<T> = (analysis: Analysis) => T | null

분석 도중에 중간 결과를 보고 가공하거나 기각할 수 있습니다.

가공한 결과는 이 분석이 최종적으로 채택될 경우 반환값으로 사용됩니다.

이 분석을 기각하려면 null을 반환합니다. 기각된 분석은 최종 분석으로 채택되지 않습니다.

type Analysis = { consumed: string; parsed: number; rest: string }

분석 중간 결과입니다. consumed는 지금까지 분석한 문자열, parsed는 분석 결과, rest는 남은 문자열입니다.

라이센스

이 라이브러리는 MIT 라이센스 아래 자유롭게 배포 가능합니다.