- Uses Typescript Compiler
- Recursive validation during runtime
- Well Tested
- Many supported types
npm i -g @dollarshaveclub/runtype # Install globally or --save-dev
Command Line API
# Input: STDIN, Output: STDOUT$ echo 'type ID = string | number' | runtype >> ./output.js# Input: Disk, Output: STDOUT$ runtype -f './files/**/*.ts' >> ./output.js# Input: Disk, Output: Disk$ runtype -f './files/**/*.ts' -o ./output.js# Debugecho 'type ID = string | number' | runtype -d
const data =consolefs
Once you've transpiled your typescript, import it in your project to be compiled into your apps build.
The transpiled API allows you to validate your data with the types and interfaces defined in your typescript files. They are functions that will throw errors if the data provided is invalid.
interfaces: Product} from './output.js'// Throws an error// etc
Additional APIs are available to work with.
console // neat// true// ['ID value is invalid']// "number"// "array", etcaliases // throws an errorinterfacesinterfaces
The following features are supported by Runtype. Contributions are always welcome!