feat: v2.0.0 — zero-dependency rewrite with new lookup APIs and TypeScript support#1
Merged
Merged
Conversation
…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
Runs on every push to main/claude/** branches and on PRs targeting main. https://claude.ai/code/session_01V2bGsWhrzxeEpoV8BJyZMi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)
module.exports = getAllHsn | getCodeByTxt | getDesByCodeused bitwise OR on functions, which evaluates to0. Nothing was exported. Fixed tomodule.exports = { getAllHsn, getCodeByTxt, getDesByCode, ... }.sourceFile: 'code_list.xlsx'used a relative path that broke whenever the package was called from any directory other than the package root. Fixed withpath.join(__dirname, ...).getCodeByTxt(null)andgetDesByCode(undefined)threw unhandled TypeErrors. Now throws a descriptive error with the parameter name.Performance overhaul — 0 runtime dependencies (was 41)
convert-excel-to-jsonpulled in 41 transitive packages just to parse one static file at runtime. The Excel is now pre-converted todata/hsn_codes.jsonat build time viascripts/build-data.js. At runtime,index.jsdoes a simplerequire('./data/hsn_codes.json')— no parsing overhead, no extra installs.convert-excel-to-jsonis moved todevDependencies. 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
getHsnByExactCode(code)undefinedisValidHsnCode(code)null/undefined— useful for GST form validationgetHsnChapter(chapter)'52'for cotton)searchHsn(query, options)matchType(contains/startsWith/exact) andlimit/offsetpaginationgetStats()TypeScript support
Added
index.d.tswith 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 — onlyindex.js,index.d.ts,data/are published; scripts and tests are excluded"engines": { "node": ">=14" }"dependencies": {}— zero runtime depsTest plan
npm install hsn-code-packageinstalls with zero extra packagesgetAllHsn()returns 12,604 entriesgetCodeByTxt('cotton')returns matching entriesisValidHsnCode(null)returnsfalsewithout throwinggetHsnChapter('52')returns cotton chapter codessearchHsn('silk', { limit: 5 })returns at most 5 results@types/installnpm testpasses all 35 testshttps://claude.ai/code/session_01V2bGsWhrzxeEpoV8BJyZMi
Generated by Claude Code