v2.0.0 — Zero-dependency rewrite with new lookup APIs and TypeScript support
What's new in v2.0.0
🐛 Critical bug fixes
- Exports were completely broken —
module.exportsused bitwise OR on functions (evaluates to0), meaning nothing was exported and the package silently failed for all users. Fixed. - File path broke outside the package directory — the Excel file was loaded with a relative path, crashing when called from any other directory. Fixed with
__dirname. - Crashes on null/undefined input —
getCodeByTxt(null)andgetDesByCode(undefined)threw unhandled TypeErrors. Now throws a clear, descriptive error.
⚡ Zero runtime dependencies (was 41)
The package previously installed 41 transitive packages at runtime just to parse one static Excel file. The HSN data is now pre-built into data/hsn_codes.json and shipped directly — no parsing at startup, no extra installs for your users.
🆕 New API methods
| Method | Description |
|---|---|
getHsnByExactCode(code) |
Exact match — returns the single entry or undefined |
isValidHsnCode(code) |
Boolean validation, safe on null/undefined |
getHsnChapter(chapter) |
All codes under a 2-digit chapter (e.g. '52' for cotton) |
searchHsn(query, options) |
Search with matchType, limit, and offset for pagination |
getStats() |
Dataset metadata — version, date, total codes, chapters |
🔷 TypeScript support
Full index.d.ts type definitions included. No @types/ package needed.
✅ Tests
35 tests added with 98% coverage across all functions and edge cases.
📦 Dataset
12,604 HSN codes across 86 chapters (CBIC / WCO Harmonized System Nomenclature).
Migration from v1
Existing calls to getAllHsn(), getCodeByTxt(), and getDesByCode() work the same — they now validate input and won't crash on null. Destructured imports are required:
// v1 (broken — nothing was exported)
const hsn = require('hsn-code-package');
// v2 (correct)
const { getAllHsn, getCodeByTxt, getDesByCode } = require('hsn-code-package');