Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
32 changes: 32 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: "npm"

- name: Install
run: npm ci

- name: Build
run: npm run build

- name: Test (coverage)
run: npm run test:coverage

- name: Test (mutation)
run: npm run test:mutation
96 changes: 5 additions & 91 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,92 +1,6 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
node_modules
build
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# gatsby files
.cache/
public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/
.kelonio.state.json
*.stryker-tmp
reports
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run pre-push
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
3 changes: 3 additions & 0 deletions .prepush.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
main_branch=master
merge_main_branch=true
run_tests=true
49 changes: 49 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Commands

```bash
npm install # install dependencies
npm run build # compile TypeScript to build/
npm run watch # compile in watch mode
npm test # run tests
npm run test:coverage # run tests with coverage report
npm run test:mutation # run Stryker mutation tests (~3 min)
```

To run a single test file:
```bash
npx jest src/__tests__/generate-isin.spec.ts
```

To run a test by name:
```bash
npx jest -t "should generate the correct check digit"
```

## Architecture

This is a small npm library (`@thomaschaplin/isin-generator`) that generates valid 12-character ISINs. It depends on `@thomaschaplin/cusip-generator` to supply the 9-character CUSIP component of each ISIN.

**ISIN structure:** `[2-char country code] + [9-char CUSIP] + [1 check digit]`

### Source layout

- `src/generate-isin.ts` — core logic. `generateIsin(countryCode?: string)` picks a random country code (or uses the one provided), calls `generateCusip()` fresh each invocation, then computes a Luhn-variant check digit via `calculateValues` → `calculateCheckDigit`.
- `src/fixtures/country-codes.ts` — exported `string[]` of ISO 3166-1 alpha-2 country codes used for random selection.
- `src/index.ts` — re-exports `generateIsin` as the public API.
- `build/` — compiled output (gitignored); this is what gets published to npm per the `files` field in `package.json`.

### Check digit algorithm

The `generateIsinCheckDigit` function is called with a 12-character string (`code + cusip + '0'`). `calculateValues` iterates indices 0–10 (skipping the placeholder check digit at index 11), converts letters to their numeric equivalent via `charCode - 55`, and splits two-digit results. `calculateCheckDigit` then applies a Luhn-style doubling of even-indexed values to produce the final digit.

### Testing approach

Tests mock `@thomaschaplin/cusip-generator` with a fixed CUSIP (`"037833100"`) to enable deterministic assertions on exact ISIN output (e.g. `"US0378331005"`). When adding tests for the check digit logic, use this pattern — asserting exact output kills far more mutations than length-only checks.

### Pre-push hook

Husky runs `prepush.sh` before every push, which reads `.prepush.config` and interactively prompts to merge `master` and/or run tests. In non-interactive environments (e.g. CI) the `/dev/tty` read will fail gracefully and the push continues.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Thomas Chaplin
Copyright (c) 2023 Thomas Chaplin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading