feat: add generate() to structural validators#68
Merged
jan-kubica merged 2 commits intomainfrom Mar 22, 2026
Merged
Conversation
|
| Filename | Overview |
|---|---|
| src/ad/nrt.ts | Generator is correct but silently omits valid prefixes "A", "F", "L" which have digit-range constraints; all generated values still pass validate(). |
| src/ai/tin.ts | Uses Math.random() < 0.5 for prefix selection instead of the randomInt helper used consistently across all other generators in this PR. |
| src/bic.ts | Generator hardcodes only 7 country codes despite the validator accepting any [A-Z]{2} code; limits diversity of generated test values. |
| src/us/ssn.ts | Generator correctly avoids area "000", "666", 900–999, group "00", serial "0000", and all three blacklisted SSNs via the outer for(;;) loop. |
| src/us/itin.ts | Generator correctly constrains area to start with "9" and group to 70–99 excluding 89 and 93, matching the validator exactly. |
| src/gb/nino.ts | Generator correctly rejects both invalid first/second letter sets and invalid two-letter prefixes via a do-while loop; format and suffix are correct. |
| src/kr/brn.ts | Generator correctly enforces all three validator constraints: office ≥ 101, bizType ≠ "00", serial ≠ "0000". |
| src/in/pan.ts | Generator correctly selects holder type from the same HOLDER_TYPES string used by the validator and produces a 10-character value matching PAN_RE. |
| src/pk/cnic.ts | Generator correctly produces 13 digits with province from VALID_PROVINCES (1–7) and gender digit from 1–9, satisfying all validator constraints. |
| src/us/ein.ts | Generator uses a comprehensive hardcoded list of valid EIN prefixes and consistently uses randomInt for selection. |
Sequence Diagram
sequenceDiagram
participant Caller
participant generate
participant validate
Caller->>generate: generate()
activate generate
generate->>generate: randomInt / randomDigits
generate-->>Caller: structurally valid string
deactivate generate
Caller->>validate: validate(generated)
activate validate
validate->>validate: compact()
validate->>validate: length / format checks
validate->>validate: component checks (RMO, prefix, group…)
validate-->>Caller: { valid: true, compact: … }
deactivate validate
note over generate,validate: Contract: validate(generate()) must always return valid: true
Reviews (2): Last reviewed commit: "fix: address review comments" | Re-trigger Greptile
- us/itin: use randomInt instead of Math.random for group selection (was causing unused import) - us/ssn: add blacklist check in generate() loop to prevent producing known-invalid SSNs; drop unused randomDigits import - de/handelsreg, us/ein: use randomInt for array selection, consistent with all other generators
Contributor
Author
|
All items addressed in b9d7037:
CC on behalf of @jan-kubica |
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
generate()functions to 27 structural (no-checksum) validatorsvalidate()functionTest plan
bun test)