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


TypeScript joi.alternatives函数代码示例

本文整理汇总了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(),
        },
开发者ID:elastic,项目名称:kibana,代码行数:31,代码来源:index.ts

示例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
开发者ID:starlightslo,项目名称:hapi-ts-gulp-mvc-example,代码行数:31,代码来源:hapi-auth-local.ts

示例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
}
开发者ID:Pajn,项目名称:RAXA,代码行数:74,代码来源:validations.ts

示例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(), // 第三方配置
开发者ID:YangShaoQun,项目名称:taro,代码行数:32,代码来源:configSchema.ts

示例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
  });
};
开发者ID:elastic,项目名称:kibana,代码行数:20,代码来源:input_validation.ts


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