UNPKG

1.74 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.IsIdentityCard = exports.isIdentityCard = exports.IS_IDENTITY_CARD = void 0;
7const ValidateBy_1 = require("../common/ValidateBy");
8const isIdentityCard_1 = __importDefault(require("validator/lib/isIdentityCard"));
9exports.IS_IDENTITY_CARD = 'isIdentityCard';
10/**
11 * Check if the string is a valid identity card code.
12 * locale is one of ['ES', 'zh-TW', 'he-IL', 'ar-TN'] OR 'any'. If 'any' is used, function will check if any of the locals match.
13 * Defaults to 'any'.
14 * If given value is not a string, then it returns false.
15 */
16function isIdentityCard(value, locale) {
17 return typeof value === 'string' && (0, isIdentityCard_1.default)(value, locale);
18}
19exports.isIdentityCard = isIdentityCard;
20/**
21 * Check if the string is a valid identity card code.
22 * locale is one of ['ES', 'zh-TW', 'he-IL', 'ar-TN'] OR 'any'. If 'any' is used, function will check if any of the locals match.
23 * Defaults to 'any'.
24 * If given value is not a string, then it returns false.
25 */
26function IsIdentityCard(locale, validationOptions) {
27 return (0, ValidateBy_1.ValidateBy)({
28 name: exports.IS_IDENTITY_CARD,
29 constraints: [locale],
30 validator: {
31 validate: (value, args) => isIdentityCard(value, args.constraints[0]),
32 defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a identity card number', validationOptions),
33 },
34 }, validationOptions);
35}
36exports.IsIdentityCard = IsIdentityCard;
37//# sourceMappingURL=IsIdentityCard.js.map
\No newline at end of file