Decorators

@system-inc/base-foundation · 515c140 · 33 symbols

Validates that an array property contains no more than the given number of elements.

VerifyArrayMaxSize: OptionsRuleDecorator<number>
@VerifyArrayMaxSize(10)
tags: string[];

View source ↗

Validates that an array property contains at least the given number of elements.

VerifyArrayMinSize: OptionsRuleDecorator<number>
@VerifyArrayMinSize(1)
tags: string[];

View source ↗

Validates that an array property contains only unique values.

VerifyArrayUnique: VoidRuleDecorator
@VerifyArrayUnique()
tags: string[];

View source ↗

@VerifyBy

decorator

Creates a property decorator for a validation rule.

The returned factory is callable (VerifyIsEmail() / VerifyMaxLength(255)) and also exposes a .check() predicate for ad-hoc use:

VerifyIsEmail.check('foo@bar.com');       // true
VerifyMaxLength.check('abc', 255);         // true

Usage:

// No options:
export const VerifyIsString = registerRule<void>({
    name: 'IsString',
    check: (value) => typeof value === 'string',
    defaultMessage: ({ property }) => `${property} must be a string`,
});

// With options:
export const VerifyMaxLength = registerRule<number>({
    name: 'MaxLength',
    check: (value, max) =>
        typeof value === 'string' && value.length <= max,
    defaultMessage: ({ property, options }) =>
        `${property} must be at most ${options} characters`,
});

// Array-level:
export const VerifyArrayMinSize = registerRule<number>({
    name: 'ArrayMinSize',
    operatesOn: 'array',
    check: (value, min) => Array.isArray(value) && value.length >= min,
    defaultMessage: ({ property, options }) =>
        `${property} must contain at least ${options} elements`,
});
VerifyBy(definition: RuleDefinition<TOptions>): RuleDecorator<TOptions>

View source ↗

Validates that the property is an array.

VerifyIsArray: VoidRuleDecorator
@VerifyIsArray()
tags: string[];

View source ↗

Validates that the property is a boolean.

VerifyIsBoolean: VoidRuleDecorator
@VerifyIsBoolean()
verified: boolean;

View source ↗

Validates that a value is a real ISO 3166-1 country code. Membership is checked against the complete list (249 entries per format).

Formats:

  • 'alpha2' (default) — two uppercase letters (US, DE, GB)
  • 'alpha3' — three uppercase letters (USA, DEU, GBR)
  • 'numeric' — three digits as a string, zero-padded (840, 276, 826)

The ISO list is stable (1–2 updates per decade); the embedded data lives in ./internal/Iso3166Codes.ts and can be resynced from the ISO Maintenance Agency when needed.

VerifyIsCountryCode: (format: CountryCodeFormat) => PropertyDecorator & { check: (value: unknown, format: CountryCodeFormat) => boolean }
@VerifyIsCountryCode('alpha2')
country: string;

View source ↗

@VerifyIsDate

decorator

Validates that the property is a valid Date instance.

VerifyIsDate: VoidRuleDecorator
@VerifyIsDate()
birthday: Date;

View source ↗

Validates that the property is neither null nor undefined.

VerifyIsDefined: VoidRuleDecorator
@VerifyIsDefined()
accountId: string;

View source ↗

Validates that the property is a domain name such as example.com or api.example.co.uk.

VerifyIsDomain: VoidRuleDecorator
@VerifyIsDomain()
domain: string;

View source ↗

Validates that the property is a plausible email address. Pragmatic rather than strictly RFC 5322 — layer VerifyStringMatches or VerifyBy for stricter needs.

VerifyIsEmail: VoidRuleDecorator
@VerifyIsEmail()
email: string;

View source ↗

@VerifyIsEnum

decorator

Validates that a value is one of a defined enumeration.

"Enumeration" here is the general sense — any fixed set of allowed values — not strictly a TypeScript enum. Accepts:

  • A TypeScript enum: @VerifyIsEnum(Status)
  • A const object: @VerifyIsEnum({ A: 'a', B: 'b' } as const)
  • A plain array: @VerifyIsEnum(['Contact', 'Article'])
VerifyIsEnum: (allowed: EnumLike) => PropertyDecorator & { check: (value: unknown, allowed: EnumLike) => boolean }
@VerifyIsEnum(OrderStatus)
status: OrderStatus;

View source ↗

@VerifyIsInt

decorator

Validates that the property is an integer.

VerifyIsInt: VoidRuleDecorator
@VerifyIsInt()
quantity: number;

View source ↗

@VerifyIsIP

decorator

Validates that the property is an IPv4 or IPv6 address. Pass a version to accept only one family.

VerifyIsIP: (version?: IPVersion) => PropertyDecorator & { check: (value: unknown, version?: IPVersion) => boolean }
@VerifyIsIP(4)
address: string;

