RunTypes

Built-in Formats

Complete reference for all built-in string and number format types with usage examples and parameters.

Type Formats come with a comprehensive set of built-in formats for common validation scenarios. This page documents all available formats, their parameters, and the differences between similar formats.

String Formats

Email

Import from @mionkit/type-formats/FormatsString:

import {StrEmail, StrEmailStrict, StrEmailPunycode} from '@mionkit/type-formats/FormatsString';

StrEmail vs StrEmailStrict

FormatValidationPerformanceUse Case
StrEmailPattern-based (regex)FasterGeneral email validation, allows special chars like +, ()
StrEmailStrictComponent-basedSlowerStrict RFC compliance, validates local part and domain separately

Default Drizzle Column Types

FormatPostgreSQLMySQLSQLite
StrEmailvarchar(254)varchar(254)text()

StrEmail uses a single regex pattern for validation. It allows special characters in the local part:

import {StrEmail} from '@mionkit/type-formats/FormatsString';

type UserEmail = StrEmail;

// Valid
('user@example.com'); // ✓
('user+tag@example.com'); // ✓ (allows + for email aliases)
('user(comment)@test.com'); // ✓

// Invalid
('user@name@example.com'); // ✗ (multiple @)
('@example.com'); // ✗ (missing local part)
StrEmail is the most performant option for email validation. It uses a single regex pattern which makes it significantly faster than component-based validation.

StrEmailStrict validates each component separately (local part, domain, TLD):

import {StrEmailStrict} from '@mionkit/type-formats/FormatsString';

// Valid
('user@example.com'); // ✓
('user.name@sub.domain.com'); // ✓

// Invalid (stricter than StrEmail)
('user+tag@example.com'); // ✗ (disallows special chars)
('user(comment)@test.com'); // ✗ (disallows parentheses)

StrEmailPunycode allows internationalized domains (punycode):

import {StrEmailPunycode} from '@mionkit/type-formats/FormatsString';

type InternationalEmail = StrEmailPunycode;

// Valid
('user@xn--80akhbyknj4f.xn--p1ai'); // ✓ (punycode domain)
('user@sub-domain.example.com'); // ✓ (hyphenated domains)

URL

Import from @mionkit/type-formats/FormatsString:

import {StrUrl, StrUrlHttp, StrUrlFile} from '@mionkit/type-formats/FormatsString';

StrUrl vs StrUrlHttp

FormatAllowed ProtocolsUse Case
StrUrlhttp, https, ftp, ftps, ws, wssGeneral URL validation
StrUrlHttphttp, https onlyWeb URLs only
StrUrlFilefile onlyLocal file paths

Default Drizzle Column Types

FormatPostgreSQLMySQLSQLite
StrUrlvarchar(2048)varchar(2048)text()
import {StrUrl, StrUrlHttp, StrUrlFile} from '@mionkit/type-formats/FormatsString';

type GeneralUrl = StrUrl;
type WebUrl = StrUrlHttp;
type FileUrl = StrUrlFile;

// StrUrl - accepts multiple protocols
('http://example.com'); // ✓
('https://example.com'); // ✓
('ftp://example.com'); // ✓
('ws://example.com'); // ✓

// StrUrlHttp - HTTP/HTTPS only
('http://example.com'); // ✓
('https://example.com'); // ✓
('ftp://example.com'); // ✗
('ws://example.com'); // ✗

// StrUrlFile - file protocol only
('file://hello.png'); // ✓
('file:///c:/lorem/ipsum.jpg'); // ✓
('http://example.com'); // ✗

Domain

Import from @mionkit/type-formats/FormatsString:

import {StrDomain, StrDomainStrict} from '@mionkit/type-formats/FormatsString';

StrDomain vs StrDomainStrict

FormatValidationPerformanceError Messages
StrDomainPattern-based (regex)FasterGeneric errors
StrDomainStrictComponent-basedSlowerDetailed errors per component

