UNPKG

@rickosborne/rebound

Version:

Rick Osborne's utilities for working with bounded numbers

15 lines 1.36 kB
import type { ReboundedFromChecked, TypedCheckedBounds } from "./spec.js"; export interface GuardExact<T extends number> extends TypedCheckedBounds { (this: void, value: unknown): value is T; } export interface GuardIfPresent<T extends number> extends TypedCheckedBounds { (this: void, value: unknown): value is T | undefined | null; } export type IfIfPresent<IfPresent extends boolean, T> = IfPresent extends true ? (T | null | undefined) : T; export type If<IfPresent extends boolean | undefined, T, U> = IfPresent extends true ? T : U; export declare const validateBounded: <IsLowerInc extends boolean, Lower extends number, IsInt extends boolean, Upper extends number, IsUpperInc extends boolean, IfPresent extends boolean>(isLowerInc: IsLowerInc, lower: Lower, isInt: IsInt, upper: Upper, isUpperInc: IsUpperInc, ifPresent: IfPresent, value: unknown) => value is IfIfPresent<IfPresent, number & ReboundedFromChecked<IsLowerInc, Lower, IsInt, Upper, IsUpperInc>>; /** * Generate a guard for the branded number type matching the given spec. */ export declare function guardForBounds<Bounds extends Omit<TypedCheckedBounds, "typeName">, N extends number, IfPresent extends boolean>(bounds: Bounds, typeName: string, fnName: string, ifPresent: IfPresent): If<IfPresent, GuardIfPresent<N>, GuardExact<N>>; //# sourceMappingURL=guard-bounded.d.ts.map