rawValue

function rawValue(verificable): unknown

This function returns the raw value behind a Verificable object, without performing any checks on it.

This function is mainly useful when writing your own Predicate functions, to get the raw value out of the Verificable and perform necessary checks on it, returning VerificaError if value is not considered matching.

Examples:

First, let's define an example object product that we want to verify and wrap it with asVerificable():

const { asVerificable, rawValue } = require("verifica");

const product = {
    name: "Headphones",
    price: 1200,
};
const verificable = asVerificable(product);

Then, we can call rawValue() to get the raw value behind the Verificable object:

rawValue(verificable); // { name: "Headphones", price: 1200 }

We can also call rawValue() for any of Verificable object properties, since they are always a Verificable objects as well, representing the deeper nested values:

rawValue(verificable.name); // "Headphones"

Calling rawValue() on a Verificable representing missing value will result in VerificaException:

rawValue(verificable.not.existing.path); // <throws VerificaException>

Last updated