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

TypeScript joi.alternatives函数代码示例

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

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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript joi.any函数代码示例发布时间:2022-05-25
下一篇:
TypeScript jison.Parser类代码示例发布时间: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