Lietuviškų asmens kodo / įmonės kodo tikrinimo bei generavimo funkcijos
Examples can be found here:
- www.pranciskus.com/asmens-kodas for validating and generating personal codes
- www.pranciskus.com/imones-kodas for validating and generating company codes
npm install lt-codes
yarn add lt-codes
import { personalCode, companyCode } from 'lt-codes';
Function | Description |
---|---|
personalCode.validate(code: string) |
Validates personal code |
personalCode.generate() |
Generates personal code |
const code = '39001010000'; // example
const generatedCode = personalCode.generate();
const { isValid, isException, error } = personalCode.validate(code);
{
"isValid": true,
"error": "",
"isException": true
}
import { ValidationResult } from 'lt-codes';
const result: ValidationResult = personalCode.validate(code);
Function | Description |
---|---|
companyCode.validate(code: string) |
Validates company code |
companyCode.generate() |
Generates company code |
const code = '123456789'; // example
const generatedCode = companyCode.generate();
const { isValid, isException, error } = companyCode.validate(code);
{
"isValid": true,
"error": "",
"isException": false
}
import { ValidationResult } from 'lt-codes';
const result: ValidationResult = companyCode.validate(code);
You can import all error types from lt-codes
as use as constants.
import { ValidationError } from 'lt-codes';
error
property returned by validate()
can be empty or one of the following values:
Value | Description |
---|---|
ValidationError.EMPTY |
Code not passed (empty) |
ValidationError.INVALID |
Do not pass regex checker |
ValidationError.INVALID_CONTROL_NUMBER |
Invalid control number (last digit) |
ValidationError.INVALID_DATE |
Invalid user birth date |