![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Icelandic social security number (kennitölur) utilities for servers and clients
Icelandic national ID (kennitölur) utilities for servers and clients. Now with TypeScript support!
Install with npm:
npm install kennitala
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
This library validates kennitölur both with -
spacers and without, so remember to sanitize your kennitala before storing it in a database!
You can use the included sanitize
function:
import { sanitize } from "kennitala";
const sanitizedKennitala = sanitize("310896-2099");
// returns '3108962099'
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,
}
// 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)
// 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
// Format a kennitala by adding a traditional '-' spacer
formatKennitala('3108962099'); // returns '310896-2099'
formatKennitala('3108962099', false); // returns '3108962099'
Below is the API based on the type definitions from the refactored TypeScript library.
isValid(kennitala: string, options?: { allowTestKennitala?: boolean }): boolean
Checks if the kennitala checksum is correct for either a person or company. Non-digit characters are removed before validation.
Parameters:
kennitala
: The kennitala string to validate.options
(optional): An object with the following property:
allowTestKennitala
(default: false
): Set to true
to allow validation of test kennitala numbers.Returns: true
if the kennitala is valid, false
otherwise.
isPerson(kennitala: string, options?: { allowTestKennitala?: boolean }): boolean
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:
kennitala
: The kennitala string to validate.options
(optional): Same as in isValid
.Returns: true
if the kennitala is valid for a person, false
otherwise.
isCompany(kennitala: string): boolean
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:
kennitala
: The kennitala string to validate.Returns: true
if the kennitala is valid for a company, false
otherwise.
isTemporary(kennitala: string): boolean
Checks if the kennitala is a valid temporary ID.
Parameters:
kennitala
: The kennitala string to validate.Returns: true
if the kennitala is a valid temporary ID, false
otherwise.
sanitize(kennitala: string): string | undefined
Sanitizes the input by removing all non-digit characters.
Parameters:
kennitala
: The kennitala string to sanitize.Returns: The sanitized kennitala string if input is valid, undefined
otherwise.
formatKennitala(kennitala: string, spacer?: boolean): string
Formats the kennitala by adding a -
spacer between the 6th and 7th digits. Does not validate the input.
Parameters:
kennitala
: The kennitala string to format.spacer
(optional): Includes a -
spacer character by default.Returns: The formatted kennitala string.
info(kennitala: string): KennitalaInfo | undefined
Returns an object containing information about the kennitala.
Parameters:
kennitala
: The kennitala string to analyze.Returns: An object of type KennitalaInfo
if valid, undefined
otherwise.
KennitalaInfo
Type Definition:
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)
}
generatePerson(date?: Date): string | undefined
Generates a valid kennitala for a person. Optionally accepts a Date
object to specify the birth date.
Parameters:
date
(optional): The birth date to use for generating the kennitala.Returns: A valid kennitala string if generation is successful, undefined
otherwise.
generateCompany(date?: Date): string | undefined
Generates a valid kennitala for a company. Optionally accepts a Date
object to specify the registration date.
Parameters:
date
(optional): The date to use for generating the company kennitala.Returns: A valid kennitala string if generation is successful, undefined
otherwise.
The library uses Jest for testing. To run the tests, use:
npm test
To build the project, run:
npm run build
This will compile the TypeScript code and place the output in the dist/
folder.
FAQs
Icelandic social security number (kennitölur) utilities for servers and clients
The npm package kennitala receives a total of 0 weekly downloads. As such, kennitala popularity was classified as not popular.
We found that kennitala demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.