本文整理匯總了TypeScript中validator.isURL函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isURL函數的具體用法?TypeScript isURL怎麽用?TypeScript isURL使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了isURL函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: async
async ({ message, store }) => {
const matches = loaderRegex.exec(message);
if (message.length === 0 || !matches) {
return usage;
}
const [, rawUrl, rawPath, concept] = matches;
const path = rawPath.split(".");
let url = rawUrl;
const slackFixedUrl = slackEscapeRegex.exec(rawUrl);
if (slackFixedUrl) {
url = slackFixedUrl[1];
}
if (!isURL(url)) {
return `Error: '${url}' doesn't appear to be a valid URL.\n${usage}`;
}
const { data: json } = await axios.get(url, { responseType: "json" });
let items: string[];
if (path) {
const itemOrItems = traverse(json, path);
if (!itemOrItems) {
const validKeys = Object.keys(json)
.slice(0, 5)
.map(k => `'${k}'`)
.join(", ");
throw new Error(
`Invalid path: '${rawPath}'. Some valid keys: ${validKeys}...`
);
}
if (Array.isArray(itemOrItems)) {
items = itemOrItems.map(i => i.toString());
} else {
const item = itemOrItems.toString();
if (item === "[object Object]") {
throw new Error(
`Requested item does not appear to be a primitive or array! Aborting.`
);
}
items = [item];
}
} else if (Array.isArray(json)) {
items = json.map(i => i.toString());
} else {
const item = json.toString();
if (item === "[object Object]") {
throw new Error(
`Requested item does not appear to be a primitive or array! Aborting.`
);
}
items = [item];
}
await store.dispatch(loadConceptAction(concept, items));
return `Loaded ${items.length} items from ${url}.`;
}
示例2: constructor
constructor(name: string,
altNames: Array<string |
{value: string, type: "URI" | "IP" | "DNS" | "EMAIL" | "OTHER"}>){
super(name);
if (!Array.isArray(altNames)) {
throw new Error(`The altNames parameter must be a string array for the ${""
}AltNameStore constructor, given:\n${altNames}`);
}
this._altNames = [];
this._length = 0;
for (let name of altNames) {
if (typeof name !== "string"
&& (typeof name.value !== "string" ||
name.type !== "URI" ||
name.type !== "IP" ||
name.type !== "DNS" ||
name.type !== "EMAIL" ||
name.type !== "OTHER")){
throw new Error(`The altNames parameter must be an array containing strings or${""
} objects with a valid value and type property for the${""
} AltNameStore constructor, given:\n${altNames}`);
}
if (typeof name.value === "string"){
this._altNames.push(new AlternativeName(name.type, name.value));
} else {
let type: "URI" | "IP" | "DNS" | "EMAIL" | "OTHER";
const dnOpt = {
require_tld: false,
allow_underscores: false,
allow_trailing_dot: true
};
if (validator.isIP(name)) {
type = "IP";
} else if (validator.isFQDN(name, dnOpt)) {
type = "DNS";
} else if (name.charAt(0) === "*" && // wildcard case
validator.isFQDN(name.substring(2), dnOpt)){
type = "DNS";
} else if (validator.isEmail(name)) {
type = "EMAIL";
} else if (validator.isURL(name)) {
type = "URI";
} else {
type = "OTHER";
}
this._altNames.push(new AlternativeName(type, name));
}
this._length++;
}
}
示例3: isHostValid
function isHostValid (host: string) {
const isURLOptions = {
require_host: true,
require_tld: true
}
// We validate 'localhost', so we don't have the top level domain
if (isTestInstance()) {
isURLOptions.require_tld = false
}
return exists(host) && validator.isURL(host, isURLOptions) && host.split('://').length === 1
}
示例4: isActivityPubUrlValid
function isActivityPubUrlValid (url: string) {
const isURLOptions = {
require_host: true,
require_tld: true,
require_protocol: true,
require_valid_protocol: true,
protocols: [ 'http', 'https' ]
}
// We validate 'localhost', so we don't have the top level domain
if (isTestInstance()) {
isURLOptions.require_tld = false
}
return exists(url) && validator.isURL('' + url, isURLOptions) && validator.isLength('' + url, CONSTRAINTS_FIELDS.ACTORS.URL)
}
示例5:
result = validator.isMobilePhone('sample', 'vi-VN');
result = validator.isMobilePhone('sample', 'zh-CN');
result = validator.isMobilePhone('sample', 'zh-TW');
result = validator.isMongoId('sample');
result = validator.isMultibyte('sample');
result = validator.isNull('sample');
result = validator.isNumeric('sample');
result = validator.isSurrogatePair('sample');
let isURLOptions: ValidatorJS.IsURLOptions;
result = validator.isURL('sample');
result = validator.isURL('sample', isURLOptions);
result = validator.isUUID('sample');
result = validator.isUUID('sample', 5);
result = validator.isUUID('sample', 'all');
result = validator.isUppercase('sample');
result = validator.isVariableWidth('sample');
result = validator.isWhitelisted('sample', 'abc');
result = validator.isWhitelisted('sample', ['a', 'b', 'c']);
result = validator.matches('foobar', 'foo/i');
result = validator.matches('foobar', 'foo', 'i');
示例6:
tv4.addFormat("url-ip", (data, schema): any=> {
if (validator.isURL(data) || validator.isIP(data)) {
return null;
}
return {code: 10005};
});