### Install Kennitala Package Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Install the kennitala library using npm. This is the first step before using any of its utilities. ```bash npm install kennitala ``` -------------------------------- ### Get Kennitala Information Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Use `info` to retrieve an object containing details about the kennitala, such as its type, validity, and birthday. Returns `undefined` if the kennitala is invalid. ```typescript info(kennitala: string): KennitalaInfo | undefined ``` -------------------------------- ### Get Detailed Kennitala Information Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Retrieve comprehensive details about a kennitala, including its validity, type (person/company), birthday, and age. ```javascript import { isValid, isPerson, isCompany, formatKennitala, info, generatePerson, generateCompany, } from 'kennitala'; // Get detailed information about a kennitala const kennitalaInfo = info('3108962099'); // kennitalaInfo contains: { kt: '3108962099', valid: true, type: 'person', birthday: new Date('1996-08-31T00:00:00.000Z'), birthdayReadable: 'Sat Aug 31 1996', age: 27, } ``` -------------------------------- ### Run Tests with Jest Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Execute the library's tests using the npm test command. ```bash npm test ``` -------------------------------- ### Build Project Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Compile the TypeScript code into the `dist/` folder using the npm run build command. ```bash npm run build ``` -------------------------------- ### generateCompany(date: Date): string Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Generates a valid kennitala for a company based on a `Date` object to specify the registration date. ```APIDOC ## generateCompany(date: Date): string ### Description Generates a valid kennitala for a company based on a `Date` object to specify the registration date. ### Parameters #### Path Parameters - **date** (Date) - Required - The date to use for generating the company kennitala. ### Returns - **string** - A valid kennitala string. ``` -------------------------------- ### info(kennitala: string): KennitalaInfo | undefined Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Returns an object containing information about the kennitala. ```APIDOC ## info(kennitala: string): KennitalaInfo | undefined ### Description Returns an object containing information about the kennitala. ### Parameters #### Path Parameters - **kennitala** (string) - Required - The kennitala string to analyze. ### Returns - **KennitalaInfo | undefined** - An object of type `KennitalaInfo` if valid, `undefined` otherwise. ### Response Body #### KennitalaInfo Type Definition ```typescript interface KennitalaInfo { kt: string; // The sanitized kennitala valid: boolean; // Whether the kennitala is valid type: "person" | "company" | "temporary" | "invalid"; // Type of kennitala age?: number; // Age calculated from the birthday (if applicable) birthday?: Date; // Date object representing the birthday (if applicable) birthdayReadable?: string; // Human-readable date string (if applicable) } ``` ``` -------------------------------- ### Generate Company Kennitala Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Use `generateCompany` to create a valid kennitala for a company, based on a provided date. ```typescript generateCompany(date: Date): string ``` -------------------------------- ### generatePerson(date: Date, startingIncrement = 20): string Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Generates a valid kennitala for a person based on a `Date` object to specify the birth date. ```APIDOC ## generatePerson(date: Date, startingIncrement = 20): string ### Description Generates a valid kennitala for a person based on a `Date` object to specify the birth date. ### Parameters #### Path Parameters - **date** (Date) - Required - The birth date to use for generating the kennitala. #### Query Parameters - **startingIncrement** (number) - Optional - The starting increment for digits 7 and 8 (default: 20). ### Returns - **string** - A valid kennitala string. ``` -------------------------------- ### isCompany(kennitala: string): boolean Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Checks if the kennitala is valid for a company. The day of birth must be between 41-71. Non-digit characters are removed before validation. ```APIDOC ## isCompany(kennitala: string): boolean ### Description Checks if the kennitala is valid for a company. The day of birth must be between 41-71. Non-digit characters are removed before validation. ### Parameters #### Path Parameters - **kennitala** (string) - Required - The kennitala string to validate. ### Returns - **boolean** - `true` if the kennitala is valid for a company, `false` otherwise. ``` -------------------------------- ### Generate Person Kennitala Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Use `generatePerson` to create a valid kennitala for a person, based on a provided birth date. The `startingIncrement` parameter controls the 7th and 8th digits. ```typescript generatePerson(date: Date, startingIncrement = 20): string ``` -------------------------------- ### sanitize(kennitala: string): string Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Sanitizes the input by removing all non-digit characters. ```APIDOC ## sanitize(kennitala: string): string ### Description Sanitizes the input by removing all non-digit characters. ### Parameters #### Path Parameters - **kennitala** (string) - Required - The kennitala string to sanitize. ### Returns - **string** - The sanitized kennitala string if input is valid, otherwise returns the `kennitala` string unchanged. ``` -------------------------------- ### formatKennitala(kennitala: string, spacer?: boolean): string Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Formats the kennitala by adding a `-` spacer between the 6th and 7th digits. Does not validate the input. ```APIDOC ## formatKennitala(kennitala: string, spacer?: boolean): string ### Description Formats the kennitala by adding a `-` spacer between the 6th and 7th digits. Does not validate the input. ### Parameters #### Path Parameters - **kennitala** (string) - Required - The kennitala string to format. #### Query Parameters - **spacer** (boolean) - Optional - Includes a `-` spacer character by default. ### Returns - **string** - The formatted kennitala string. ``` -------------------------------- ### isTemporary(kennitala: string): boolean Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Checks if the kennitala is a valid temporary ID. ```APIDOC ## isTemporary(kennitala: string): boolean ### Description Checks if the kennitala is a valid temporary ID. ### Parameters #### Path Parameters - **kennitala** (string) - Required - The kennitala string to validate. ### Returns - **boolean** - `true` if the kennitala is a valid temporary ID, `false` otherwise. ``` -------------------------------- ### Check if Kennitala is for a Company Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Use `isCompany` to validate a kennitala for a company. The day of birth must be between 41-71. Non-digit characters are removed before validation. ```typescript isCompany(kennitala: string): boolean ``` -------------------------------- ### isValid(kennitala: string): boolean Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Checks if the kennitala checksum is correct for either a person or company. Non-digit characters are removed before validation. ```APIDOC ## isValid(kennitala: string): boolean ### Description Checks if the kennitala checksum is correct for either a person or company. Non-digit characters are removed before validation. ### Parameters #### Path Parameters - **kennitala** (string) - Required - The kennitala string to validate. ### Returns - **boolean** - `true` if the kennitala is valid, `false` otherwise. ``` -------------------------------- ### Check if Kennitala is Temporary Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Use `isTemporary` to determine if a kennitala is a valid temporary ID. ```typescript isTemporary(kennitala: string): boolean ``` -------------------------------- ### Format Kennitala Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Use `formatKennitala` to add a hyphen after the 6th digit. This function does not validate the input kennitala. The spacer is included by default. ```typescript formatKennitala(kennitala: string, spacer?: boolean): string ``` -------------------------------- ### Sanitize Kennitala Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Remove hyphens from a kennitala string for consistent storage or processing. This is recommended before storing in databases. ```javascript import { sanitize } from "kennitala"; const sanitizedKennitala = sanitize("310896-2099"); // returns '3108962099' ``` -------------------------------- ### isPerson(kennitala: string): boolean Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Checks if the kennitala is valid for a person. The day of birth must be between 1-31. Non-digit characters are removed before validation. ```APIDOC ## isPerson(kennitala: string): boolean ### Description Checks if the kennitala is valid for a person. The day of birth must be between 1-31. Non-digit characters are removed before validation. ### Parameters #### Path Parameters - **kennitala** (string) - Required - The kennitala string to validate. ### Returns - **boolean** - `true` if the kennitala is valid for a person, `false` otherwise. ``` -------------------------------- ### Check Kennitala Validity Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Use `isValid` to check if a kennitala has a correct checksum. Non-digit characters are removed before validation. ```typescript isValid(kennitala: string): boolean ``` -------------------------------- ### KennitalaInfo Type Definition Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Defines the structure of the object returned by the `info` function, including the sanitized kennitala, validity status, type, age, and birthday. ```typescript interface KennitalaInfo { kt: string; // The sanitized kennitala valid: boolean; // Whether the kennitala is valid type: "person" | "company" | "temporary" | "invalid"; // Type of kennitala age?: number; // Age calculated from the birthday (if applicable) birthday?: Date; // Date object representing the birthday (if applicable) birthdayReadable?: string; // Human-readable date string (if applicable) } ``` -------------------------------- ### Check if Kennitala is for a Person Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Use `isPerson` to validate a kennitala for a person. The day of birth must be between 1-31. Non-digit characters are removed before validation. ```typescript isPerson(kennitala: string): boolean ``` -------------------------------- ### Validate Kennitala Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Check if a given string is a valid Icelandic national ID. This function accepts both person and company kennitölur. ```javascript import { isValid } from "kennitala"; // Check if a kennitala is valid for either a person or a company isValid("3108962099"); // returns true isValid("8281249124"); // returns false ``` -------------------------------- ### Check if Kennitala is for a Company Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Determine if a kennitala is specifically valid for a company. This function returns false for person kennitölur. ```javascript // Check if a kennitala is valid for a company (returns false for persons) isCompany('6010100890'); // returns true isCompany('601010-0890'); // returns true isCompany('3108962099'); // returns false ``` -------------------------------- ### Sanitize Kennitala Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Use `sanitize` to remove all non-digit characters from a kennitala string. If the input is invalid, the original string is returned. ```typescript sanitize(kennitala: string): string ``` -------------------------------- ### Format Kennitala with Hyphen Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Add a traditional hyphen separator to a kennitala string. An optional boolean argument can be used to disable formatting. ```javascript // Format a kennitala by adding a traditional '-' spacer formatKennitala('3108962099'); // returns '310896-2099' formatKennitala('3108962099', false); // returns '3108962099' ``` -------------------------------- ### Check if Kennitala is for a Person Source: https://github.com/hermannbjorgvin/kennitala/blob/master/README.md Determine if a kennitala is specifically valid for a person. This function returns false for company kennitölur and invalid inputs. ```javascript // Check if a kennitala is valid for a person (returns false for companies) isPerson('3108962099'); // returns true isPerson('601010-0890'); // returns false (invalid date) isPerson(3108962099); // returns false (invalid input type) isPerson('31^_^08!!96LOL20T_T99'); // returns false (invalid format) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.