View source ↗

Validates that a value is a well-formed BCP 47 language tag.

Uses the built-in Intl.Locale constructor, which parses the full BCP 47 grammar (language, script, region, variants, extensions). Examples that pass: "en", "en-US", "zh-Hans-CN", "ja-JP-u-ca-japanese". Examples that fail: "not-a-locale", "english", "en_US" (underscore).

This is real validation — the runtime does the parsing, so there's no shipped allowlist to maintain.

VerifyIsLocale: VoidRuleDecorator
@VerifyIsLocale()
locale: string;

View source ↗

Validates that the property is not empty — rejects null, undefined, '', [], and {}. Numbers (including 0), booleans, and class instances are never empty.

VerifyIsNotEmpty: VoidRuleDecorator
@VerifyIsNotEmpty()
name: string;

View source ↗

Validates that the property is a finite number.

VerifyIsNumber: VoidRuleDecorator
@VerifyIsNumber()
price: number;

View source ↗

Validates that the property is an object (not an array and not null).

VerifyIsObject: VoidRuleDecorator
@VerifyIsObject()
metadata: object;

View source ↗

Marks the property as optional. When the value is null or undefined, every other rule on the property is skipped.

The rule itself always passes — it serves as a sentinel read by the ValidationEngine.

VerifyIsOptional: VoidRuleDecorator
@VerifyIsOptional()
@VerifyIsEmail()
email?: string;

View source ↗

Standalone validator — exposed for callers that need to run the phone-number check outside a decorator (e.g. in a service method).

verifyIsPhoneNumber(value: unknown, options?: IsPhoneNumberOptions): boolean

View source ↗

Validates that the property is a phone number in an accepted format (E.164 and North American formats by default).

VerifyIsPhoneNumber: (options?: IsPhoneNumberOptions) => PropertyDecorator & { check: (value: unknown, options?: IsPhoneNumberOptions) => boolean }
@VerifyIsPhoneNumber()
phone: string;

View source ↗

Validates that the property is a string.

VerifyIsString: VoidRuleDecorator
@VerifyIsString()
name: string;

View source ↗

Validates that the property is a valid IANA time zone name such as America/Denver.

VerifyIsTimeZone: VoidRuleDecorator
@VerifyIsTimeZone()
timeZone: string;

View source ↗

@VerifyIsUrl

decorator

Validates that the property is a valid http: or https: URL.

VerifyIsUrl: VoidRuleDecorator
@VerifyIsUrl()
website: string;

View source ↗

@VerifyIsUUID

decorator

Validates that the property is a UUID of the given version (18, or 'all' for any version).

VerifyIsUUID: (version: UUIDVersion) => PropertyDecorator & { check: (value: unknown, version: UUIDVersion) => boolean }
@VerifyIsUUID(4)
id: string;

View source ↗

@VerifyLength

decorator

Validates that a string or array property's length is at least min and, when given, at most max (inclusive).

VerifyLength: (min: number, max?: number) => PropertyDecorator & { check: (value: unknown, min: number, max?: number) => boolean }
@VerifyLength(1, 80)
title: string;

View source ↗

@VerifyMax

decorator

Validates that a number property is not greater than the given maximum.

VerifyMax: OptionsRuleDecorator<number>
@VerifyMax(100)
percentage: number;

View source ↗

Validates that a Date property is on or before the given maximum.

VerifyMaxDate: (maximum: Date) => PropertyDecorator & { check: (value: unknown, maximum: Date) => boolean }
@VerifyMaxDate(new Date('2030-01-01'))
expiresAt: Date;

View source ↗

Validates that a string or array property is at most the given length.

VerifyMaxLength: OptionsRuleDecorator<number>
@VerifyMaxLength(280)
message: string;

View source ↗

@VerifyMin

decorator

Validates that a number property is not less than the given minimum.

VerifyMin: OptionsRuleDecorator<number>
@VerifyMin(0)
quantity: number;

View source ↗

Validates that a Date property is on or after the given minimum.

VerifyMinDate: (minimum: Date) => PropertyDecorator & { check: (value: unknown, minimum: Date) => boolean }
@VerifyMinDate(new Date('2000-01-01'))
startsAt: Date;

View source ↗

Validates that a string or array property is at least the given length.

VerifyMinLength: OptionsRuleDecorator<number>
@VerifyMinLength(8)
password: string;

View source ↗

Regex match against a string value. Accepts either a RegExp or a pattern string; strings are promoted to new RegExp(pattern, modifiers).

VerifyStringMatches: (pattern: string | RegExp, modifiers?: string) => PropertyDecorator & { check: (value: unknown, pattern: string | RegExp, modifiers?: string) => boolean }
@VerifyStringMatches(/^[a-z0-9-]+$/)
slug: string;

View source ↗