Runtime dynamic type validation in function calls.
npm install fish-type-js
Data type validation in function calls on Runtime to be used in javascript projects.




We have the new version 1.1.0 ready!
In this version:
- Improve input function type semantic.
- Add typedef validation module.
#### Install:
Run this command to install the library from npm.
``sh`
npm install fish-type-js
#### Library:
The library export two things, a decorate function that have to be use for decorate a single function and add a automatic call parameters validation, and a list of primitive data types.
Decorate function - format
`javascript
const {decorate} = require('fish-type-js');
//I will get the function output.
const sumT = decorate({input},output)(sum);
`
Define input and output:
You can specify the types of the parameters that the function receive and the return data of the function.
`javascript
const newFunction = decorate({input},output)(Function);
`
IN: paramters structure / OUT: type function return
Type parameters:
You can use this type parameters in each parameter key.
* undefined
* string
* null
* boolean
* number
* object
* promise
Or create more complex object schema and mix the function call with a joi schema validation, is important
to remember include JOI module to use his data types schema.
`javascript
const Joi = require('joi');
//Include primitives types.
const pointType = Joi.object().keys({
lat: Joi.number(),
lng: Joi.number()
});
const findGeoT = decorate({point:pointType})(findGeo);
findGeoT({lat:1.111,lng:3.01});
`
#### Examples:
Try this basic example of how to use the library.
`javascript
//Include lib and types.
const {decorate} = require('fish-type-js');
//Basic function.
const sum = (a,b)=>{
return a+b;
}
//Decorate the function.
const sumT = decorate({a:'number',b:'number'},'number')(sum);
sumT(10,10);
``
If you want more examples, go and download the project and go to /samples folder and chek the examples.