TypeCzech

TypeCzech is a detachable runtime type checking JavaScript library that can be toggled on and off. Include one file in your web page or in your Node.js file to allow you to type check function parameters and results. Errors can be set to throw exceptions or just output to the Console. The motivation is to verify function parameters before execution, and function results after completion with PRE_check() and POST_check() funtions.

The shortest possible example on a live JSFiddle.

GitHub

TypeCzech project with tests

Local TypeCzech Tutorial

00-Readme-Example - Realistic example of verifying types and checking emptiness
01-What-is-TypeCzech - Check function parameters before task, and function results after execution
02-Validate-Parameters-by-Value - Verify function parameters by checking values with regular expressions, set membership, or array size
03-Turn-Off-Library-Not-Loaded - Turn off TypeCzech by not loading TypeCzech.js
04-Turn-Off-No-Check-Functions - Turn off TypeCzech by not loading checking functions
05-Verify-Return-Results-by-Value - Verify function results by checking return value with regular expressions, set membership, or array size
06-Validate-Parameters-and-Results - Example of verifying parameters by set membership, and checking function results via a regular expression
07-Mutated-Function-Parameters - Ensure function parameters are not accidentally altered in a function call
08-Mutated-Recursive-Function-Parameters - Certify function parameters are not unintentionally modified in a stack of recursive function calls
09-Closure-Parameters-Results-and-Methods - Check parameters and results in closures with numerous functions
10-Class-Parameters-Results-and-Methods - Verify parameters and results in classes with mutliple methods
11-Object-Properties - Check scalar, array, object parameters and results with checkParam_type(), as well as the creation of Closures and IIFEs
12-Object-Interface - Verify creation of Classes, ClassFrees, Prototypes, and OLOOs via check_interface()
13-Parameter-and-Results-Multi-Types - Checking functions with multiple parameters and returned array results
14-Array-and-Object-Types - Typeless arrays, objects without specified keys, typed arrays, and objects with keys
15-Lone-Single-Type-Parameter-Functions - Single parameters versus multiple parameters
16-Arrays-with-One-Type - Arrays with one type, but multiple elements
17-Variadic-Functions - Checking variadic functions with one type of parameter, but multiple parameters
18-Class-Type-Checks - Use both check_interface() and checkParam_type() on classes
19-Lone-Empty-Param-and-Result - Check for single parameters which are empty strings, arrays with no elements, and objects without properties
20-Multiple-Empty-Params-and-Results - Check numerous parameters for emptiness which are OK, ignored, or an error
21-Type-Check-with-Extra-Optional-Params - Ignore types of extra array elements and object properties in single parameters and results
22-Empty-Checks-with-Extra-Optional-Params - Ignore empty array elements and object properties in single parameters and results
23-Typed-Either-Checks - Allow multiple different parameter type signatures and function return signatures
24-Empty-Either-Checks - Allow multiple different empty parameter and return signatures
25-Default-Parameters - Parameters
26-Type-and-Empty-Abbreviations - Emptiness and type abbreviations
27-Type-and-Empty-Object-Extras - Types and emptiness together with extra parameters
28-Accept-Null-and-Undefined-Values - Accept nulls and undefineds as valid parameters
29-Class-Object-Type-Checks - Class type checks
30-HTML-Type-Checks - HTML type checks
31-Extended-Class-Type-Checks - Extended classes with type checks on creation and methods
32-Extended-Closure-Type-Checks-check - Extended closures with type checks on creation and functions
33-Count-Checks - Console count of checks
34-Parameter-Check-Events - Checking failure events, change tab contents or screen color on test execution
35-Throw-or-Log - Throw exceptions, console log, or ignore checking errors
36-Start-and-Stop - Turn checking on and off programmatically
37-Readme-Example-Arrow-Functions - Difference between arrow and ordinary functions
38-Every-Check - Example of every checking function in TypeCzech
39-Assert-Checks - Check return values of functions outside of the program
40-Prescribed-Use - Best practices
41-Lens-Example - Lens Example
42-Extended-Objects - Extended Object Types
43-PHP-On-OFF-Extending-Classes - PHP On Off Extending Classes

101-Extending-Classes-Inline - Extended classes and checks in one inlined file
102-Extending-Classes-Imports - Extended classes and checks all imported
103-Extending-Classes-Production - Extended classes inlined with imported checks when testing
201-Extending-Closures-Inline - Closure modules and checks in one inlined file
202-Extending-Closures-Imports - Closure modules and checks all imported
203-Extending-Closures-Production - Closure modules inlined with imported checks when testing
204-Extending-Closures-Single - Closure checks in one imported file when testing
301-Extending-IIFEs-Inline - IIFE modules and checks in one inlined file
302-Extending-IIFEs-Imports - IIFE modules and checks all imported
303-Extending-IIFEs-Production - IIFE modules inlined with imported checks when testing
304-Extending-IIFEs-Single - IIFE checks in one imported file when testing
401-Extending-ClassFree-Inline - ClassFree constructors and checks in one inlined file
402-Extending-ClassFree-Imports - ClassFree constructors and checks all imported
403-Extending-ClassFree-Production - ClassFree constructors inlined with imported checks when testing
404-Extending-ClassFree-Single - ClassFree constructors checks in one imported file when testing
501-Extending-Prototypes-Inline - Inherited prototypes and checks in one inlined file
502-Extending-Prototypes-Imports - Inherited prototypes and checks all imported
503-Extending-Prototypes-Production - Inherited prototypes inlined with imported checks when testing
504-Extending-Prototypes-Single - Inherited prototype checks in one imported file when testing
601-Extending-OLOO-Inline - Created OLOO and checks in one inlined file
602-Extending-OLOO-Imports - Created OLOO and checks all imported
603-Extending-OLOO-Production - Created OLOO inlined with imported checks when testing
604-Extending-OLOO-Single - Created OLOO checks in one imported file when testing

700-Simple-Example - Simple example
701-Array-of-Objects - Check arrays of objects
702-DeClassify - Strip methods from an object leaving a plain object
703-Async-Await - Check return types inside an await function
704-Ramda-Curry - Set up type checking with curried functions
705-Sensible-Switching - Sensible way to set up the toggling of type checking
706-Elegant-On-Off - Only load type checking code if type checking is enabled by async loading
707-React-JSX - Type check parameters and results of React JSX components
708-Monad-Type-Checking - Type check monad parameters
709-Generators - Type iterator parameters
710-One-Check-Function - One type check function serving 10 functions

© 2024 Steen Hansen