A modern and lightweight library for validating emails, identity cards (ID), IBANs, passports, and phone numbers. ✅
Install the library using your favorite package manager:
# Using npm
npm install validate-kaike-js
# Using yarn
yarn add validate-kaike-js
# Using pnpm
pnpm add validate-kaike-js
The validate
function must always be used for both single and multiple validations, ensuring consistency and simplicity in implementation.
import {
validate,
validateEmail,
validateIdentityCard,
validateIban,
validatePassport,
validatePhoneCountryCode,
} from "validate-kaike-js";
validate([{ fn: validateEmail, input: "test@email.com", provider: "GMAIL" }])
.then(console.log)
.catch(console.error);
validate([{ fn: validateIdentityCard, input: "123456789LA001", country: "AO" }])
.then(console.log)
.catch(console.error);
If the input is invalid, an error will be thrown:
validate([{ fn: validateEmail, input: "invalid_email", provider: "GMAIL" }]).catch(console.error);
Output:
[{ message: "Invalid email", value: "invalid_email" }];
Validate multiple inputs simultaneously with validate()
:
validate([
{ fn: validateEmail, input: "test@email.com", provider: "GMAIL" },
{ fn: validateIdentityCard, input: "123456789LA001", country: "AO" },
{ fn: validateIban, input: "AO06123456789012345678901", country: "AO" },
{ fn: validatePassport, input: "A1234567", country: "US" },
{ fn: validatePhoneCountryCode, input: "+244923456789", phoneCountryCode: "+244" },
])
.then(console.log)
.catch(console.error);
✅ If all validations pass, the return will be an array with the results:
[
{ message: "Valid email", value: "test@email.com" },
{ message: "Valid identity card", value: "123456789LA001" },
{ message: "Valid IBAN", value: "AO06123456789012345678901" },
{ message: "Valid Passport", value: "A1234567" },
{ message: "Valid phone country code", value: "+244923456789" },
];
❌ If any validation fails, validate
rejects the promise with an array of errors:
validate([{ fn: validateEmail, input: "invalid_email", provider: "GMAIL" }]).catch(console.error);
Output:
[{ message: "Invalid email", value: "invalid_email" }];
Method | Validates | Valid Example | Invalid Example | Additional Argument |
---|---|---|---|---|
validateEmail |
test@email.com |
invalid_email |
provider (only for this method) |
|
validateIdentityCard |
Identity card | 123456789LA001 |
12345ABC |
country (only for this method) |
validateIban |
IBAN | AO06123456789012345678901 |
123456 |
country (only for this method) |
validatePassport |
Passport | A1234567 |
XYZ12 |
country (only for this method) |
validatePhoneCountryCode |
Phone country code | +244923456789 |
+000000000000 |
phoneCountryCode (only for this method) |
MIT © 2025 - Kaike Bartolomeu