pure-parse
Version:
Strongly typed validation library that decouples type aliases from validation logic
31 lines (30 loc) • 887 B
TypeScript
import { Primitive } from '../common';
import { Guard } from './Guard';
/**
* Compares the input against a list of primitive values with the strict equality operator (`===`).
* The inferred type of the guard is that of a literal type; for example, `equalsGuard('red')` returns a `Guard<'red'>`.
* @example
* ```ts
* const isRed = equalsGuard('red')
* isRed('red') // -> true
* isRed('blue') // -> false
*
* const isOne = equalsGuard(1)
* isOne(1) // -> true
* isOne(2) // -> false
* ```
* @example
* Commonly used in discriminated unions:
* ```ts
* const isResult = oneOfGuard([
* objectGuard({
* tag: equalsGuard('success')
* }),
* objectGuard({
* tag: equalsGuard('error')
* }),
* ])
* ```
* @param constant compared against `data` with the `===` operator.
*/
export declare const equalsGuard: <const T extends Primitive>(constant: T) => Guard<T>;