Skip to content

feat: v2.0.0 — zero-dependency rewrite with new lookup APIs and TypeScript support#1

Merged
karthi-21 merged 3 commits into
mainfrom
claude/elegant-dijkstra-a8o8l
Jun 1, 2026
Merged

feat: v2.0.0 — zero-dependency rewrite with new lookup APIs and TypeScript support#1
karthi-21 merged 3 commits into
mainfrom
claude/elegant-dijkstra-a8o8l

Conversation

@karthi-21
Copy link
Copy Markdown
Owner

Summary

This PR upgrades the package from v1.0.2 to v2.0.0, fixing critical bugs that made the package completely non-functional for many users, eliminating 41 runtime dependencies, and adding new features that are commonly requested.

Bug fixes (were breaking the package)

  • Critical: broken exportsmodule.exports = getAllHsn | getCodeByTxt | getDesByCode used bitwise OR on functions, which evaluates to 0. Nothing was exported. Fixed to module.exports = { getAllHsn, getCodeByTxt, getDesByCode, ... }.
  • Broken file pathsourceFile: 'code_list.xlsx' used a relative path that broke whenever the package was called from any directory other than the package root. Fixed with path.join(__dirname, ...).
  • Crashes on null/undefined inputgetCodeByTxt(null) and getDesByCode(undefined) threw unhandled TypeErrors. Now throws a descriptive error with the parameter name.

Performance overhaul — 0 runtime dependencies (was 41)

convert-excel-to-json pulled in 41 transitive packages just to parse one static file at runtime. The Excel is now pre-converted to data/hsn_codes.json at build time via scripts/build-data.js. At runtime, index.js does a simple require('./data/hsn_codes.json') — no parsing overhead, no extra installs.

convert-excel-to-json is moved to devDependencies. Users installing this package get zero extra dependencies.

The parsed result is also cached in memory so repeated calls don't re-read the file.

New API methods

Method Description
getHsnByExactCode(code) Strict single-result lookup — returns the entry or undefined
isValidHsnCode(code) Boolean validation, safe on null/undefined — useful for GST form validation
getHsnChapter(chapter) Returns all codes under a 2-digit chapter (e.g. '52' for cotton)
searchHsn(query, options) Advanced search with matchType (contains/startsWith/exact) and limit/offset pagination
getStats() Dataset metadata — version, lastUpdated, totalCodes, chapterCount, source

TypeScript support

Added index.d.ts with full type definitions for all exported functions and interfaces (HsnCode, SearchOptions, HsnStats). No @types/ package needed.

Tests

Added Jest test suite — 35 tests, 98% coverage. Covers all functions including edge cases (null, undefined, empty string, numeric input, no match).

package.json improvements

  • "types": "index.d.ts" — TypeScript auto-discovery
  • "files" whitelist — only index.js, index.d.ts, data/ are published; scripts and tests are excluded
  • "engines": { "node": ">=14" }
  • Expanded keywords for npm discoverability (HSN, GST, India GST, CBIC, WCO, harmonized system, etc.)
  • "dependencies": {} — zero runtime deps

Test plan

  • npm install hsn-code-package installs with zero extra packages
  • getAllHsn() returns 12,604 entries
  • getCodeByTxt('cotton') returns matching entries
  • isValidHsnCode(null) returns false without throwing
  • getHsnChapter('52') returns cotton chapter codes
  • searchHsn('silk', { limit: 5 }) returns at most 5 results
  • TypeScript consumers get type hints without any @types/ install
  • npm test passes all 35 tests

https://claude.ai/code/session_01V2bGsWhrzxeEpoV8BJyZMi


Generated by Claude Code

claude added 3 commits June 1, 2026 13:17
…cript support

- Fix critical export bug (bitwise OR on functions evaluated to 0)
- Fix broken runtime file path (use __dirname instead of relative path)
- Add input validation with descriptive TypeErrors on null/undefined
- Cache parsed data so the dataset is only loaded once per process

- Pre-bake Excel → JSON at build time (scripts/build-data.js)
  Moves convert-excel-to-json to devDependencies, eliminating all 41
  transitive runtime dependencies; users install nothing extra

- Add getHsnByExactCode(code) — strict single-result lookup
- Add isValidHsnCode(code) — boolean validation, safe on null/undefined
- Add getHsnChapter(chapter) — browse all codes under a 2-digit chapter
- Add searchHsn(query, options) — matchType + limit/offset pagination
- Add getStats() — dataset metadata (version, date, counts, source)

- Add index.d.ts TypeScript definitions for all exported functions
- Add Jest test suite (35 tests, 98% coverage)
- Update package.json: version 2.0.0, types field, files whitelist,
  expanded keywords, engines >= 14, correct devDependencies
- Rewrite README with full API docs, migration guide, and examples

https://claude.ai/code/session_01V2bGsWhrzxeEpoV8BJyZMi
@karthi-21 karthi-21 marked this pull request as ready for review June 1, 2026 13:59
@karthi-21 karthi-21 self-assigned this Jun 1, 2026
@karthi-21 karthi-21 merged commit d8b53a4 into main Jun 1, 2026
6 checks passed
@karthi-21 karthi-21 deleted the claude/elegant-dijkstra-a8o8l branch June 1, 2026 14:00
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