當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript yup.mixed函數代碼示例

本文整理匯總了TypeScript中yup.mixed函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript mixed函數的具體用法?TypeScript mixed怎麽用?TypeScript mixed使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了mixed函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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:

    path: "path",
    errors: ["error"],
    inner: [yup.ValidationError("error", true, "path")],
    type: "date",
    value: { start: "2017-11-10" }
};
error.value = "value";
error.value = true;
error.value = 5;
error.value = { name: "value" };
error.type = {};
error.type = [];
error.errors = ["error"];

// mixed
let mixed: MixedSchema = yup.mixed();
mixed.clone();
mixed.label("label");
mixed.meta({ meta: "value" });
mixed.describe().label;
mixed.describe().meta;
mixed.describe().tests;
mixed.describe().type;
mixed.concat(yup.string());
mixed.validate({});
mixed.validate({ hello: "world" }, { strict: true }).then(value => value);
mixed.validateSync({ hello: "world" }, { strict: true });
mixed.validateAt("path", {}, { strict: true, context: {} });
mixed
    .validateAt("path", {}, { strict: true, context: {} })
    .then(value => value);
開發者ID:j-f1,項目名稱:forked-DefinitelyTyped,代碼行數:31,代碼來源:yup-tests.ts

示例3: number

      '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']),
  check_attempts: number(),
  check_body: string().when('check', {
    is: 'http_body',
    then: string().required()
  }),
  check_interval: number().typeError('Check interval must be a number.'),
  check_passive: boolean(),
  check_path: string()
    .matches(/\/.*/)
    .when('check', { is: 'http', then: string().required() })
    .when('check', { is: 'http_body', then: string().required() }),
開發者ID:linode,項目名稱:manager,代碼行數:31,代碼來源:nodebalancers.schema.ts

示例4: string



  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(),
  check_body: string()
    .when('check', { is: 'http_body', then: string().required() }),
  check_interval: number().typeError("Check interval must be a number."),
  check_passive: boolean(),
  check_path: string().matches(/\/.*/)
    .when('check', { is: 'http', then: string().required() })
    .when('check', { is: 'http_body', then: string().required() }),
  check_timeout: number().typeError("Timeout must be a number.").integer(),
  check: mixed().oneOf(["none", "connection", "http", "http_body"]),
開發者ID:displague,項目名稱:manager,代碼行數:29,代碼來源:nodebalancers.schema.ts

示例5: boolean

  restricted: boolean().required(
    'You must indicate if this user should have restricted access.'
  )
});

export const UpdateUserSchema = object({
  username: string()
    .min(3, 'Username must be between 3 and 32 characters.')
    .max(32, 'Username must be between 3 and 32 characters.'),
  email: string().email('Must be a valid email address.'),
  restricted: boolean()
});

const GrantSchema = object({
  id: number().required('ID is required.'),
  permissions: mixed().oneOf(
    [null, 'read_only', 'read_write'],
    'Permissions must be null, read_only, or read_write.'
  )
});

export const UpdateGrantSchema = object({
  global: object(),
  linode: array().of(GrantSchema),
  domain: array().of(GrantSchema),
  nodebalancer: array().of(GrantSchema),
  image: array().of(GrantSchema),
  longview: array().of(GrantSchema),
  stackscript: array().of(GrantSchema),
  volume: array().of(GrantSchema)
});
開發者ID:linode,項目名稱:manager,代碼行數:31,代碼來源:account.schema.ts

示例6: boolean

  restricted: boolean()
    .required("You must indicate if this user should have restricted access.")
});

export const UpdateUserSchema = object({
  username: string()
  .min(3, "Username must be between 3 and 32 characters.")
  .max(32, "Username must be between 3 and 32 characters."),
  email: string()
    .email("Must be a valid email address."),
  restricted: boolean()
});

const GrantSchema = object({
  id: number().required("ID is required."),
  permissions: mixed()
    .oneOf([null, 'read_only', 'read_write'],
    "Permissions must be null, read_only, or read_write.")
})

export const UpdateGrantSchema = object({
  global: object(),
  linode: array().of(GrantSchema),
  domain: array().of(GrantSchema),
  nodebalancer: array().of(GrantSchema),
  image: array().of(GrantSchema),
  longview: array().of(GrantSchema),
  stackscript: array().of(GrantSchema),
  volume: array().of(GrantSchema),
});
開發者ID:displague,項目名稱:manager,代碼行數:30,代碼來源:account.schema.ts

示例7: array

  authorized_users: array().of(string()).notRequired()
});

const alerts = object({
  cpu: number()
    .typeError("CPU Usage must be a number")
    .min(0, "Must be between 0 and 2000")
    .max(2000, "Must be between 0 and 2000"),
  network_in: number(),
  network_out: number(),
  transfer_quota: number(),
  io: number(),
}).nullable(true);

const schedule = object({
  day: mixed().oneOf(["Sunday", "Monday", "Tuesday",
  "Wednesday", "Thursday", "Friday", "Saturday"], "Invalid day value."),
  window: mixed().oneOf(["W0", "W2", "W4", "W8", "W10",
  "W12", "W14", "W16", "W18", "W20", "W22"], "Invalid schedule value."),
});

const backups = object({
  schedule,
  enabled: boolean(),
})

export const UpdateLinodeSchema = object({
  label: string().nullable(true)
    .min(3, "Label must contain between 3 and 32 characters.")
    .max(32,"Label must contain between 3 and 32 characters.")
    .matches(/^[a-zA-Z]((?!--|__)[a-zA-Z0-9-_])+$/,
開發者ID:displague,項目名稱:manager,代碼行數:31,代碼來源:linode.schema.ts

示例8: object

    .notRequired()
});

const alerts = object({
  cpu: number()
    .typeError('CPU Usage must be a number')
    .min(0, 'Must be between 0 and 2000')
    .max(2000, 'Must be between 0 and 2000'),
  network_in: number(),
  network_out: number(),
  transfer_quota: number(),
  io: number()
}).nullable(true);

const schedule = object({
  day: mixed().oneOf(
    [
      'Sunday',
      'Monday',
      'Tuesday',
      'Wednesday',
      'Thursday',
      'Friday',
      'Saturday'
    ],
    'Invalid day value.'
  ),
  window: mixed().oneOf(
    [
      'W0',
      'W2',
開發者ID:linode,項目名稱:manager,代碼行數:31,代碼來源:linode.schema.ts

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


注:本文中的yup.mixed函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。