本文整理匯總了TypeScript中joi.alternatives函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript alternatives函數的具體用法?TypeScript alternatives怎麽用?TypeScript alternatives使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了alternatives函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: pre
return value;
},
pre(value: any, state: State, options: ValidationOptions) {
// If value isn't defined, let Joi handle default value if it's defined.
if (value instanceof ByteSizeValue) {
return value as any;
}
return this.createError('bytes.base', { value }, state, options);
},
rules: [
anyCustomRule,
{
name: 'min',
params: {
limit: Joi.alternatives([Joi.number(), Joi.string()]).required(),
},
validate(params, value, state, options) {
const limit = ensureByteSizeValue(params.limit);
if (value.isLessThan(limit)) {
return this.createError('bytes.min', { value, limit }, state, options);
}
return value;
},
},
{
name: 'max',
params: {
limit: Joi.alternatives([Joi.number(), Joi.string()]).required(),
},
示例2: function
pkg: {
name: 'hapi-auth-local',
version: '1.0.0'
}
};
internals['schema'] = Joi.object({
session: Joi.string().default('sid'),
ttl: Joi.number().integer().min(0).when('keepAlive', { is: true, then: Joi.required() }),
domain: Joi.string().allow(null),
path: Joi.string().default('/'),
clearInvalid: Joi.boolean().default(false),
keepAlive: Joi.boolean().default(false),
isSecure: Joi.boolean().default(true),
isHttpOnly: Joi.boolean().default(true),
appendNext: Joi.alternatives(Joi.string(), Joi.boolean()).default(false),
redirectOnTry: Joi.boolean().default(true),
validateFunc: Joi.func(),
requestDecoratorName: Joi.string().default('cookieAuth')
}).required();
internals['implementation'] = function(server, options) {
const results = Joi.validate(options, internals['schema']);
Hoek.assert(!results.error, results.error);
const settings = results.value;
const scheme = {
authenticate: function(request, reply) {
const validate = function() {
// Check session
示例3: propertyToJoi
function propertyToJoi(property: Property, optional = false) {
let joiRule
switch (property.type) {
case 'action':
joiRule = joi.alternatives([
joi.object({
type: joi
.string()
.required()
.only('call'),
deviceId: joi.string().required(),
interfaceId: joi.string().required(),
method: joi.string().required(),
arguments: joi.object().required(),
}),
joi.object({
type: joi
.string()
.required()
.only('modification'),
deviceId: joi.string().required(),
interfaceId: joi.string().required(),
statusId: joi.string().required(),
value: joi.any().required(),
}),
])
break
case 'array':
joiRule = joi.array().items(propertyToJoi(property.items, true))
break
case 'boolean':
joiRule = joi.boolean()
break
case 'device':
joiRule = joi.string()
break
case 'enum':
joiRule = joi.alternatives(joi.string(), joi.number())
// .only(property.values.map(value => value.value.toString()))
break
case 'modification':
joiRule = joi.object({
deviceId: joi.string().required(),
interfaceId: joi.string().required(),
statusId: joi.string().required(),
value: joi.any().required(),
})
break
case 'integer':
joiRule = joi.number().integer()
// fall through
case 'number':
let numberJoiRule: joi.NumberSchema = joiRule || joi.number()
if (property.min !== undefined) {
numberJoiRule = numberJoiRule.min(property.min)
}
if (property.max !== undefined) {
numberJoiRule = numberJoiRule.max(property.max)
}
joiRule = numberJoiRule
break
case 'string':
joiRule = joi.string()
break
}
if (!property.optional && !optional) {
joiRule = joiRule.required()
}
return joiRule
}
示例4:
// DEPRECATED: https://nervjs.github.io/taro/docs/config-detail.html#deprecated-h5webpack
'webpack': Joi.forbidden(),
// https://webpack.js.org/configuration/resolve/#resolve-alias
'alias': Joi.object().pattern(
Joi.string(), Joi.string().strict()
),
// https://webpack.js.org/configuration/entry-context/#entry
'entry': Joi.alternatives(
Joi.string(),
Joi.array().items(Joi.alternatives(
Joi.string(),
Joi.object().pattern(
Joi.string(),
Joi.alternatives(
Joi.string(),
Joi.array().items(Joi.string())
)
)
)),
Joi.func()
),
'enableSourceMap': Joi.bool(),
'enableExtract': Joi.bool(),
'cssLoaderOption': Joi.object(), // 第三方配置
'styleLoaderOption': Joi.object(), // 第三方配置
'sassLoaderOption': Joi.object(), // 第三方配置
'lessLoaderOption': Joi.object(), // 第三方配置
'stylusLoaderOption': Joi.object(), // 第三方配置
'mediaUrlLoaderOption': Joi.object(), // 第三方配置
'fontUrlLoaderOption': Joi.object(), // 第三方配置
示例5:
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import Joi from 'joi';
export const dateValidation = Joi.alternatives()
.try(Joi.date().iso(), Joi.number())
.required();
export const withDefaultValidators = (validators = {}) => {
return Joi.object().keys({
_debug: Joi.bool(),
start: dateValidation,
end: dateValidation,
uiFiltersES: Joi.string(),
...validators
});
};