From 18a2e0dab2756cd1fde6e849f862b46bfc896133 Mon Sep 17 00:00:00 2001 From: Rahul Nikam Date: Sun, 24 Sep 2023 19:51:22 +0530 Subject: [PATCH] feat(isPancard): added validation for pancard --- src/index.js | 151 +++++++++++++++++++++++++++++++++++++--- test/validators.test.js | 11 +-- 2 files changed, 150 insertions(+), 12 deletions(-) diff --git a/src/index.js b/src/index.js index d2214ac89..169eb7ba3 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ import toBoolean from './lib/toBoolean'; import equals from './lib/equals'; import contains from './lib/contains'; import matches from './lib/matches'; + import isEmail from './lib/isEmail'; import isURL from './lib/isURL'; import isMACAddress from './lib/isMACAddress'; @@ -13,8 +14,10 @@ import isIPRange from './lib/isIPRange'; import isFQDN from './lib/isFQDN'; import isDate from './lib/isDate'; import isTime from './lib/isTime'; + import isBoolean from './lib/isBoolean'; import isLocale from './lib/isLocale'; + import isAlpha, { locales as isAlphaLocales } from './lib/isAlpha'; import isAlphanumeric, { locales as isAlphanumericLocales } from './lib/isAlphanumeric'; import isNumeric from './lib/isNumeric'; @@ -22,7 +25,9 @@ import isPassportNumber from './lib/isPassportNumber'; import isPort from './lib/isPort'; import isLowercase from './lib/isLowercase'; import isUppercase from './lib/isUppercase'; + import isIMEI from './lib/isIMEI'; + import isAscii from './lib/isAscii'; import isFullWidth from './lib/isFullWidth'; import isHalfWidth from './lib/isHalfWidth'; @@ -30,43 +35,59 @@ import isVariableWidth from './lib/isVariableWidth'; import isMultibyte from './lib/isMultibyte'; import isSemVer from './lib/isSemVer'; import isSurrogatePair from './lib/isSurrogatePair'; + import isInt from './lib/isInt'; -import isFloat from './lib/isFloat'; -import { locales as isFloatLocales } from './lib/isFloat'; +import isFloat, { locales as isFloatLocales } from './lib/isFloat'; import isDecimal from './lib/isDecimal'; import isHexadecimal from './lib/isHexadecimal'; import isOctal from './lib/isOctal'; import isDivisibleBy from './lib/isDivisibleBy'; + import isHexColor from './lib/isHexColor'; import isRgbColor from './lib/isRgbColor'; import isHSL from './lib/isHSL'; + import isISRC from './lib/isISRC'; + import isIBAN, { locales as ibanLocales } from './lib/isIBAN'; import isBIC from './lib/isBIC'; + import isMD5 from './lib/isMD5'; import isHash from './lib/isHash'; import isJWT from './lib/isJWT'; + import isJSON from './lib/isJSON'; import isEmpty from './lib/isEmpty'; + import isLength from './lib/isLength'; import isByteLength from './lib/isByteLength'; + import isUUID from './lib/isUUID'; import isMongoId from './lib/isMongoId'; + import isAfter from './lib/isAfter'; import isBefore from './lib/isBefore'; + import isIn from './lib/isIn'; + import isLuhnNumber from './lib/isLuhnNumber'; import isCreditCard from './lib/isCreditCard'; import isIdentityCard from './lib/isIdentityCard'; + import isEAN from './lib/isEAN'; import isISIN from './lib/isISIN'; import isISBN from './lib/isISBN'; import isISSN from './lib/isISSN'; import isTaxID from './lib/isTaxID'; + import isMobilePhone, { locales as isMobilePhoneLocales } from './lib/isMobilePhone'; + import isEthereumAddress from './lib/isEthereumAddress'; + import isCurrency from './lib/isCurrency'; + import isBtcAddress from './lib/isBtcAddress'; + import { isISO6346, isFreightContainerID } from './lib/isISO6346'; import isISO6391 from './lib/isISO6391'; import isISO8601 from './lib/isISO8601'; @@ -74,17 +95,19 @@ import isRFC3339 from './lib/isRFC3339'; import isISO31661Alpha2 from './lib/isISO31661Alpha2'; import isISO31661Alpha3 from './lib/isISO31661Alpha3'; import isISO4217 from './lib/isISO4217'; + import isBase32 from './lib/isBase32'; import isBase58 from './lib/isBase58'; import isBase64 from './lib/isBase64'; import isDataURI from './lib/isDataURI'; import isMagnetURI from './lib/isMagnetURI'; import isMailtoURI from './lib/isMailtoURI'; + import isMimeType from './lib/isMimeType'; + import isLatLong from './lib/isLatLong'; -import isPostalCode, { - locales as isPostalCodeLocales, -} from './lib/isPostalCode'; +import isPostalCode, { locales as isPostalCodeLocales } from './lib/isPostalCode'; + import ltrim from './lib/ltrim'; import rtrim from './lib/rtrim'; import trim from './lib/trim'; @@ -94,15 +117,127 @@ import stripLow from './lib/stripLow'; import whitelist from './lib/whitelist'; import blacklist from './lib/blacklist'; import isWhitelisted from './lib/isWhitelisted'; + import normalizeEmail from './lib/normalizeEmail'; + import isSlug from './lib/isSlug'; import isLicensePlate from './lib/isLicensePlate'; import isStrongPassword from './lib/isStrongPassword'; -import isVAT from './lib/isVAT'; import isPancard from './lib/isPancard'; +import isVAT from './lib/isVAT'; + const version = '13.11.0'; -const validator = { version, toDate, toFloat, toInt, toBoolean, equals, contains, matches, isEmail, isURL, isMACAddress, isIP, isIPRange, isFQDN, isBoolean, isIBAN, isBIC, isAlpha, isAlphaLocales, isAlphanumeric, isAlphanumericLocales, isNumeric, isPassportNumber, isPort, isLowercase, isUppercase, isAscii, isFullWidth, isHalfWidth, isVariableWidth, isMultibyte, isSemVer, isSurrogatePair, isInt, isIMEI, isFloat, isFloatLocales, isDecimal, isHexadecimal, isOctal, isDivisibleBy, isHexColor, isRgbColor, isHSL, isISRC, isMD5, isHash, isJWT, isJSON, isEmpty, isLength, isLocale, isByteLength, isUUID, isMongoId, isAfter, isBefore, isIn, isLuhnNumber, isCreditCard, isIdentityCard, isEAN, isISIN, isISBN, isISSN, isMobilePhone, isMobilePhoneLocales, isPancard, isPostalCode, isPostalCodeLocales, isEthereumAddress, isCurrency, isBtcAddress, isISO6346, isFreightContainerID, isISO6391, isISO8601, isRFC3339, isISO31661Alpha2, isISO31661Alpha3, isISO4217, isBase32, isBase58, isBase64, isDataURI, isMagnetURI, isMailtoURI, isMimeType, isLatLong, ltrim, rtrim, trim, escape, unescape, stripLow, whitelist, blacklist, isWhitelisted, normalizeEmail, toString, isSlug, isStrongPassword, isTaxID, isDate, isTime, isLicensePlate, isVAT, ibanLocales, }; +const validator = { + version, + toDate, + toFloat, + toInt, + toBoolean, + equals, + contains, + matches, + isEmail, + isURL, + isMACAddress, + isIP, + isIPRange, + isFQDN, + isBoolean, + isIBAN, + isBIC, + isAlpha, + isAlphaLocales, + isAlphanumeric, + isAlphanumericLocales, + isNumeric, + isPassportNumber, + isPort, + isLowercase, + isUppercase, + isAscii, + isFullWidth, + isHalfWidth, + isVariableWidth, + isMultibyte, + isSemVer, + isSurrogatePair, + isInt, + isIMEI, + isFloat, + isFloatLocales, + isDecimal, + isHexadecimal, + isOctal, + isDivisibleBy, + isHexColor, + isRgbColor, + isHSL, + isISRC, + isMD5, + isHash, + isJWT, + isJSON, + isEmpty, + isLength, + isLocale, + isByteLength, + isUUID, + isMongoId, + isAfter, + isBefore, + isIn, + isLuhnNumber, + isCreditCard, + isIdentityCard, + isEAN, + isISIN, + isISBN, + isISSN, + isMobilePhone, + isMobilePhoneLocales, + isPostalCode, + isPostalCodeLocales, + isEthereumAddress, + isCurrency, + isBtcAddress, + isISO6346, + isFreightContainerID, + isISO6391, + isISO8601, + isRFC3339, + isISO31661Alpha2, + isISO31661Alpha3, + isISO4217, + isBase32, + isBase58, + isBase64, + isDataURI, + isMagnetURI, + isMailtoURI, + isMimeType, + isLatLong, + ltrim, + rtrim, + trim, + escape, + unescape, + stripLow, + whitelist, + blacklist, + isWhitelisted, + normalizeEmail, + toString, + isSlug, + isStrongPassword, + isTaxID, + isDate, + isTime, + isLicensePlate, + isVAT, + ibanLocales, + isPancard, +}; -export default validator; +export default validator; \ No newline at end of file diff --git a/test/validators.test.js b/test/validators.test.js index b480c384a..c2d4ea163 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -2863,9 +2863,12 @@ describe('Validators', () => { test({ validator: 'isPancard', valid: [ - 'AAAPL1234C' + 'AAAPL1234C', + 'AABPL1234C', + 'AABPL1238C', ], invalid: [ + '', 'AAPL1234C', 'AAaPL1234C', 'AAaPL12346', @@ -2874,9 +2877,9 @@ describe('Validators', () => { 'AAaPL12304C', 'AAaPL12A4C', 'AAaPL124C', - ] - }) - }) + ], + }); + }); it('should validate passport number', () => { test({