@flect/guard

4.2.0 • Public • Published

flect logo

Flect/guard

Typeguards for Flect types

Introduction

Flect/guard is a library for validating that arbitrary JavaScript objects conform to a Flect type.

Usage

const Animal = record({
	legCount: numberType,
	sound: stringType
});
type Animal = Reify<typeof Animal>;

const v = new GuardChain();
const recV = new RecordValidator(v);
v.add(defaultGuards);
v.add(recV);

const maybeAnimal: unknown = {legCount: 3, sound: "woof"};
const animalGuard = v.get(Animal)!;
if (animalGuard(maybeAnimal)) {
	console.log(maybeAnimal.sound); // Goes 'woof'
}

/@flect/guard/

    Package Sidebar

    Install

    npm i @flect/guard

    Weekly Downloads

    4

    Version

    4.2.0

    License

    MIT

    Unpacked Size

    50.7 kB

    Total Files

    7

    Last publish

    Collaborators

    • ddurschlag