UNPKG

2.29 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.IsPostalCode = exports.isPostalCode = exports.IS_POSTAL_CODE = void 0;
7const ValidateBy_1 = require("../common/ValidateBy");
8const isPostalCode_1 = __importDefault(require("validator/lib/isPostalCode"));
9exports.IS_POSTAL_CODE = 'isPostalCode';
10/**
11 * Check if the string is a postal code,
12 * (locale is one of [ 'AD', 'AT', 'AU', 'BE', 'BG', 'BR', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'NL', 'NO', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SI', 'TN', 'TW', 'UA', 'US', 'ZA', 'ZM' ] OR 'any'. If 'any' is used, function will check if any of the locals match. Locale list is validator.isPostalCodeLocales.).
13 * If given value is not a string, then it returns false.
14 */
15function isPostalCode(value, locale) {
16 return typeof value === 'string' && (0, isPostalCode_1.default)(value, locale);
17}
18exports.isPostalCode = isPostalCode;
19/**
20 * Check if the string is a postal code,
21 * (locale is one of [ 'AD', 'AT', 'AU', 'BE', 'BG', 'BR', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'NL', 'NO', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SI', 'TN', 'TW', 'UA', 'US', 'ZA', 'ZM' ] OR 'any'. If 'any' is used, function will check if any of the locals match. Locale list is validator.isPostalCodeLocales.).
22 * If given value is not a string, then it returns false.
23 */
24function IsPostalCode(locale, validationOptions) {
25 return (0, ValidateBy_1.ValidateBy)({
26 name: exports.IS_POSTAL_CODE,
27 constraints: [locale],
28 validator: {
29 validate: (value, args) => isPostalCode(value, args.constraints[0]),
30 defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a postal code', validationOptions),
31 },
32 }, validationOptions);
33}
34exports.IsPostalCode = IsPostalCode;
35//# sourceMappingURL=IsPostalCode.js.map
\No newline at end of file