當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript validator.isURL函數代碼示例

本文整理匯總了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}.`;
  }
開發者ID:lostfictions,項目名稱:bort,代碼行數:60,代碼來源:concept-load.ts

示例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++;
    }
  }
開發者ID:zachmart,項目名稱:closedssl,代碼行數:58,代碼來源:AltNameStore.ts

示例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
}
開發者ID:jiang263,項目名稱:PeerTube,代碼行數:13,代碼來源:servers.ts

示例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)
}
開發者ID:quoidautre,項目名稱:PeerTube,代碼行數:16,代碼來源:misc.ts

示例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');
開發者ID:Crevil,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:validator-tests.ts

示例6:

 tv4.addFormat("url-ip", (data, schema): any=> {
     if (validator.isURL(data) || validator.isIP(data)) {
         return null;
     }
     return {code: 10005};
 });
開發者ID:nick121212,項目名稱:blessing,代碼行數:6,代碼來源:validator.custom.value.ts


注:本文中的validator.isURL函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。