Skip to content

feat: add rate-agnostic GST calculation utilities (#3)#5

Merged
karthi-21 merged 1 commit into
devfrom
claude/gst-calculation-utils
Jun 3, 2026
Merged

feat: add rate-agnostic GST calculation utilities (#3)#5
karthi-21 merged 1 commit into
devfrom
claude/gst-calculation-utils

Conversation

@karthi-21
Copy link
Copy Markdown
Owner

Summary

Implements the rate-agnostic portion of #3 — GST calculation/helper utilities that most developers end up writing themselves when building GST-compliant tools.

Adds a new pure, zero-dependency gst.js module:

Function Description
calculateTax(taxableAmount, rate) Tax amount + total at a given rate
calculateGSTBreakdown(taxableAmount, gstRate, options?) CGST/SGST (intra-state) or IGST (inter-state) + optional cess
reverseCalculateTax(grandTotal, rate) Extract base + tax from a tax-inclusive amount
getApplicableTaxType(supplierState, placeOfSupply) IGST vs CGST_SGST from state codes
calculateInvoiceTotals(items, isInterState) Line-item invoice totals with GST round-off
groupItemsByTaxRate(items) GSTR-1 style grouping by rate
applyRoundOffRules(amount) 2-decimal half-up rounding

All functions are re-exported from index.js, fully typed in index.d.ts, documented in the README, and covered by 20 new tests.

What's intentionally deferred

calculateItemTax(item) from the issue — the variant that auto-looks-up the rate from an HSN code — depends on rate data being present in the dataset (#2). Once #2 lands, that becomes a thin wrapper over calculateGSTBreakdown.

Test plan

  • npm test → 55 passing (35 existing + 20 new), gst.js at 100% coverage
  • Verified intra-state, inter-state, cess, and round-off scenarios
  • Verified existing HSN lookup API is unchanged
  • Bumped version to 2.1.0 (additive, non-breaking)

Refs #3

https://claude.ai/code/session_01V2bGsWhrzxeEpoV8BJyZMi


Generated by Claude Code

Adds a new pure, zero-dependency `gst.js` module with helper functions
that most GST tools end up reimplementing:

- calculateTax — tax + total at a given rate
- calculateGSTBreakdown — CGST/SGST (intra) or IGST (inter) + cess
- reverseCalculateTax — extract base + tax from inclusive total
- getApplicableTaxType — IGST vs CGST_SGST from state codes
- calculateInvoiceTotals — line-item invoice totals with round-off
- groupItemsByTaxRate — GSTR-1 style grouping
- applyRoundOffRules — 2-decimal half-up rounding

All re-exported from index.js, fully typed in index.d.ts, documented
in the README, and covered by 20 new tests (gst.js 100% coverage).

The rate-lookup-from-HSN variant (calculateItemTax) is intentionally
deferred — it depends on rate data being added to the dataset (#2).

Refs #3

https://claude.ai/code/session_01V2bGsWhrzxeEpoV8BJyZMi
@karthi-21 karthi-21 changed the base branch from main to dev June 3, 2026 01:58
@karthi-21 karthi-21 marked this pull request as ready for review June 3, 2026 02:00
@karthi-21 karthi-21 merged commit 15faea9 into dev Jun 3, 2026
6 checks passed
karthi-21 pushed a commit that referenced this pull request Jun 3, 2026
Merged gst.js calculation utilities (from dev/PR #5) with all PR #6
features: GSTIN validation, SAC codes, export utils, CLI, advanced
HSN lookups, and GST rate data. All 105 tests passing.

https://claude.ai/code/session_01V2bGsWhrzxeEpoV8BJyZMi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants