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 🙏

© 2026 – Pkg Stats / Ryan Hefner

corporate-number-jp

v0.1.2

Published

日本の法人番号をローカル検証します

Downloads

19

Readme

corporate-number-jp

日本の法人番号をローカルで検証するライブラリです。TypeScript対応。

インストール

npm install corporate-number-jp

または

pnpm add corporate-number-jp

使い方

import { validateCorporateNumber, fakeCorporateNumber, type ErrorType } from 'corporate-number-jp';

const result = validateCorporateNumber('1180301018771');

if (result.valid) {
  // result.valid が true の場合、TypeScript が自動的に型を絞り込みます
  console.log('チェックデジット:', result.checkDigit);
  console.log('本体部分:', result.bodyDigits);
  console.log('法人番号:', result.corporateNumberDigits);
} else {
  // result.valid が false の場合、error と errorType にアクセスできます
  const errorType: ErrorType = result.errorType;
  console.log('エラータイプ:', errorType);
  console.log('エラー:', result.error);
}

// ランダムに正しい法人番号(13桁)を生成
const fake = fakeCorporateNumber();
console.log('fake:', fake); // 例: "1180301018771"
const check = validateCorporateNumber(fake);
console.log('valid?:', check.valid); // 常に true

API

validateCorporateNumber(corporateNumberDigits: string | number | number[])

法人番号を検証します。

引数

  • corporateNumberDigits: 検証する法人番号(文字列、数値、または数値配列)

戻り値

検証に成功した場合:

{
  valid: true,
  checkDigit: number,        // チェックデジット
  bodyDigits: number[],      // 本体部分(12桁)
  corporateNumberDigits: number[]  // 全体の桁(13桁)
}

検証に失敗した場合:

{
  valid: false,
  error: string,        // エラーメッセージ
  errorType: ErrorType  // エラータイプ
}

エラータイプ (ErrorType)

以下の値のいずれかです。

  • NON_NUMERIC: 文字列/数値入力に数字以外が含まれている
  • INVALID_LENGTH: 桁数が 13 桁ではない
  • CHECK_DIGIT_MISMATCH: チェックデジットが一致しない
  • INVALID_ARRAY_ELEMENT: 配列入力に 0-9 の整数以外が含まれている

fakeCorporateNumber()

12桁の本体部分をランダムに生成し、チェックデジットを計算して先頭に付与した13桁の法人番号文字列を返します。validateCorporateNumber で常に妥当と判定されます。

const fake = fakeCorporateNumber(); // "\d{13}"
const result = validateCorporateNumber(fake);
// result.valid === true

法人番号について

法人番号は13桁の数字で構成されており、先頭の1桁がチェックデジットです。このライブラリは、チェックデジットの計算式に基づいて、法人番号が正しい形式かどうかを検証します。

詳細は国税庁の法人番号公表サイトをご覧ください。

開発

# テストの実行
pnpm test

# ビルド
pnpm build

License

MIT