当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript valid-url.isWebUri函数代码示例

本文整理汇总了TypeScript中valid-url.isWebUri函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isWebUri函数的具体用法?TypeScript isWebUri怎么用?TypeScript isWebUri使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了isWebUri函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: parse

export function parse (): Config {

  try {
    const packageJson = require(`${process.cwd()}/package.json`)
    if (packageJson.hasOwnProperty('graphql')) {
      return parseConfigJson(packageJson.graphql)
    }
  } catch (ex) {
    // do nothing here
  }

  try {
    const graphqlrc = JSON.parse(readFileSync(`${process.cwd()}/.graphqlrc`, 'utf-8'))
    return parseConfigJson(graphqlrc)
  } catch (ex) {
    // do nothing here
  }

  if (process.env.hasOwnProperty('GRAPHQL_ENDPOINT')) {
    const endpoint = process.env.GRAPHQL_ENDPOINT
    if (!isWebUri(endpoint)) {
      throw new Error(`No valid GraphQL endpoint: ${endpoint}`)
    }

    return {
      url: endpoint,
      type: 'request',
    } as ConfigRequest
  }

  throw new Error('Couldn\'t find a GraphQL config. Please refer to https://github.com/graphcool/graphql-config')
}
开发者ID:julianbauer,项目名称:graphql-config,代码行数:32,代码来源:index.ts

示例2: registryNameToUrl

  async registryNameToUrl(buildpack: string): Promise<string> {
    if (validUrl.isWebUri(buildpack)) {
      return buildpack
    }

    Result.match({
      Ok: _ => {},
      Err: err => {
        cli.error(`Could not find the buildpack: ${buildpack}. ${err}`, {exit: 1})
      },
    }, BuildpackRegistry.isValidBuildpackSlug(buildpack))

    try {
      let response = await this.registry.buildpackExists(buildpack)
      let body = await response.json()
      return body.blob_url
    } catch (err) {
      if (err.statusCode === 404) {
        cli.error(`${buildpack} is not in the buildpack registry.`, {exit: 1})
      } else if (err.statusCode) {
        cli.error(`${err.statusCode}: ${err.message}`, {exit: 1})
      } else {
        cli.error(err.message, {exit: 1})
      }
    }

    return ''
  }
开发者ID:jimmyurl,项目名称:cli,代码行数:28,代码来源:buildpacks.ts

示例3: isValidUri

    static isValidUri(arg: string, message?: string | Error): string {
        arg = Validate.notEmpty(arg, message);
        if (!isWebUri(arg)) {
            Validate.throwError(message || 'Must be a valid url');
        }

        return arg;
    }
开发者ID:dflor003,项目名称:radar-radiator,代码行数:8,代码来源:validator.ts

示例4: doesConformToSchema

        this.assert(isWeb3Provider, this.typeAssertionMessage(variableName, 'Web3.Provider', value));
    },
    doesConformToSchema(variableName: string, value: any, schema: Schema, subSchemas?: Schema[]): void {
        const schemaValidator = new SchemaValidator();
        if (!_.isUndefined(subSchemas)) {
            _.map(subSchemas, schemaValidator.addSchema.bind(schemaValidator));
        }
        const validationResult = schemaValidator.validate(value, schema);
        const hasValidationErrors = validationResult.errors.length > 0;
        const msg = `Expected ${variableName} to conform to schema ${schema.id}
Encountered: ${JSON.stringify(value, null, '\t')}
Validation errors: ${validationResult.errors.join(', ')}`;
        this.assert(!hasValidationErrors, msg);
    },
    isWebUri(variableName: string, value: any): void {
        const isValidUrl = !_.isUndefined(validUrl.isWebUri(value));
        this.assert(isValidUrl, this.typeAssertionMessage(variableName, 'web uri', value));
    },
    isUri(variableName: string, value: any): void {
        const isValidUri = !_.isUndefined(validUrl.isUri(value));
        this.assert(isValidUri, this.typeAssertionMessage(variableName, 'uri', value));
    },
    assert(condition: boolean, message: string): void {
        if (!condition) {
            throw new Error(message);
        }
    },
    typeAssertionMessage(variableName: string, type: string, value: any): string {
        return `Expected ${variableName} to be of type ${type}, encountered: ${value}`;
    },
};
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:31,代码来源:index.ts

示例5: function

export default function(url: string): boolean {
  return /^(\/|scm:)/.test(url) || !!isWebUri(url);
}
开发者ID:SonarSource,项目名称:sonarqube,代码行数:3,代码来源:isValidUri.ts


注:本文中的valid-url.isWebUri函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。