本文整理汇总了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')
}
示例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 ''
}
示例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;
}
示例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}`;
},
};
示例5: function
export default function(url: string): boolean {
return /^(\/|scm:)/.test(url) || !!isWebUri(url);
}