Skip to main content

non-empty

$non-empty

Validates that a string, array, or object is not empty. For strings, the value must contain at least one non-whitespace character. For arrays, the length must be greater than zero. For objects, the number of keys must be greater than zero.

Example

// Require a non-blank username
new Schema('string').normalizer('$trim').validator('$non-empty')

// Require at least one tag
new Schema('array').validator('$non-empty')

// Require a non-empty configuration object
new Schema('object').validator('$non-empty')

// Combine trim + non-empty as a common pattern for required text fields
new Schema('object', {
name: new Schema('string').normalizer('$trim').validator('$non-empty'),
description: new Schema('string').normalizer('$trim').validator('$non-empty'),
})