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


TypeScript yup.object函数代码示例

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


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


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