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

jp-invoice-tax

v0.2.0

Published

適格請求書等保存方式(インボイス制度)の消費税端数処理ルール(税率ごとに1回の端数処理)に準拠した消費税計算ライブラリ。依存パッケージなし、TypeScript製。

Readme

jp-invoice-tax

npm version test license

適格請求書等保存方式(インボイス制度)の消費税計算ルールに準拠した、依存パッケージなしの TypeScript ライブラリです。

解決する課題

インボイス制度では「1つの適格請求書につき、税率ごとに1回の端数処理」を行うことが求められています。しかし実務では、明細行ごとに消費税額を計算・端数処理してから合計してしまい、正しい合計額と1円単位でずれる、という不具合がよく発生します(検索してもこの計算方式の違いを吸収してくれる汎用ライブラリが見当たらなかったため作成しました)。

このライブラリは「割戻し計算(合計してから1回だけ端数処理)」と「積上げ計算(明細行ごとに端数処理してから合計)」の両方式を明示的に選べるようにし、その挙動の違いを意図した仕様として扱えるようにします。

インストール

npm install jp-invoice-tax

使い方

import { calculateInvoiceTax } from "jp-invoice-tax";

const result = calculateInvoiceTax(
  [
    { name: "商品A", unitPrice: 333, quantity: 1, taxRate: 0.10 },
    { name: "商品B", unitPrice: 333, quantity: 1, taxRate: 0.10 },
    { name: "商品C", unitPrice: 333, quantity: 1, taxRate: 0.10 },
  ],
  { method: "total", roundingMode: "round" }
);

// result.subtotal === 999
// result.taxTotal === 100  (999 * 10% = 99.9 -> 税率区分につき1回だけ四捨五入)
// result.total    === 1099

明細行ごとに端数処理する「積上げ計算」を選ぶと、同じ入力でも合計消費税額が変わり得ます(現場で報告される「1円のずれ」の典型例です):

calculateInvoiceTax(items, { method: "per-line", roundingMode: "round" }).taxTotal;
// => 99  (333*10%=33.3->33 を3行分合計)

軽減税率(8%)と標準税率(10%)が混在する請求書も、税率ごとに自動で区分されます。

const result = calculateInvoiceTax([
  { name: "食料品", unitPrice: 1000, quantity: 1, taxRate: 0.08 },
  { name: "備品", unitPrice: 1000, quantity: 1, taxRate: 0.10 },
]);
// result.groups は taxRate: 0.08 と 0.10 の2グループに分かれる

税込単価から計算したい場合は priceType: "inclusive" を指定します。

calculateInvoiceTax([{ unitPrice: 1100, quantity: 1, taxRate: 0.10 }], {
  priceType: "inclusive",
});
// => subtotal: 1000, taxTotal: 100, total: 1100

登録番号(T + 13桁)の書式チェックも用意しています(実在確認ではなく書式のみ)。

import { isValidRegistrationNumberFormat } from "jp-invoice-tax";

isValidRegistrationNumberFormat("T1234567890123"); // true

同じ明細で割戻し計算と積上げ計算を両方計算し、差額を確認したい場合は compareCalculationMethods が使えます。

import { compareCalculationMethods } from "jp-invoice-tax";

const comparison = compareCalculationMethods(items);
comparison.matches;      // 両方式で消費税額が一致するか
comparison.taxTotalDiff; // 積上げ計算 - 割戻し計算(円)

API

calculateInvoiceTax(items, options?)

| オプション | 型 | 既定値 | 説明 | |---|---|---|---| | priceType | "exclusive" \| "inclusive" | "exclusive" | 単価が税抜か税込か | | roundingMode | "floor" \| "ceil" \| "round" | "round" | 端数処理方法(切り捨て/切り上げ/四捨五入) | | method | "total" \| "per-line" | "total" | 割戻し計算 / 積上げ計算 |

戻り値 InvoiceTaxResult は税率区分ごとの内訳(groups)と、税抜合計(subtotal)・消費税合計(taxTotal)・税込合計(total)を返します。

isValidRegistrationNumberFormat(input)

適格請求書発行事業者登録番号の書式(T + 数字13桁)を判定します。実在確認は行いません。

compareCalculationMethods(items, options?)

同じ明細を割戻し計算・積上げ計算の両方で計算し、{ total, perLine, taxTotalDiff, matches } を返します。optionsmethod を除く calculateInvoiceTax と同じオプションです。

免責事項

本ライブラリは国税庁が公表している端数処理ルール(税率ごとに1回)に沿った計算ロジックを提供するものであり、税務・法務上の助言ではありません。返品・値引き・複数書類にまたがる取引など、個別の税務判断が必要なケースについては税理士等の専門家にご確認ください。

ライセンス

MIT