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


TypeScript yup.number函数代码示例

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


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

示例1: number

const createSizeValidation = (minSize: number = 10) =>
  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.`);
开发者ID:displague,项目名称:manager,代码行数:7,代码来源:volumes.schema.ts

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

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

示例4: object

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,代码行数:30,代码来源:nodebalancers.schema.ts

示例5: 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.`),

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

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

示例6:

    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()
            .required('Header value is required'),
    }))
})
开发者ID:manishshanker,项目名称:wiremock-ui,代码行数:31,代码来源:validation.ts

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

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

示例9: object

*  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()
    .ensure()
    .required('Region is required.'),
  stackscript_id: number().notRequired(),
  backup_id: number().notRequired(),
  swap_size: number().notRequired(),
  image: string().nullable(true),
  root_pass: string().notRequired(),
  authorized_keys: array().of(string()).notRequired(),
开发者ID:displague,项目名称:manager,代码行数:31,代码来源:linode.schema.ts

示例10: object

export const ExecutePaypalPaymentSchema = object({
  payer_id: string().required('You must provide a payer ID.'),
  payment_id: string().required('You must provide a payment ID (from Paypal).')
});

export const PaymentSchema = object({
  usd: string().required('USD payment amount is required.')
});

export const CreditCardSchema = object({
  card_number: string()
    .required('Credit card number is required.')
    .min(13, 'Credit card number must be between 13 and 23 characters.')
    .max(23, 'Credit card number must be between 13 and 23 characters.'),
  expiry_year: number()
    .required('Expiration year is required.')
    .min(new Date().getFullYear(), 'Expiration year must not be in the past.')
    .max(9999, 'Expiration year must be four digits.'),
  expiry_month: number()
    .required('Expiration month is required.')
    .min(1, 'Expiration month must be a number from 1 to 12.')
    .max(12, 'Expiration month must be a number from 1 to 12.')
});

export const CreateUserSchema = object({
  username: string()
    .required('Username is required.')
    .min(3, 'Username must be between 3 and 32 characters.')
    .max(32, 'Username must be between 3 and 32 characters.'),
  email: string()
开发者ID:linode,项目名称:manager,代码行数:30,代码来源:account.schema.ts


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