Skip to content

setLabels ​

Sets field names for the {label} parameter in the whole app — like attributes in a Laravel lang file.

Signature ​

ts
function setLabels(labels: Record<string, string>): void

Parameters ​

ParameterTypeDescription
labelsRecord<string, string>Field path → name. Use * for array items: 'items.*.title'

Notes ​

  • Priority: label in the schema and the call's labels option → setLabels → the field name.
  • Calls add up: new names are added to the existing ones.

Example ​

ts
import { setMessages, setLabels } from 'tinyval';

setMessages({ required: '{label} is required' });
setLabels({ email: 'Email address', 'items.*.qty': 'Quantity' });

validate(Order, { items: [{}] }).errors;
// { email: 'Email address is required', 'items.0.qty': 'Quantity is required' }

See also ​