{"id":13452173,"url":"https://github.com/HermannBjorgvin/Kennitala","last_synced_at":"2025-03-23T19:33:46.729Z","repository":{"id":41397988,"uuid":"43650436","full_name":"HermannBjorgvin/Kennitala","owner":"HermannBjorgvin","description":"Icelandic national ID (kennitölur) utilities for servers and clients.","archived":false,"fork":false,"pushed_at":"2023-11-20T15:52:03.000Z","size":144,"stargazers_count":34,"open_issues_count":4,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-19T03:20:34.004Z","etag":null,"topics":["iceland","kennitala","nationalidvalidation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HermannBjorgvin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-04T19:54:18.000Z","updated_at":"2024-06-05T20:18:43.000Z","dependencies_parsed_at":"2024-06-18T21:52:54.257Z","dependency_job_id":null,"html_url":"https://github.com/HermannBjorgvin/Kennitala","commit_stats":{"total_commits":102,"total_committers":6,"mean_commits":17.0,"dds":0.3137254901960784,"last_synced_commit":"c70521ace9fe01cc4b03db49f065337c2c85eec4"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HermannBjorgvin%2FKennitala","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HermannBjorgvin%2FKennitala/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HermannBjorgvin%2FKennitala/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HermannBjorgvin%2FKennitala/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HermannBjorgvin","download_url":"https://codeload.github.com/HermannBjorgvin/Kennitala/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221900729,"owners_count":16898986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iceland","kennitala","nationalidvalidation"],"created_at":"2024-07-31T07:01:15.923Z","updated_at":"2025-03-23T19:33:46.713Z","avatar_url":"https://github.com/HermannBjorgvin.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Kennitala\n\nIcelandic national ID (kennitölur) utilities for servers and clients. Now with TypeScript support!\n\n[![Build Status](https://github.com/HermannBjorgvin/Kennitala/actions/workflows/ci.yml/badge.svg)](https://github.com/HermannBjorgvin/Kennitala/actions)\n[![npm](https://img.shields.io/npm/v/kennitala.svg)](https://www.npmjs.com/package/kennitala)\n[![npm](https://img.shields.io/npm/dm/kennitala.svg)](https://www.npmjs.com/package/kennitala)\n![npm bundle size](https://img.shields.io/bundlephobia/min/kennitala)\n\nInstall with npm:\n\n```bash\nnpm install kennitala\n```\n\n### Examples\n\n```javascript\nimport { isValid } from \"kennitala\";\n\n// Check if a kennitala is valid for either a person or a company\nisValid(\"3108962099\"); // returns true\nisValid(\"8281249124\"); // returns false\n```\n\n### Heads Up for Storing in Databases\n\nThis library validates kennitölur both with `-` spacers and without, so remember to **sanitize** your kennitala before storing it in a database!\n\nYou can use the included `sanitize` function:\n\n```javascript\nimport { sanitize } from \"kennitala\";\n\nconst sanitizedKennitala = sanitize(\"310896-2099\");\n// returns '3108962099'\n```\n\n### More Examples\n\n```javascript\nimport {\n  isValid,\n  isPerson,\n  isCompany,\n  formatKennitala,\n  info,\n  generatePerson,\n  generateCompany,\n} from 'kennitala';\n\n// Get detailed information about a kennitala\nconst kennitalaInfo = info('3108962099');\n// kennitalaInfo contains:\n{\n  kt: '3108962099',\n  valid: true,\n  type: 'person',\n  birthday: new Date('1996-08-31T00:00:00.000Z'),\n  birthdayReadable: 'Sat Aug 31 1996',\n  age: 27,\n}\n\n// Check if a kennitala is valid for a person (returns false for companies)\nisPerson('3108962099');            // returns true\nisPerson('601010-0890');           // returns false (invalid date)\nisPerson(3108962099);              // returns false (invalid input type)\nisPerson('31^_^08!!96LOL20T_T99'); // returns false (invalid format)\n\n// Check if a kennitala is valid for a company (returns false for persons)\nisCompany('6010100890');  // returns true\nisCompany('601010-0890'); // returns true\nisCompany('3108962099');  // returns false\n\n// Format a kennitala by adding a traditional '-' spacer\nformatKennitala('3108962099');       // returns '310896-2099'\nformatKennitala('3108962099', false); // returns '3108962099'\n```\n\n### API Documentation\n\nBelow is the API based on the type definitions from the refactored TypeScript library.\n\n#### `isValid(kennitala: string): boolean`\n\nChecks if the kennitala checksum is correct for either a person or company. Non-digit characters are removed before validation.\n\n- **Parameters:**\n\n  - `kennitala`: The kennitala string to validate.\n\n- **Returns:** `true` if the kennitala is valid, `false` otherwise.\n\n#### `isPerson(kennitala: string): boolean`\n\nChecks if the kennitala is valid for a person. The day of birth must be between 1-31. Non-digit characters are removed before validation.\n\n- **Parameters:**\n\n  - `kennitala`: The kennitala string to validate.\n\n- **Returns:** `true` if the kennitala is valid for a person, `false` otherwise.\n\n#### `isCompany(kennitala: string): boolean`\n\nChecks if the kennitala is valid for a company. The day of birth must be between 41-71. Non-digit characters are removed before validation.\n\n- **Parameters:**\n\n  - `kennitala`: The kennitala string to validate.\n\n- **Returns:** `true` if the kennitala is valid for a company, `false` otherwise.\n\n#### `isTemporary(kennitala: string): boolean`\n\nChecks if the kennitala is a valid temporary ID.\n\n- **Parameters:**\n\n  - `kennitala`: The kennitala string to validate.\n\n- **Returns:** `true` if the kennitala is a valid temporary ID, `false` otherwise.\n\n#### `sanitize(kennitala: string): string`\n\nSanitizes the input by removing all non-digit characters.\n\n- **Parameters:**\n\n  - `kennitala`: The kennitala string to sanitize.\n\n- **Returns:** The sanitized kennitala string if input is valid, otherwise returns the `kennitala` string unchanged.\n\n#### `formatKennitala(kennitala: string, spacer?: boolean): string`\n\nFormats the kennitala by adding a `-` spacer between the 6th and 7th digits. Does not validate the input.\n\n- **Parameters:**\n\n  - `kennitala`: The kennitala string to format.\n  - `spacer` (optional): Includes a `-` spacer character by default.\n\n- **Returns:** The formatted kennitala string.\n\n#### `info(kennitala: string): KennitalaInfo | undefined`\n\nReturns an object containing information about the kennitala.\n\n- **Parameters:**\n\n  - `kennitala`: The kennitala string to analyze.\n\n- **Returns:** An object of type `KennitalaInfo` if valid, `undefined` otherwise.\n\n**`KennitalaInfo` Type Definition:**\n\n```typescript\ninterface KennitalaInfo {\n  kt: string; // The sanitized kennitala\n  valid: boolean; // Whether the kennitala is valid\n  type: \"person\" | \"company\" | \"temporary\" | \"invalid\"; // Type of kennitala\n  age?: number; // Age calculated from the birthday (if applicable)\n  birthday?: Date; // Date object representing the birthday (if applicable)\n  birthdayReadable?: string; // Human-readable date string (if applicable)\n}\n```\n\n#### `generatePerson(date: Date, startingIncrement = 20): string`\n\nGenerates a valid kennitala for a person based on a `Date` object to specify the birth date.\n\n- **Parameters:**\n\n  - `date`: The birth date to use for generating the kennitala.\n  - `startingIncrement`: The starting increment for digits 7 and 8 (default: 20).\n\n- **Returns:** A valid kennitala string.\n\n#### `generateCompany(date: Date): string`\n\nGenerates a valid kennitala for a company based on a `Date` object to specify the registration date.\n\n- **Parameters:**\n\n  - `date`: The date to use for generating the company kennitala.\n\n- **Returns:** A valid kennitala string.\n\n### Testing\n\nThe library uses [Jest](https://jestjs.io/) for testing. To run the tests, use:\n\n```bash\nnpm test\n```\n\n### Building\n\nTo build the project, run:\n\n```bash\nnpm run build\n```\n\nThis will compile the TypeScript code and place the output in the `dist/` folder.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHermannBjorgvin%2FKennitala","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHermannBjorgvin%2FKennitala","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHermannBjorgvin%2FKennitala/lists"}