Default Drizzle Column Types

FormatPostgreSQLMySQLSQLite
StrDomainvarchar(253)varchar(253)text()
import {StrDomain, StrDomainStrict} from '@mionkit/type-formats/FormatsString';

type QuickDomain = StrDomain;
type DetailedDomain = StrDomainStrict;

// Both validate the same cases
('example.com'); // ✓
('sub.example.com'); // ✓
('example.co.uk'); // ✓

// Invalid for both
('example'); // ✗ (missing TLD)
('example..com'); // ✗ (empty part)
('exa!mple.com'); // ✗ (invalid characters)

Custom Domain Parameters:

import {StrDomainStrict} from '@mionkit/type-formats/FormatsString';

type SocialMediaDomain = StrDomainStrict<{
    maxLength: 200;
    minParts: 2;
    maxParts: 3;
    names: {
        allowedValues: {
            val: ['facebook', 'twitter', 'instagram', 'linkedin'];
            errorMessage: 'Only social media domains allowed';
        };
    };
    tld: {
        allowedValues: {
            val: ['com'];
            errorMessage: 'Only .com TLD allowed';
        };
    };
}>;

UUID

import {StrUUIDv4, StrUUIDv7} from '@mionkit/type-formats/FormatsString';

type UserId = StrUUIDv4; // Standard UUID v4: xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx
type EventId = StrUUIDv7; // Time-ordered UUID v7: xxxxxxxx-xxxx-7xxx-xxxx-xxxxxxxxxxxx

Default Drizzle Column Types

FormatPostgreSQLMySQLSQLite
StrUUID / StrUUIDv7uuid()varchar(36)text()
UUID v7 is better suited for database keys as it's time-ordered and sortable.

IP Address

import {StrIP, StrIPv4, StrIPv6, StrIPWithPort} from '@mionkit/type-formats/FormatsString';

type AnyIP = StrIP; // IPv4 or IPv6
type OnlyV4 = StrIPv4; // IPv4 only
type OnlyV6 = StrIPv6; // IPv6 only
type WithPort = StrIPWithPort; // Any IP with port support

// Examples
('192.168.0.1'); // ✓ StrIPv4
('2001:0db8:85a3::8a2e:0370:7334'); // ✓ StrIPv6
('localhost'); // ✓ (when allowLocalHost: true)

IP Format Parameters:

ParameterTypeDescription
version4 | 6 | 'any'IP version to validate
allowLocalHostbooleanAllow localhost values (127.0.0.1, ::1)
allowPortbooleanAllow port suffix (:8080)

Default Drizzle Column Types

FormatPostgreSQLMySQLSQLite
StrIP / StrIPv4 / StrIPv6inet()varchar(45)text()

Date

Available Date Formats:

FormatExampleDescription
'ISO' or 'YYYY-MM-DD'2023-01-15ISO 8601 date (default)
'DD-MM-YYYY'15-01-2023European format
'MM-DD-YYYY'01-15-2023US format
'YYYY-MM'2023-01Year and month only
'MM-DD'01-15Month and day only
'DD-MM'15-01Day and month only
import {StrDate} from '@mionkit/type-formats/FormatsString';

// Default ISO format
type ISODate = StrDate; // 'YYYY-MM-DD'

// Custom formats
type EuropeanDate = StrDate<{format: 'DD-MM-YYYY'}>;
type USDate = StrDate<{format: 'MM-DD-YYYY'}>;
type MonthYear = StrDate<{format: 'YYYY-MM'}>;

// Validates leap years correctly
('2000-02-29'); // ✓ (leap year)
('1900-02-29'); // ✗ (not a leap year)

Default Drizzle Column Types

FormatPostgreSQLMySQLSQLite
StrDatedate()date()text()

Time

Available Time Formats:

