1.0.0 • Published 6 months ago

all-validators v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

Summary

The AllValidators is a class that provides a set of validators for form controls. It contains methods for validating various types of data such as email, credit card number, IBAN, BIC, DNI, NIE, CIF, passport, date, and numeric values.

Example Usage

// Validate an email
const isValidEmail = AllValidators.email("test@example.com");
// Output: true

// Validate a credit card number
const isValidCardNumber = AllValidators.creditCardNumber(
  "1234567890123456",
  "Visa"
);
// Output: true

// Validate a date
const isValidDate = AllValidators.date("2022-01-01");
// Output: true

// Validate a numeric value
const isNumber = AllValidators.isNumber("123.45", true, true);
// Output: true

Code Analysis

Main functionalities

  • Provides validators for various types of data such as email, credit card number, IBAN, BIC, DNI, NIE, CIF, passport, date, and numeric values.
  • Allows validation of dates based on different comparisons such as after, before, same, same or after, same or before, and between dates.
  • Supports validation of maximum and minimum values.
  • Provides validation for empty values.

Methods

  • email(value: string): boolean: Validates an email address.
  • ccc(value: string): boolean: Validates a bank account number.
  • creditCardNumber(value: string, type?: string): boolean: Validates a credit card number, with an optional card type parameter.
  • iban(value: string): boolean: Validates an IBAN.
  • bic(value: string): boolean: Validates a BIC/SWIFT code.
  • dni(value: string): boolean: Validates a Spanish DNI (National Identity Document) number.
  • nie(value: string): boolean: Validates a Spanish NIE (Foreigner Identification Number) number.
  • cif(value: string): boolean: Validates a Spanish CIF (Tax Identification Code) number.
  • passport(value: string): boolean: Validates a passport number.
  • date(value: string): boolean: Validates a date in the format "YYYY-MM-DD".
  • isAfterDate(value: string, compare: any, precision?: TimeRanges): boolean: Validates if a date is after another date.
  • isBeforeDate(value: string, compare: any, precision?: TimeRanges): boolean: Validates if a date is before another date.
  • isSameDate(value: string, compare: any, precision?: TimeRanges): boolean: Validates if a date is the same as another date.
  • isSameOrAfterDate(value: string, compare: any, precision?: TimeRanges): boolean: Validates if a date is the same or after another date.
  • isSameOrBeforeDate(value: string, compare: any, precision?: TimeRanges): boolean: Validates if a date is the same or before another date.
  • isBetweenDates(value: string, start: any, end: any, precision?: TimeRanges, inclusivity?: Inclusivity): boolean: Validates if a date is between two other dates.
  • max(value: number, maxValue: number): boolean: Validates if a value is less than or equal to a maximum value.
  • min(value: number, minValue: number): boolean: Validates if a value is greater than or equal to a minimum value.
  • isNumber(value: string, decimal: boolean = true, separators?: boolean): boolean: Validates if a value is a number, with options for decimal and separators.
  • isEmpty(value: any): Checks if a value is empty.

Fields

  • None.