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


TypeScript yup.string函数代码示例

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


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

示例1: switch

const renderable = yup.lazy(value => {
    switch (typeof value) {
        case "number":
            return yup.number();
        case "string":
            return yup.string();
        default:
            return yup.mixed();
    }
});
开发者ID:j-f1,项目名称:forked-DefinitelyTyped,代码行数:10,代码来源:yup-tests.ts

示例2: 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

示例3: object

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

export const updateAccountSchema = object({
  email: string()
    .max(128, "Email must be 128 characters or less."),
  address_1: string()
    .max(64, "Address must be 64 characters or less."),
  city: string()
    .max(24, "City must be 24 characters or less."),
  company: string()
    .max(128, "Company must be 128 characters or less."),
  country: string()
    .min(2, "Country code must be two letters.")
    .max(2, "Country code must be two letters."),
  first_name: string()
    .max(50, "First name must be 50 characters or less."),
  last_name: string()
    .max(50, "Last name must be 50 characters or less."),
  address_2: string()
    .max(64, "Address must be 64 characters or less."),
  phone: string()
    .max(32, "Phone number must be 32 characters or less."),
  state: string()
    .max(24, "State must be 24 characters or less."),
  tax_id: string()
    .max(100, "Tax ID must be 100 characters or less."),
  zip: string()
    .max(16, "Zip code must be 16 characters or less.")
});

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

示例4: object

    .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.`);

// @todo this should be used in CreateVolumeForm and CreateVolumeFromLinodeForm
// export const tag = string()
//   .min(3, "Tags must be between 3 and 50 characters.")
//   .max(50, "Tags must be between 3 and 50 characters.")

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())
});
开发者ID:linode,项目名称:manager,代码行数:30,代码来源:volumes.schema.ts

示例5: 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

示例6: 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

示例7: function

) {
    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()
    }),
    x: yup.ref("$x")
});

schema.cast({ foo: { bar: "boom" } }, { context: { x: 5 } });

// lazy function
const node: ObjectSchema<any> = yup.object().shape({
    id: yup.number(),
    child: yup.lazy(() => node.default(undefined))
});
const renderable = yup.lazy(value => {
    switch (typeof value) {
        case "number":
            return yup.number();
开发者ID:j-f1,项目名称:forked-DefinitelyTyped,代码行数:31,代码来源:yup-tests.ts

示例8: 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

示例9: object

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

import { NodeBalancerConfigFields } from './interfaces';

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 private 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.`),
开发者ID:linode,项目名称:manager,代码行数:31,代码来源:nodebalancers.schema.ts

示例10: 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


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