FormatExampleDescription
'ISO' or 'HH:mm:ss[.mmm]TZ'14:30:00ZISO 8601 with timezone (default)
'HH:mm:ss[.mmm]'14:30:00.123With optional milliseconds
'HH:mm:ss'14:30:00Hours, minutes, seconds
'HH:mm'14:30Hours and minutes
'mm:ss'30:45Minutes and seconds
'HH'14Hours only
'mm'30Minutes only
'ss'45Seconds only
import {StrTime} from '@mionkit/type-formats/FormatsString';

// Default ISO format with timezone
type ISOTime = StrTime; // 'HH:mm:ss[.mmm]TZ'

// Custom formats
type SimpleTime = StrTime<{format: 'HH:mm:ss'}>;
type ShortTime = StrTime<{format: 'HH:mm'}>;
type Duration = StrTime<{format: 'mm:ss'}>;

// ISO time examples
('14:30:00Z'); // ✓ UTC
('14:30:00+05:30'); // ✓ with offset
('14:30:00.123Z'); // ✓ with milliseconds

Default Drizzle Column Types

FormatPostgreSQLMySQLSQLite
StrTimetime()time()text()

DateTime

DateTime combines date and time formats with a configurable separator:

import {StrDateTime} from '@mionkit/type-formats/FormatsString';

// Default: ISO date + ISO time, separated by 'T'
type ISODateTime = StrDateTime;
// Example: '2023-01-15T14:30:00Z'

// Custom combination
type CustomDateTime = StrDateTime<{
    date: {format: 'DD-MM-YYYY'};
    time: {format: 'HH:mm'};
    splitChar: ' '; // space separator instead of 'T'
}>;
// Example: '15-01-2023 14:30'

// Short datetime
type ShortDateTime = StrDateTime<{
    date: {format: 'MM-DD'};
    time: {format: 'HH'};
}>;
// Example: '01-15T14'

DateTime Parameters:

ParameterTypeDescription
dateFormatParams_DateDate format configuration
timeFormatParams_TimeTime format configuration
splitCharstringSeparator between date and time (default: 'T')

Default Drizzle Column Types

FormatPostgreSQLMySQLSQLite
StrDateTimetimestamp()datetime()text()

Basic Strings

import {StrAlphaNumeric, StrAlpha, StrNumeric, StrLowercase, StrUppercase} from '@mionkit/type-formats/FormatsString';

type Username = StrAlphaNumeric; // Letters and numbers only
type Name = StrAlpha; // Letters only (supports Unicode)
type Code = StrNumeric; // Digits only
type Slug = StrLowercase; // Forced lowercase
type Initials = StrUppercase; // Forced uppercase

Custom Strings

Use StrFormat to define custom string constraints with validators and transformers:

import {StrFormat} from '@mionkit/type-formats/FormatsString';

// Username: 3-20 chars, lowercase, trimmed
type Username = StrFormat<{
    minLength: 3;
    maxLength: 20;
    lowercase: true;
    trim: true;
}>;

// Slug with pattern validation
const slugRegex = /^[a-z0-9-]+$/;
type Slug = StrFormat<{
    minLength: 1;
    maxLength: 100;
    pattern: {
        val: typeof slugRegex;
        errorMessage: 'Slug can only contain lowercase letters, numbers, and hyphens';
        mockSamples: ['my-post', 'hello-world', 'article-123'];
    };
}>;

// Name with allowed characters only
type SafeName = StrFormat<{
    minLength: 1;
    maxLength: 50;
    allowedChars: {
        val: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ';
        errorMessage: 'Name can only contain letters and spaces';
    };
    capitalize: true;
}>;

String Format Parameters:

