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

TypeScript yup.object函数代码示例

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

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



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

示例1: it

      it('should return specific error message', () => {
        const data = { label: 1234 };
        const schema = object().shape({
          region: string().required('A region is required.'),
        });

        return Request(setData(data, schema))
          .catch((response) => {
            expect(response.response.data.errors).toEqual([{
              field: 'region',
              reason: `A region is required.`,
            }]);
          });
      });
开发者ID:displague,项目名称:manager,代码行数:14,代码来源:index.test.ts


示例2: require

import { validateYupSchema, yupToFormErrors } from '../src';

const Yup = require('yup');
const schema = Yup.object().shape({
  name: Yup.string('Name must be a string').required('required'),
});

describe('Yup helpers', () => {
  describe('yupToFormErrors()', () => {
    it('should transform Yup ValidationErrors into an object', async () => {
      try {
        await schema.validate({}, { abortEarly: false });
      } catch (e) {
        expect(yupToFormErrors(e)).toEqual({
          name: 'required',
        });
      }
    });
  });

  describe('validateYupSchema()', () => {
    it('should validate', async () => {
      try {
        await validateYupSchema({}, schema);
      } catch (e) {
        expect(e.name).toEqual('ValidationError');
        expect(e.errors).toEqual(['required']);
      }
    });

    it('should stringify all values', async () => {
开发者ID:isahgaga,项目名称:formik,代码行数:31,代码来源:yupHelpers.ts


示例3: object

import { array, mixed, number, object, string } from 'yup';

export const importZoneSchema = object({
  domain: string().required('Domain is required.'),
  remote_nameserver: string().required('Remote nameserver is required.')
});

const domainSchemaBase = object().shape({
  domain: string()
    .matches(/([a-zA-Z0-9-_]+\.)+([a-zA-Z]{2,3}\.)?([a-zA-Z]{2,16}|XN--[a-zA-Z0-9]+)/, 'Domain is not valid.'),
  status: mixed().oneOf(['disabled', 'active', 'edit_mode', 'has_errors']),
  tags: array(),
  description: string()
    .min(1, 'Description must be between 1 and 255 characters.')
    .max(255, 'Description must be between 1 and 255 characters.'),
  retry_sec: number(),
  master_ips: array().of(string()),
  axfr_ips: array().of(string()),
  expire_sec: number(),
  refresh_sec: number(),
  ttl_sec: number()
});

export const createDomainSchema = domainSchemaBase.shape({
  domain: string()
    .required('Domain is required.')
    .matches(/([a-zA-Z0-9-_]+\.)+([a-zA-Z]{2,3}\.)?([a-zA-Z]{2,16}|XN--[a-zA-Z0-9]+)/, 'Domain is not valid.'),
  type: mixed()
    .required()
    .oneOf(['master', 'slave']),
  soa_email: string()
开发者ID:displague,项目名称:manager,代码行数:31,代码来源:domains.schema.ts


示例4: object

import { array, boolean, number, object, string } from 'yup';

export const updateIPSchema = object().shape({
  rdns: string()
    .notRequired()
    .nullable(true)
});

export const allocateIPSchema = object().shape({
  type: string()
    .required()
    .matches(
      /^ipv4$/,
      'Only IPv4 address may be allocated through this endpoint.'
    ),
  public: boolean().required(),
  linode_id: number().required()
});

export const assignAddressesSchema = object().shape({
  region: string().required(),
  assignments: array()
    .of(object())
    .required()
});

export const shareAddressesSchema = object().shape({
  linode_id: number().required(),
  ips: array().of(string())
});
开发者ID:linode,项目名称:manager,代码行数:30,代码来源:networking.schema.ts


示例5: object

import { array, boolean, mixed, number, object, string } from 'yup';

import { NodeBalancerConfigFields } from './configs';

export const nodeBalancerConfigNodeSchema = object({
  label: string()
    .matches(/^[a-z0-9-_]+$/, "Label can't contain special characters, uppercase characters, or whitespace.")
    .min(3, 'Label should be between 3 and 32 characters.')
    .max(32, 'Label should be between 3 and 32 characters.')
    .required('Label is required.'),


  address: string()
    .matches(/^192\.168\.\d{1,3}\.\d{1,3}$/, 'Must be a valid IPv4 address.')
    .required('IP address is required.'),

  port: number().typeError("Port must be a number.")
    .required('Port is required.')
    .min(1, "Port must be between 1 and 65535.")
    .max(65535, "Port must be between 1 and 65535."),

  weight: number().typeError("Weight must be a number.")
    .min(1, `Weight must be between 1 and 255.`)
    .max(255, `Weight must be between 1 and 255.`),

  mode: mixed()
    .oneOf(['accept', 'reject', 'drain'])
});

export const createNodeBalancerConfigSchema = object({
  algorithm: mixed().oneOf(["roundrobin", "leastconn", "source"]),
  check_attempts: number(),
开发者ID:displague,项目名称:manager,代码行数:32,代码来源:nodebalancers.schema.ts


示例6: object

import { number, object, string } from 'yup';

export const createImageSchema = object().shape({
  disk_id: number()
    .typeError('Disk is required.')
    .required('Disk is required.'),
  label: string()
    .notRequired()
    .max(50, 'Length must be 50 characters or less.')
    .matches(/^[a-zA-Z0-9,.?\-_\s']+$/, 'Image labels cannot contain special characters.'),
  description: string()
    .notRequired()
    .min(1)
    .max(65000)
});

export const updateImageSchema = object().shape({
  label: string()
    .notRequired()
    .max(50, 'Length must be 50 characters or less.')
    .matches(/^[a-zA-Z0-9,.?\-_\s']+$/, 'Image labels cannot contain special characters.'),
  description: string()
    .notRequired()
    .max(65000, 'Length must be 65000 characters or less.')
});
开发者ID:displague,项目名称:manager,代码行数:25,代码来源:image.schema.ts


示例7: object

export const ResizeVolumeSchema = (minSize: number = 10) => object({
  size: createSizeValidation(minSize),
})
开发者ID:displague,项目名称:manager,代码行数:3,代码来源:volumes.schema.ts


示例8:

import * as Yup from 'yup'

export const mappingValidationSchema = Yup.object().shape({
    method: Yup.string()
        .required('Request method is required'),
    queryParameters: Yup.array().of(Yup.object().shape({
        key: Yup.string()
            .required('Query parameter name is required'),
        value: Yup.string()
            .required('Query parameter value is required'),
    })),
    requestHeaders: Yup.array().of(Yup.object().shape({
        key: Yup.string()
            .required('Header name is required'),
        value: Yup.string()
            .required('Header value is required'),
    })),
    requestCookies: Yup.array().of(Yup.object().shape({
        key: Yup.string()
            .required('Cookie name is required'),
        value: Yup.string()
            .required('Cookie value is required'),
    })),
    responseStatus: Yup.number()
        .min(100, 'Response status code is invalid')
        .max(527, 'Response status code is invalid')
        .required('Response status code is required'),
    responseHeaders: Yup.array().of(Yup.object().shape({
        key: Yup.string()
            .required('Header name is required'),
        value: Yup.string()
开发者ID:manishshanker,项目名称:wiremock-ui,代码行数:31,代码来源:validation.ts


示例9: object

import { array, boolean, number, object, string } from 'yup';

export const updateIPSchema = object().shape({
  rdns: string().notRequired().nullable(true)
});

export const allocateIPSchema = object().shape({
  type: string()
    .required()
    .matches(/^ipv4$/, 'Only IPv4 address may be allocated through this endpoint.'),
  public: boolean().required(),
  linode_id: number().required()
});

export const assignAddressesSchema = object().shape({
  region: string().required(),
  assignments: array().of(object()).required()
});

export const shareAddressesSchema = object().shape({
  linode_id: number().required(),
  ips: array().of(string())
});
开发者ID:displague,项目名称:manager,代码行数:23,代码来源:networking.schema.ts


示例10: number

  number()
    .integer()
    .typeError(`Size must be a number`)
    .min(minSize, `Size must be between ${minSize} and ${MAX_VOLUME_SIZE}.`)
    .max(MAX_VOLUME_SIZE, `Size must be between ${minSize} and ${MAX_VOLUME_SIZE}.`)
    .required(`A size is required.`);

export const CreateVolumeSchema = object({
  region: string()
    .when('linode_id', {
      is: (id) => id === undefined || id === '',
      then: string().required("Must provide a region or a Linode ID."),
    }),
  linode_id: number(),
  size: createSizeValidation(10),
  label: string()
    .required("Label is required.")
    .ensure()
    .trim()
    .min(1, "Label must be between 1 and 32 characters.")
    .max(32, "Label must be 32 characters or less."),
  config_id: number().typeError("Config ID must be a number."),
  tags: array().of(string())
});

export const CloneVolumeSchema = object({
  label: string().required()
})

export const ResizeVolumeSchema = (minSize: number = 10) => object({
  size: createSizeValidation(minSize),
开发者ID:displague,项目名称:manager,代码行数:31,代码来源:volumes.schema.ts


示例11: object

import { object, string } from 'yup';

export const CreateBucketSchema = object({
  label: string()
    .required('Label is required.')
    .ensure()
    .trim()
    // @todo: What are the actual limits?
    .min(3, 'Label must be between 3 and 32 characters.')
    .max(32, 'Label must be 32 characters or less.'),
  cluster: string().required('Cluster is required.')
});
开发者ID:linode,项目名称:manager,代码行数:12,代码来源:buckets.schema.ts


示例12: array

import { array, boolean, mixed, number, object, string } from 'yup';
// import * as zxcvbn from 'zxcvbn';

const stackscript_data = array().of(object()).nullable(true);

/* @todo add more comprehensive validation.
*  First validate password using the regex used by the API. Then make sure the password also has a zxcvbn score >= 3.
*  Only run validation tests if image is provided (as otherwise the value passed is an empty string, which will fail
*  validation.)
*/
// const root_pass_disk = string()
//   .when('image', {
//     is: (value) => Boolean(value),
//     then: string().required("You must provide a root password when deploying from an image.")
//       .min(6, "Password must be between 6 and 128 characters.")
//       .max(128, "Password must be between 6 and 128 characters.")
//       .matches(/^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[!"#$%&'()*+,-.\/:;<=>?@\[\]^_`{|}~\\]))|((?=.*[A-Z])(?=.*[!"#$%&'()*+,-.\/:;<=>?@\[\]^_`{|}~\\]))|((?=.*[0-9])(?=.*[!"#$%&'()*+,-.\/:;<=>?@\[\]^_`{|}~\\])))/,
//         "Password must contain at least 2 of the following classes: uppercase letters, lowercase letters, numbers, and punctuation.")
//       .test('is-strong-password', 'Please choose a stronger password.', (value: string) => zxcvbn(value).score > 3),
//     otherwise: string().notRequired()
//   });

export const ResizeLinodeDiskSchema = object({
  size: number().required().min(1),
});

export const CreateLinodeSchema = object({
  type: string()
    .ensure()
    .required('Plan is required.'),
  region: string()
开发者ID:displague,项目名称:manager,代码行数:31,代码来源:linode.schema.ts


示例13: array

import { array, boolean, mixed, number, object, string } from 'yup';
// import * as zxcvbn from 'zxcvbn';

const stackscript_data = array()
  .of(object())
  .nullable(true);

/* @todo add more comprehensive validation.
 *  First validate password using the regex used by the API. Then make sure the password also has a zxcvbn score >= 3.
 *  Only run validation tests if image is provided (as otherwise the value passed is an empty string, which will fail
 *  validation.)
 */
// const root_pass_disk = string()
//   .when('image', {
//     is: (value) => Boolean(value),
//     then: string().required("You must provide a root password when deploying from an image.")
//       .min(6, "Password must be between 6 and 128 characters.")
//       .max(128, "Password must be between 6 and 128 characters.")
//       .matches(/^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[!"#$%&'()*+,-.\/:;<=>?@\[\]^_`{|}~\\]))|((?=.*[A-Z])(?=.*[!"#$%&'()*+,-.\/:;<=>?@\[\]^_`{|}~\\]))|((?=.*[0-9])(?=.*[!"#$%&'()*+,-.\/:;<=>?@\[\]^_`{|}~\\])))/,
//         "Password must contain at least 2 of the following classes: uppercase letters, lowercase letters, numbers, and punctuation.")
//       .test('is-strong-password', 'Please choose a stronger password.', (value: string) => zxcvbn(value).score > 3),
//     otherwise: string().notRequired()
//   });

export const ResizeLinodeDiskSchema = object({
  size: number()
    .required()
    .min(1)
});

export const CreateLinodeSchema = object({
开发者ID:linode,项目名称:manager,代码行数:31,代码来源:linode.schema.ts


示例14: reach

import * as yup from 'yup';
import { setLocale } from 'yup/lib/customLocale';

// tslint:disable-next-line:no-duplicate-imports
import { reach, date, Schema, ObjectSchema, ValidationError, MixedSchema, SchemaDescription, TestOptions, ValidateOptions, NumberSchema } from 'yup';

// reach function
let schema = yup.object().shape({
    nested: yup.object().shape({
        arr: yup.array().of(
            yup.object().shape({ num: yup.number().max(4) })
        )
    })
  });
reach(schema, 'nested.arr.num');
reach(schema, 'nested.arr[].num');

// addMethod function
yup.addMethod<NumberSchema>(yup.number, 'minimum', function(this, minValue: number, message: string) {
    return this.min(minValue, message);
});
yup.addMethod(yup.date, 'newMethod', function(this: yup.DateSchema, date: Date, message?: string) {
    return this.max(date, message);
});

// ref function
schema = yup.object().shape({
    baz: yup.ref('foo.bar'),
    foo: yup.object().shape({
      bar: yup.string()
    }),
开发者ID:Engineer2B,项目名称:DefinitelyTyped,代码行数:31,代码来源:yup-tests.ts


示例15: object

import { object, string } from 'yup';

export const enableTwoFactorSchema = object({
  tfa_code: string().required('Please enter a token.')
});
开发者ID:linode,项目名称:manager,代码行数:5,代码来源:twofactor.schema.ts


示例16: object

import { number, object, string } from 'yup';

const recordBaseSchema = object().shape({
  name: string()
    .max(100, 'Record name must be 100 characters or less.'),
  target: string(),
  priority: number()
    .min(0, 'Priority must be between 0 and 255.')
    .max(255, 'Priority must be between 1 and 255.'),
  weight: number(),
  port: number(),
  service: string().nullable(true),
  protocol: string().nullable(true),
  ttl_sec: number(),
  tag: string()
});

const validRecordTypes: string[] = ['A', 'AAAA', 'NS', 'MX', 'CNAME', 'TXT', 'SRV', 'PTR', 'CAA'];

export const createRecordSchema = recordBaseSchema.shape({
  type: string()
    .required('Type is required.')
    .oneOf(validRecordTypes),
});

export const updateRecordSchema = recordBaseSchema.shape({
  type: string()
    .oneOf(validRecordTypes),
});
开发者ID:displague,项目名称:manager,代码行数:29,代码来源:records.schema.ts


示例17: object

import { number, object, string } from 'yup';

export const createSupportTicketSchema = object({
  summary: string()
    .required('Summary is required.')
    .min(1, 'Summary must be between 1 and 64 characters.')
    .max(64, 'Summary must be between 1 and 64 characters.')
    .trim(),
  description: string()
    .required('Description is required.')
    .min(1, 'Description must be between 1 and 64,000 characters.')
    .max(64000, 'Description must be between 1 and 64,000 characters.')
    .trim(),
  domain_id: number(),
  linode_id: number(),
  longviewclient_id: number(),
  nodebalancer_id: number(),
  volume_id: number(),
});

export const createReplySchema = object({
  description: string()
    .required('Description is required.')
    .min(1, 'Description must be between 1 and 65,535 characters.')
    .max(65535, 'Description must be between 1 and 65,535 characters.')
    .trim()
});
开发者ID:displague,项目名称:manager,代码行数:27,代码来源:support.schema.ts


示例18: object

import { array, boolean, object, string } from 'yup';

export const stackScriptSchema = object({
  script: string().required('Script is required.'),
  label: string()
    .required('Label is required.')
    .min(3, 'Label must be between 3 and 128 characters.')
    .max(128, 'Label must be between 3 and 128 characters.'),
  images: array()
    .of(string())
    .required('An image is required.'),
  description: string(),
  is_public: boolean(),
  rev_note: string()
});

export const updateStackScriptSchema = object({
  script: string(),
  label: string()
    .min(3, 'Label must be between 3 and 128 characters.')
    .max(128, 'Label must be between 3 and 128 characters.'),
  images: array()
    .of(string())
    .min(1, 'An image is required.'),
  description: string(),
  is_public: boolean(),
  rev_note: string()
});
开发者ID:linode,项目名称:manager,代码行数:28,代码来源:stackscripts.schema.ts


示例19:

import * as Yup from "yup";

export const UserRules = {
    email: Yup.string()
        .email("Invalid email address")
        .required("Email is required!"),
    password: Yup.string().required("Password is required!"),
};

export const PriceListRules = {
    item: Yup.object()
        .nullable(true)
        .required("Item is required"),
    name: Yup.string().required("Name is required"),
    quantity: Yup.number()
        .integer()
        .required("Quantity is required")
        .moreThan(0, "Quantity must be greater than zero"),
    slug: Yup.string()
        .min(4)
        .matches(/^[a-z|0-9|_|\-]+$/, "Slug must be a-z, 0-9, or underscore")
        .required("Slug is required"),
};

export const PostRules = {
    body: Yup.string().required("Post body is required"),
    slug: Yup.string()
        .min(4)
        .matches(/^[a-z|0-9|_|\-]+$/, "Slug must be a-z, 0-9, or underscore")
        .required("Slug is required"),
    summary: Yup.string().required("Post summary is required"),
开发者ID:ihsw,项目名称:sotah-client,代码行数:31,代码来源:index.ts


示例20: object

import { array, boolean, object, string } from 'yup';

export const createPersonalAccessTokenSchema = object({
  scopes: string(),
  expiry: string(),
  label: string()
    .min(1, 'Label must be between 1 and 100 characters.')
    .max(100, 'Label must be between 1 and 100 characters.')
});

export const createSSHKeySchema = object({
  label: string()
    .required('Label is required.')
    .min(1, 'Label must be between 1 and 64 characters.')
    .max(64, 'Label must be between 1 and 64 characters.')
    .trim(),
  ssh_key: string()
});

export const updateProfileSchema = object({
  email: string().email(),
  timezone: string(),
  email_notifications: boolean(),
  authorized_keys: array().of(string()),
  restricted: boolean(),
  two_factor_auth: boolean(),
  lish_auth_method: string().oneOf(['password_keys', 'keys_only', 'disabled'])
});
开发者ID:linode,项目名称:manager,代码行数:28,代码来源:profile.schema.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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