-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.ts
More file actions
27 lines (23 loc) · 820 Bytes
/
Copy pathmod.ts
File metadata and controls
27 lines (23 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Lithuanian national identification number generator
*
* Outputs a valid random nin when called.
*/
import { format } from "./deps.ts";
import { calculateG, checksum, Gender } from "./src/lt-nin-rules.ts";
import { birthDate, gender, serialNumber } from "./src/property-generator.ts";
export function generateNIN(year: number | null, verbose: boolean) {
const bdArg = year ? { firstYear: year, lastYear: year } : {};
const bd = birthDate(bdArg);
const gd = gender();
if (verbose) {
console.log(
`Birth date: ${format(bd, "yyyy-MM-dd")}\n`,
` Gender: ${Gender[gd]}\n`,
);
}
const identificationNumber = calculateG(bd.getFullYear(), gd).toString() +
format(bd, "yyMMdd") +
serialNumber().toString();
return identificationNumber + checksum(identificationNumber);
}