Lightweight npm library that provides different financial validators


Keywords
typescript, nodejs, finance, validators, banking, payment, credit card, npm, swift, iban, bic, cvv, expiry date, credit card number, routing number
License
MIT
Install
npm install valifino@0.0.1

Documentation

Valifino

npm package Build Status Downloads Issues Code Coverage Commitizen Friendly Semantic Release

A comprehensive library of financial validators for Node.js, built using TypeScript. This library provides a set of functions to validate various financial instruments and formats such as credit card numbers, IBANs, SWIFT/BIC codes, and more.

Valifino

Install

npm install valifino

Features

API

isValidCreditCardNumber(cardNumber: string): boolean

Validates a credit card number using the Luhn algorithm.

Example:

import { isValidCreditCardNumber} from 'valifino';

/**
 * @param {string} cardNumber - The card number in string format.
 * @returns True if the card number is valid, false otherwise.
 */
isValidCreditCardNumber('4111111111111111'); // => true

isValidCVV(cardType: string, cvv: string): boolean

Validates the CVV code of a credit card based on the card type.

Example:

import { isValidCVV } from 'valifino';

/**
 * Validates the CVV code for the given card type.
 * @param {string} cvv - The CVV code to validate.
 * @param {string} cardType - The type of the card (e.g., CardType.Visa, CardType.MasterCard).
 * @returns True if the CVV is valid, false otherwise.
 */
isValidCVV(123, 'Visa'); // => true
isValidCVV(432, 'Amex'); // => false

isValidExpirationDate(expirationDate: string): boolean

Validates the expiration date of a credit card.

import { isValidExpirationDate } from 'valifino';

/**
 * @param {string} expirationDate - The expiration date in the format MM/YY or MM/YYYY.
 * @returns True if the expiration date is valid, false otherwise.
 */
isValidExpirationDate('12/2029'); // => true
isValidExpirationDate('01-2025'); // => false

isValidIBAN(iban: string): boolean

Validates an International Bank Account Number (IBAN) for multiple countries.

import { isValidIBAN } from 'valifino';

/**
 * Checks whether a given string is a valid International Bank Account Number (IBAN).
 * @param {string} iban The IBAN to validate.
 * @returns `true` if the IBAN is valid, `false` otherwise.
 */
isValidIBAN('MD75EX0900002374642125EU'); // => true (Moldova IBAN)
isValidIBAN('BE68539007547035'); // => false (incorrect digit check)

isValidBBAN(countryCode: string, bban: string): boolean

Validates a Basic Bank Account Number (BBAN) for multiple countries.

import { isValidBBAN } from './valifino';

/**
 * Checks if the provided BBAN (Basic Bank Account Number) is valid for a given country.
 *
 * @param {string} countryCode - The two-letter ISO country code.
 * @param {string} bban - The BBAN to validate.
 * @returns True if the BBAN is valid for the specified country, false otherwise.
 */
isValidBBAN('BE', '539007547034'); // => true (Belgium)
isValidBBAN('BE', 'ABC-0075470-34); // => false

isValidSWIFT(swiftCode: string): boolean

Validates a SWIFT/BIC code.

import { isValidSWIFT } from 'valifino';

/**
 * Validates a SWIFT/BIC code.
 * @param {string} swiftCode - The SWIFT/BIC code to validate.
 * @returns True if the SWIFT/BIC code is valid, false otherwise.
 */
isValidSWIFT('DEUTDEFF'); // => true (Deutsche Bank)
isValidSWIFT('DEUTDEFF!'); // => false (invalid character)

isValidUSRoutingNumber(routingNumber: string): boolean

Validates a US routing number with ABA algorithm.

import { isValidUSRoutingNumber } from 'valifino';

/**
 * Validates a US routing number.
 * @param {string} routingNumber - The US routing number to validate.
 * @returns True if the routing number is valid, false otherwise.
 */
isValidUSRoutingNumber('021000021'); // => true
isValidUSRoutingNumber('021000021!'); // => false (invalid character)

isValidCurrencyCode(currencyCode: string): boolean

Validates a currency code based on the ISO 4217 standard.

import { isValidCurrencyCode } from 'valifino';

/**
 * Validates a currency code against the ISO 4217 standard.
 * @param {string} currencyCode - The currency code to validate.
 * @returns True if the currency code is valid, false otherwise.
 */
isValidCurrencyCode('USD'); // => true
isValidCurrencyCode('XYZ'); // => false

isValidTransactionAmount(amount: number): boolean

Validates a transaction amount (up to 2 decimal places are allowed).

import { isValidTransactionAmount } from 'valifino';

/**
 * Validates a transaction amount (up to 2 decimal places are allowed).
 * @param {number} amount - The transaction amount to validate.
 * @returns True if the transaction amount is valid, false otherwise.
 */
isValidTransactionAmount(100.0); // => true
isValidTransactionAmount(100.1234); // => false
isValidTransactionAmount(-50.00); // => false

isValidEthereumWalletAddress(walletAddress: string): boolean

Validates an Ethereum crypto wallet address.

import { isValidEthereumWalletAddress } from 'valifino';

/**
 * Validates an Ethereum crypto wallet address.
 * @param {string} walletAddress - The Ethereum wallet address to validate.
 * @returns True if the wallet address is valid, false otherwise.
 */
isValidEthereumWalletAddress('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); // => true
isValidEthereumWalletAddress('de0B295669a9FD93d5F28D9Ec85E40f4cb697BAe!'); // => false

We Value Your Feedback

At Valifino, we strive to continuously improve and provide the best financial validation library for the community. Your feedback is crucial in helping us achieve this goal!

If you encounter any issues, have suggestions, or would like to request new features, please don't hesitate to open an issue. We welcome and appreciate all contributions, whether it's reporting bugs, sharing ideas, or helping us enhance existing features.

Thank you for supporting Valifino! Together, we can make financial validations easier and more reliable.