UNPKG

1.24 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.IsUrl = exports.isURL = exports.IS_URL = void 0;
7const ValidateBy_1 = require("../common/ValidateBy");
8const isURL_1 = __importDefault(require("validator/lib/isURL"));
9exports.IS_URL = 'isUrl';
10/**
11 * Checks if the string is an url.
12 * If given value is not a string, then it returns false.
13 */
14function isURL(value, options) {
15 return typeof value === 'string' && (0, isURL_1.default)(value, options);
16}
17exports.isURL = isURL;
18/**
19 * Checks if the string is an url.
20 * If given value is not a string, then it returns false.
21 */
22function IsUrl(options, validationOptions) {
23 return (0, ValidateBy_1.ValidateBy)({
24 name: exports.IS_URL,
25 constraints: [options],
26 validator: {
27 validate: (value, args) => isURL(value, args.constraints[0]),
28 defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be an URL address', validationOptions),
29 },
30 }, validationOptions);
31}
32exports.IsUrl = IsUrl;
33//# sourceMappingURL=IsUrl.js.map
\No newline at end of file