Rod

Transformations

Custom logic and data mapping.

Transformations

Transformations allow you to add custom validation logic (refine) or modify the data (transform) after it has passed initial type checks.

Refine (Custom Validation)

Add custom constraints that aren't covered by built-in validators.

use rod_rs::refine;

let schema = refine(string(), |val| {
    if val.as_str().unwrap().contains("!") {
        Ok(())
    } else {
        Err("Must contain !".to_string())
    }
});
import { rod } from 'rod-js';

const schema = rod.string().refine(
    (val) => val.includes("!"),
    "Must contain !"
);
# Refinements are coming soon to Python bindings.

Transform (Data Mapping)

Modify the output value of the validation.

use rod_rs::{transform, RodValue};

let schema = transform(number(), |val| {
    RodValue::Number(val.as_f64().unwrap() * 2.0)
});
import { rod } from 'rod-js';

const schema = rod.number().transform((val) => val * 2);
# Transformations are coming soon to Python bindings.

On this page