本文整理汇总了TypeScript中yup.array函数的典型用法代码示例。如果您正苦于以下问题:TypeScript array函数的具体用法?TypeScript array怎么用?TypeScript array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
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()
}),
示例2: function
date,
Schema,
ObjectSchema,
ValidationError,
MixedSchema,
SchemaDescription,
TestOptions,
ValidateOptions,
NumberSchema,
TestContext
} 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,
示例3: number
check_timeout: number().typeError("Timeout must be a number.").integer(),
check: mixed().oneOf(["none", "connection", "http", "http_body"]),
cipher_suite: mixed().oneOf(["recommended", "legacy"]),
port: number().integer()
.required('Port is required')
.min(1, "Port must be between 1 and 65535.")
.max(65535, "Port must be between 1 and 65535."),
protocol: mixed().oneOf(['http', 'https', 'tcp']),
ssl_key: string()
.when('protocol', { is: 'https', then: string()
.required('SSL key is required when using HTTPS.') }),
ssl_cert: string()
.when('protocol', { is: 'https', then: string()
.required('SSL certificate is required when using HTTPS.') }),
stickiness: mixed().oneOf(["none", "table", "http_cookie"]),
nodes: array()
.of(nodeBalancerConfigNodeSchema).required().min(1, "You must provide at least one back end node."),
});
export const UpdateNodeBalancerConfigSchema = 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"]),
示例4: 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'])
});
示例5:
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()
示例6: 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()
});
示例7: 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())
});
示例8: object
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),
})
export const UpdateVolumeSchema = object({
label: string().required()
})
export const AttachVolumeSchema = object({
示例9: 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)
});
export const UpdateAccountSettingsSchema = object({
network_helper: boolean(),
backups_enabled: boolean(),
managed: boolean()
});