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/id

v0.4.0

Published

Provides utility to analyze Korean id numbers. / 주민등록번호를 분석하는 도구를 제공합니다. 생년월일과 성별 등의 정보를 확인하고, 주민등록번호의 유효성을 검증합니다.

Downloads

403

Readme

koKR - id

주민등록번호와 관련한 유틸리티를 제공합니다.

설치

npm install @kokr/id

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

import {} from "https://deno.land/x/kokr/id/mod.ts";

사용법

테스트에 사용한 주민등록번호 및 외국인등록번호는 아무 숫자나 입력 후, 검증코드를 계산하여 만든 번호로서 실제로 존재하지 않는 번호입니다.

주민등록번호 및 외국인등록번호 분석

주민등록번호 및 외국인등록번호를 분석해, 등록번호의 유효성, 성별, 외국인 여부, 생일, 나이 등을 알 수 있습니다. 입력된 등록번호는 숫자를 제외한 모든 문자를 제거하고 분석합니다. 따라서 중간에 하이픈('-')여부에 관계없이 사용가능합니다. 자세한 내용은 데이터 구조를 참고하세요.

import { analyze } from "@kokr/id";

analyze("000101-1000002");
/*
{
  valid: true, // 올바른 주민번호 여부
  parity: 2, // 주민번호 맨 뒤 검증코드
  gender: 'M', // 성별
  foreigner: false, // 외국인여부
  birth: '1900-01-01', // 생일 (2003-02-29와 같이 존재하지 않는 경우 null 반환)
  age: 121, // 만나이
  krAge: 122, // 한국나이
}
*/

만나이와 한국식 나이는 오늘날짜 기준으로 계산합니다. 만약, 다른 날짜를 기준으로 계산하고 싶다면 now 옵션을 사용할 수 있습니다.

analyze("000101-1000002", { now: "2021-06-01" });

주민등록번호 및 외국인등록번호 검증

주민등록번호 및 외국인등록번호의 유효성을 검증합니다. 검증결과는 boolean으로 반환됩니다. 외국인등록번호를 제외한 주민등록번호만 검증하고 싶다면 disableForeigner 옵션을 사용할 수 있습니다.

import { validate } from "@kokr/id";

// 주민등록번호 및 외국인등록번호 검증
validate("010101-0010101");
validate("010101-5010105");
validate("010101-6010108");
validate("010101-7010101");
validate("010101-8010103");

// 주민등록번호만 검증 (외국인등록번호 제외)
validate("010101-5010105", { disableForeigner: true }); // false
validate("010101-6010108", { disableForeigner: true }); // false
validate("010101-7010101", { disableForeigner: true }); // false
validate("010101-8010103", { disableForeigner: true }); // false

주민등록번호 및 외국인등록번호 포매팅

주민등록번호 및 외국인등록번호를 포매팅합니다. 포매팅된 결과는 string으로 반환됩니다. 숫자를 제외한 모든 문자는 제거되며, 하이픈('-')이 포함됩니다.

import { format } from "@kokr/id";

format("0101010010101"); // 010101-0010101

기본적으로 잘못된 주민등록번호는 포매팅 처리하지 않습니다. 잘못된 경우 null을 반환합니다.

format("01234"); // null

자릿수가 다르거나, 잘못된 주민등록번호를 포매팅하고 싶다면 ignoreInvalid 옵션을 사용할 수 있습니다.

format("010101", { ignoreInvalid: true }); // 010101
format("0101010", { ignoreInvalid: true }); // 010101-0
format("01010100101019", { ignoreInvalid: true }); // 010101-00101019

데이터 구조

등록번호 분석결과(AnalyzeResult)

| 속성 | 타입 | 설명 | | ----------- | ------------------------ | ---------------------------------------------------- | | valid | boolean | 주어진 주민등록번호가 올바른지 | | parity | number | null | 주민등록번호의 패리티 값, 잘못된 주민등록번호의 반환 | | gender | "M" | "F" | null | 성별, M은 남성, F는 여성 | | foreigner | boolean | null | 외국인 여부 | | birth | string | null | 생년월일 | | age | number | null | 만나이 | | krAge | number | null | 한국나이 |

API

API 문서 보기