← Runtime data validation

Data.string

luastra/data
Data.string(optionsValue: StringOptions?): Schema

Builds a runtime schema for string input with optional UTF-8 byte-length bounds and trimming defined by Data.StringOptions. The schema is a description only; validation occurs later through Data.decode.

Before you use it

Add luastra/data to this module's dependencies in luastra.json, then import it with require("luastra/data"). No host capability is required. Define schemas outside render when they are reused.

How it fits

This pure constructor returns an immutable schema synchronously; Data.decode performs the actual validation later.

When to use it

Use Data.string for form fields, URL parameters, storage fields, or server properties that must be text at runtime. Add the narrowest useful byte bounds at the untrusted boundary; this alpha has no pattern option, so validate application-specific formats separately.

Parameters

ParameterType / valuesDescription
optionsValueStringOptions?Optional length, trimming, and pattern constraints for accepted strings.
optionsValue.minBytesinteger (0..4096)?Minimum UTF-8 byte length; defaults to 0.
optionsValue.maxBytesinteger (0..4096)?Maximum UTF-8 byte length; defaults to 4096.
optionsValue.trimboolean?Trims surrounding whitespace before validation when true; defaults to false.

Returns

Schema — an immutable runtime schema that can be composed or passed to Data.decode.

What happens next

An immutable schema ready to compose or pass to Data.decode.

Failures and fixes

Ordinary invalid input is a Data.decode failure, not an exception. Invalid schema options are programmer errors and fail immediately. String bounds count UTF-8 bytes; Data.string has no pattern option in this alpha.

Availability

Public-source alpha API in 0.5.0-alpha; host-independent and synchronous.

Focused example

local Data = require("luastra/data")
local title = Data.string { minBytes = 1, maxBytes = 80, trim = true }

Continue learning

Prerequisites

Data.StringOptionsData.decodeData.optional

Complete inventory

View all pages in Runtime data validation
← Previous: Data.SchemaNext: Data.number →