transformers
const transformers: object;
Defined in: core/behavior/behaviors/transform-value.ts:209
Готовые трансформеры для частых случаев. Все идемпотентны и безопасны для повторного применения.
Type Declaration
digitsOnly()
digitsOnly: <TForm>(field, options?) => void;
Оставить только цифры
Type Parameters
TForm
TForm extends FormFields
Parameters
field
FieldPathNode<TForm, string>
options?
TransformValueOptions & object
Returns
void
removeSpaces()
removeSpaces: <TForm>(field, options?) => void;
Удалить все пробелы
Type Parameters
TForm
TForm extends FormFields
Parameters
field
FieldPathNode<TForm, string>
options?
TransformValueOptions & object
Returns
void
round()
round: <TForm>(field, options?) => void;
Округлить число
Type Parameters
TForm
TForm extends FormFields
Parameters
field
FieldPathNode<TForm, number>
options?
TransformValueOptions & object
Returns
void
roundTo2()
roundTo2: <TForm>(field, options?) => void;
Округлить до 2 знаков после запятой
Type Parameters
TForm
TForm extends FormFields
Parameters
field
FieldPathNode<TForm, number>
options?
TransformValueOptions & object
Returns
void
toLowerCase()
toLowerCase: <TForm>(field, options?) => void;
Перевести в нижний регистр
Type Parameters
TForm
TForm extends FormFields
Parameters
field
FieldPathNode<TForm, string>
options?
TransformValueOptions & object
Returns
void
toUpperCase()
toUpperCase: <TForm>(field, options?) => void;
Перевести в верхний регистр
Type Parameters
TForm
TForm extends FormFields
Parameters
field
FieldPathNode<TForm, string>
options?
TransformValueOptions & object
Returns
void
trim()
trim: <TForm>(field, options?) => void;
Удалить пробелы с краев
Type Parameters
TForm
TForm extends FormFields
Parameters
field
FieldPathNode<TForm, string>
options?
TransformValueOptions & object
Returns
void
Examples
import { transformers, type BehaviorSchemaFn } from '@reformer/core/behaviors';
interface RegistrationForm {
username: string;
email: string;
promoCode: string;
inn: string;
amount: number;
}
export const behavior: BehaviorSchemaFn<RegistrationForm> = (path) => {
transformers.trim(path.username);
transformers.toLowerCase(path.email);
transformers.toUpperCase(path.promoCode);
transformers.digitsOnly(path.inn);
transformers.roundTo2(path.amount);
};
import { createTransformer, type BehaviorSchemaFn } from '@reformer/core/behaviors';
// trim + lowercase в одном трансформере (применяется как одна операция)
const normalizeEmail = createTransformer<string>(
(v) => (v ?? '').trim().toLowerCase(),
);
interface ContactForm { email: string }
export const contactBehavior: BehaviorSchemaFn<ContactForm> = (path) => {
normalizeEmail(path.email);
};