Registry / security / kennitala-utility

kennitala-utility

JSON →
library6.1.2jsnpmunverified

Utility functions for Icelandic social security numbers (kennitolur). Written in TypeScript, supports both CommonJS and ES Modules. Current stable version is 6.1.2. Released as needed, with changelog on GitHub. Key differentiator: comprehensive set of functions for formatting, validation, date extraction, and company detection. Includes full TypeScript type definitions.

npm install kennitala-utility
INSTALL
IMPORT
SIG · KENNITALA-UTILITY
K
kennitala-utility
securityjavascriptv6.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import kennitala from 'kennitala-utility'
const kennitala = require('kennitala-utility').default
Default import works in ESM (TypeScript) and CommonJS (with esModuleInterop). In CJS, require will give the module object; use .default if using default export.
format
import { format } from 'kennitala-utility'
const format = require('kennitala-utility').format
Named import for individual functions. CommonJS require also works as shown.
isValid
import { isValid } from 'kennitala-utility'
const { isValid } = require('kennitala-utility').default
Named import is correct. CommonJS destructuring works directly from the module.
getAge
import { getAge } from 'kennitala-utility'
Named import for getAge. Takes a second optional parameter referenceDate.
clean
import { clean } from 'kennitala-utility'
const clean = require('kennitala-utility').clean
Both import styles work.

Shows how to import and use key functions: format, isValid, getAge, clean, and makeKennitala.

import { format, isValid, getAge, clean, makeKennitala } from 'kennitala-utility'; const rawKt = '120174-3399'; console.log('Formatted:', format(rawKt)); // '120174-3399' console.log('Valid:', isValid(rawKt)); // true console.log('Age:', getAge(rawKt)); // e.g., 50 console.log('Cleaned:', clean(rawKt)); // '1201743399' const birthdate = new Date('1974-01-12'); const newKt = makeKennitala(birthdate); console.log('Generated kennitala:', newKt); // e.g., '1201743399'
Debug
Known issues
gotchaThe function 'clean' does not validate the kennitala; it only removes non-digit characters. Use 'cleanAndValidate' for validation.
fix
Use cleanAndValidate() if you need both cleaning and validation.
affects: >=1.0.0
gotchaThe function 'isValid' accepts strings with or without the hyphen, but returns false for invalid formats or checksum errors.
fix
Always validate input; the function expects either 10 digits or format 'XXXXXX-XXXX'.
affects: >=1.0.0
gotchaThe function 'getAge' can take an optional reference date. If omitted, it uses the current date. Ensure you pass a Date object for consistency.
fix
Pass a reference date if you need age at a specific time, e.g., getAge('1201743399', new Date('2024-01-01')).
affects: >=1.0.0
gotchaThe function 'makeKennitala' generates a valid kennitala for a given birthdate, but the random suffix may change on each call.
fix
Do not rely on deterministic outputs; the suffix is random.
affects: >=1.0.0
deprecatedPrevious versions (before 6.0) had a different API. Check the changelog for migration.
fix
Upgrade to v6.x and update imports as shown in the docs.
affects: <6.0.0
Errors
Common errors & fixes
Error: Cannot find module 'kennitala-utility'
Package not installed or missing from node_modules.
fix
Run 'npm install kennitala-utility' or 'yarn add kennitala-utility' in your project.
TypeError: kennitala.isValid is not a function
Using an incorrect import (e.g., default import for named function).
fix
Use named import: import { isValid } from 'kennitala-utility'
Module parse failed: Unexpected token (1:44)
Project uses CommonJS require with a default import in TypeScript without esModuleInterop.
fix
Set 'esModuleInterop': true in tsconfig.json, or use import = require syntax.
Error: Invalid kennitala format
Passing a string that doesn't match the expected format (e.g., missing hyphen, wrong length).
fix
Ensure the kennitala is either 10 digits or in the format 'XXXXXX-XXXX'. Use clean() first to remove spaces or dashes.
Upgrade
Version history
6.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
kennitala-utility — npm install kennitala-utility · libregistry