Skip to content

Repository files navigation

fresh-validation

keeps your data fresh

Provides validateData(data, Class), which throws a TypeError if the runtime types of any properties annotated with @validate() do not match their Typescript types

Version 3

Version 3 is a complete rewrite in typescript. Use @validate() decorators to automatically tag class members that should be validated at runtime, using reflected type metadata.

Usage

import{validate}from'fresh-validation';classA{
@validate()count: number;
@validate()// deep typechecking on decorated classesoptions: Position;
@validate()//only validates if add is a function (no parameter checking)add: (a: number,b: number)=>number;
@validate(true)// optionalname?: string;
@validate(false,string)// array element type must be passednames: string[];
@validate(false,number,true)// array elements may be unefined/nullsums: number[];}classPosition{
@validate()x: number;
@validate()y: number;}consta: A=validateData({count: 10,},A);

Uses emitDecoratorMetadata to provide Typescript type information at runtime

Caveats

  • limited type information
  • additional type data must be passed to @validate for some types.
    • optional types
    • arrays
    • unions
    • discriminated unions

Install

npminstallfresh-validation

Development

Build

yarn install
yarn build

Test

yarn test

Generate Documentation

yarn docs

About

typescript runtime type validation to keep your data fresh

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages