Skip to content

Migrate codebase from JavaScript to TypeScript#8

Merged
thomaschaplin merged 2 commits into
masterfrom
move-to-typescript
Mar 11, 2026
Merged

Migrate codebase from JavaScript to TypeScript#8
thomaschaplin merged 2 commits into
masterfrom
move-to-typescript

Conversation

@thomaschaplin
Copy link
Copy Markdown
Owner

Summary

This PR rewrites the entire codebase from JavaScript to TypeScript, adds a comprehensive test suite, fixes several bugs found during the migration, and sets up CI/CD tooling.

Changes

TypeScript migration

  • Replaced index.js (CommonJS) with typed ES modules under src/
  • Core logic rewritten in src/generate-isin.ts with proper type annotations
  • Country codes moved from country-codes.json into a typed fixture at src/fixtures/country-codes.ts
  • src/index.ts added as the package entry point
  • tsconfig.json added to configure compilation to build/

New features

  • generateIsin() now accepts an optional countryCode parameter, allowing callers to pin the country (e.g. generateIsin("US")). Country code is treated as case-insensitive.

Bug fixes found during migration

  • CUSIP was generated once at module load — every ISIN was sharing the same CUSIP. Fixed by moving generateCusip() inside generateIsin() so each call produces a fresh value.
  • Orphaned dead statement — a countryCodes[Math.random() * ...] expression was computed but its result discarded. Removed.
  • Error never thrownnew Error(...) was created but not thrown. Fixed to throw new Error(...).
  • Wrong type annotationscalculateValues was typed as returning string[] but pushed numbers; calculateCheckDigit accepted string[] and used redundant parseInt calls. Corrected to number[].

Testing

  • Jest test suite added (src/__tests__/generate-isin.spec.ts) using a mocked CUSIP for deterministic assertions
  • Tests assert exact known ISIN values (e.g. US0378331005, GB0378331002) to verify correct check digit calculation end-to-end
  • Additional tests cover case-insensitive country codes, per-call CUSIP generation, and fixture content
  • Performance benchmark via kelonio (~0.03ms per call)
  • Stryker mutation testing config added — generate-isin.ts achieves 87.8% mutation score

CI/CD & tooling

  • GitHub Actions workflow (.github/workflows/tests.yml) runs build, coverage, and mutation tests on push/PR to master
  • Dependabot configured for daily npm dependency updates
  • Husky pre-push hook with interactive prompts to merge latest master and run tests before pushing
  • release.sh and prepush.sh scripts added
  • .nvmrc added to pin Node version
  • examples/ directory added with a standalone TypeScript usage example

Test plan

  • npm test — all 9 tests pass
  • npm run test:coverage — full coverage run passes
  • npm run test:mutation — 87.8% mutation score on core logic
  • npm run build — TypeScript compiles cleanly to build/

🤖 Generated with Claude Code

thomaschaplin and others added 2 commits March 11, 2026 12:59
- Rewrote core ISIN generation logic in TypeScript (src/generate-isin.ts),
  replacing the old index.js CommonJS module with typed ES module exports
- Moved country codes from country-codes.json into a typed TS fixture
  (src/fixtures/country-codes.ts)
- Added optional countryCode parameter to generateIsin() so callers can
  pin the country code (e.g. generateIsin("US"))
- Fixed four bugs in the migrated code: CUSIP was generated once at module
  load (now per-call), orphaned dead statement removed, error was created
  but never thrown, and calculateValues/calculateCheckDigit were typed as
  string[] instead of number[]
- Added Jest test suite with deterministic assertions using a mocked CUSIP,
  covering correct check digit calculation for known ISINs (US0378331005,
  GB0378331002), case-insensitive country codes, per-call CUSIP generation,
  and a performance benchmark via kelonio
- Added Stryker mutation testing config; generate-isin.ts achieves 87.8%
  mutation score
- Added GitHub Actions CI workflow running build, coverage, and mutation
  tests on push/PR to master
- Added Dependabot config for daily npm dependency updates
- Added Husky pre-push hook with interactive merge-main and run-tests prompts
- Added examples/ directory with a standalone TypeScript usage example
- Added tsconfig.json, jest.config.js, stryker.conf.json, .nvmrc, and
  release/prepush shell scripts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Rewrote README to reflect TypeScript migration: updated usage examples
  to show the optional countryCode parameter, fixed the broken ES6 import,
  replaced ES5/ES6 sections with CommonJS/ESM, and added an API reference
  section
- Added CLAUDE.md with development commands, codebase architecture, and
  guidance for future Claude Code sessions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@thomaschaplin thomaschaplin merged commit 8c34e52 into master Mar 11, 2026
1 check passed
@thomaschaplin thomaschaplin deleted the move-to-typescript branch March 11, 2026 13:11
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.

1 participant