UNPKG

container.ts

Version:
44 lines 1.72 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var validator_1 = require("validator"); var field_1 = require("../field"); var validate_1 = require("../validate"); /** Validate that value is a valid ISO3166-1 alpha-2 country code. */ function isCountry(value) { if (value === void 0) { value = ""; } try { if (validator_1.default.isISO31661Alpha2(value) !== true) { throw new validate_1.ValidateError(validate_1.EValidateError.IsCountryError, value); } return value.toUpperCase(); } catch (error) { throw new validate_1.ValidateError(validate_1.EValidateError.IsCountryError, value, error); } } exports.isCountry = isCountry; var CountryField = /** @class */ (function (_super) { __extends(CountryField, _super); function CountryField() { return _super !== null && _super.apply(this, arguments) || this; } CountryField.prototype.validate = function (value) { return isCountry(value); }; return CountryField; }(field_1.Field)); exports.CountryField = CountryField; //# sourceMappingURL=is-country.js.map