ParameterTypeDescription
Validators
minLengthnumberMinimum string length
maxLengthnumberMaximum string length
lengthnumberExact string length
pattern{val: RegExp; errorMessage: string; mockSamples: string[]}Regex pattern validation
allowedChars{val: string; errorMessage: string}Only these characters allowed
disallowedChars{val: string; errorMessage: string; mockSamples: string}These characters not allowed
allowedValues{val: string[]; errorMessage: string}Only these exact values allowed
disallowedValues{val: string[]; errorMessage: string}These exact values not allowed
Transformers
lowercasebooleanConvert to lowercase
uppercasebooleanConvert to uppercase
capitalizebooleanCapitalize first letter
trimbooleanRemove leading/trailing whitespace
replace{searchValue: string; replaceValue: string}Replace first occurrence
replaceAll{searchValue: string; replaceValue: string}Replace all occurrences
When using pattern, disallowedChars, or disallowedValues, you must provide mockSamples so the mock generator knows what valid values to produce.

Number Formats

Import from @mionkit/type-formats/FormatsNumber:

import {
    NumFormat,
    NumInteger,
    NumFloat,
    NumPositive,
    NumNegative,
    NumPositiveInt,
    NumNegativeInt,
    NumInt8,
    NumInt16,
    NumInt32,
    NumUInt8,
    NumUInt16,
    NumUInt32,
} from '@mionkit/type-formats/FormatsNumber';
TypeDescriptionRangeBinary Size
NumIntegerAny integerNumber.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER8 bytes
NumFloatMust be a floatNumber.MIN_VALUE to Number.MAX_VALUE8 bytes
NumPositive≥ 00 to Number.MAX_VALUE8 bytes
NumNegative≤ 0Number.MIN_VALUE to 08 bytes
NumPositiveIntPositive integer0 to Number.MAX_SAFE_INTEGER8 bytes
NumNegativeIntNegative integerNumber.MIN_SAFE_INTEGER to 08 bytes
NumInt88-bit signed-2⁷ to 2⁷-1 (-128 to 127)1 byte
NumInt1616-bit signed-2¹⁵ to 2¹⁵-1 (-32,768 to 32,767)2 bytes
NumInt3232-bit signed-2³¹ to 2³¹-1 (-2,147,483,648 to 2,147,483,647)4 bytes
NumUInt88-bit unsigned0 to 2⁸-1 (255)1 byte
NumUInt1616-bit unsigned0 to 2¹⁶-1 (65,535)2 bytes
NumUInt3232-bit unsigned0 to 2³²-1 (4,294,967,295)4 bytes
Using the correct number format is important for binary serialization. Typed integers (e.g., NumInt8, NumUInt16) are encoded more efficiently than generic numbers, resulting in smaller binary payloads.

Default Drizzle Column Types

FormatPostgreSQLMySQLSQLite
NumInteger / NumPositiveInt / NumNegativeIntinteger()int()integer()
NumInt8 / NumInt16 / NumInt32integer()int()integer()
NumUInt8 / NumUInt16 / NumUInt32integer()int()integer()
NumFloat / NumPositive / NumNegativedoublePrecision()double()real()
BigIntFormat (TypeScript bigint)bigint({mode: 'bigint'})bigint({mode: 'bigint'})blob({mode: 'bigint'})

Custom Numbers

import {NumFormat} from '@mionkit/type-formats/FormatsNumber';

// Age with valid range
type Age = NumFormat<{
    min: 0;
    max: 120;
    integer: true;
}>;

// Percentage with decimals
type Percentage = NumFormat<{
    min: 0;
    max: 100;
}>;

// Price must be multiple of 0.01 (cents)
type Price = NumFormat<{
    min: 0;
    multipleOf: 1; // multipleOf must be integer
    integer: true; // store as cents
}>;

Number Format Parameters:

ParameterTypeDescription
minnumberMinimum value (inclusive)
maxnumberMaximum value (inclusive)
gtnumberGreater than (exclusive)
ltnumberLess than (exclusive)
integerbooleanMust be an integer
floatbooleanMust be a float
multipleOfnumberMust be a multiple of (integer only)

Note: min/max and gt/lt are mutually exclusive. integer and float are also mutually exclusive.