本文整理汇总了TypeScript中validator.isLength函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isLength函数的具体用法?TypeScript isLength怎么用?TypeScript isLength使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isLength函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: isString
userSchema.path('name').validate(function(name: string) {
// this gets default from username if not set anyway.
if (this.isNew) {
return true;
}
return isString(name) && isLength(name, 3, 30);
}, 'Name must be between 3 and 30 characters.');
示例2:
userSchema.path('password_hash').validate(function() {
// here we check the length. remember that the virtual _password field is
// the one that triggers the hashing.
if (this._password && isString(this._password) && !isLength(this._password, 6)) {
this.invalidate('password', 'Password must be at least 6 characters.');
}
}, null);
示例3: isActorPublicKeyValid
function isActorPublicKeyValid (publicKey: string) {
return exists(publicKey) &&
typeof publicKey === 'string' &&
publicKey.startsWith('-----BEGIN PUBLIC KEY-----') &&
publicKey.indexOf('-----END PUBLIC KEY-----') !== -1 &&
validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACTORS.PUBLIC_KEY)
}
示例4: isActorPrivateKeyValid
function isActorPrivateKeyValid (privateKey: string) {
return exists(privateKey) &&
typeof privateKey === 'string' &&
privateKey.startsWith('-----BEGIN RSA PRIVATE KEY-----') &&
// Sometimes there is a \n at the end, so just assert the string contains the end mark
privateKey.indexOf('-----END RSA PRIVATE KEY-----') !== -1 &&
validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACTORS.PRIVATE_KEY)
}
示例5: isValid
public static isValid(obj: any): boolean {
if (obj.post_id && !validator.isInt(obj.post_id))
return false;
if (!obj.post_date || !moment(obj.post_date, "MMM DD, YYYY").isValid())
return false;
if (!obj.post_status || !validator.isIn(obj.post_status, ["Enabled", "Disabled"]))
return false;
if (!obj.post_title || !validator.isLength(obj.post_title, {max: 255}))
return false;
if (!validator.isLength(obj.post_image, {max: 255}))
return false;
if (!validator.isLength(obj.post_intro_markdown, {max: 255}))
return false;
if (!obj.post_markdown || !validator.isLength(obj.post_markdown, {max: 10000}))
return false;
if (!obj.post_alias || !validator.isLength(obj.post_alias, {min: 5, max: 255}))
return false;
return true;
}
示例6: isActivityPubUrlValid
function isActivityPubUrlValid (url: string) {
const isURLOptions = {
require_host: true,
require_tld: true,
require_protocol: true,
require_valid_protocol: true,
protocols: [ 'http', 'https' ]
}
// We validate 'localhost', so we don't have the top level domain
if (isTestInstance()) {
isURLOptions.require_tld = false
}
return exists(url) && validator.isURL('' + url, isURLOptions) && validator.isLength('' + url, CONSTRAINTS_FIELDS.ACTORS.URL)
}
示例7: isRemoteVideoUrlValid
function isRemoteVideoUrlValid (url: any) {
return url.type === 'Link' &&
(
ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 &&
isActivityPubUrlValid(url.href) &&
validator.isInt(url.width + '', { min: 0 }) &&
validator.isInt(url.size + '', { min: 0 })
) ||
(
ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 &&
isActivityPubUrlValid(url.href) &&
validator.isInt(url.width + '', { min: 0 })
) ||
(
ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mimeType) !== -1 &&
validator.isLength(url.href, { min: 5 }) &&
validator.isInt(url.width + '', { min: 0 })
)
}
示例8: isVideoLanguageValid
function isVideoLanguageValid (value: any) {
return value === null ||
(typeof value === 'string' && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.LANGUAGE))
}
示例9: isString
commentSchema.path('message').validate((msg: any) => {
return isString(msg) && validator.isLength(msg, 3, 5000);
}, 'Message must be at least 3 chars and no longer than 5k characters.');
示例10: isVideoFileInfoHashValid
function isVideoFileInfoHashValid (value: string) {
return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
}