• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript validator.isURL函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript validator.isUUID函数代码示例发布时间:2022-05-25
下一篇:
TypeScript validator.isNumeric函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap