https://github.com/damiancipolat/fish-type-js
Runtime validation of data types in functions call parameters and return in runtime for ES6.
https://github.com/damiancipolat/fish-type-js
dynamic es6 functions javascript nodejs npm react typecheck typechecker
Last synced: about 2 months ago
JSON representation
Runtime validation of data types in functions call parameters and return in runtime for ES6.
- Host: GitHub
- URL: https://github.com/damiancipolat/fish-type-js
- Owner: damiancipolat
- License: mit
- Created: 2019-04-12T06:23:05.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-30T04:21:35.000Z (about 7 years ago)
- Last Synced: 2025-04-06T14:43:43.385Z (about 1 year ago)
- Topics: dynamic, es6, functions, javascript, nodejs, npm, react, typecheck, typechecker
- Language: JavaScript
- Homepage:
- Size: 146 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Fish type JS
Data type validation in function calls on **Runtime** to be used in javascript projects.
[](https://david-dm.org/damiancipolat/Fish-type-JS)
[](https://github.com/damiancipolat/Fish-type-JS/blob/master/LICENSE)
[](https://github.com/damiancipolat/Fish-type-JShttps://github.com/damiancipolat/Fish-type-JS)
[](https://travis-ci.com/damiancipolat/Fish-type-JS)
**We have the new version 1.1.0 ready!**
In this version:
- Improve input function type semantic.
- Add typedef validation module.
## Objective:
Every JS programmer knows how annoying it is to work with static validators of data types. That's why I created this library, to help us and make sure that our function is always executed only with the types of data that we define for it.
## Type data validation:
This library uses joi https://github.com/hapijs/joi to handle the type validations, you can use custom primitives data as "string", "bool", "number" or more complex structure to validate if the parameters used to call a function match with the paramters that we define to allow it.
## Usage:
#### 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.
## Note:
This library is a work in progress project, I'm sure that will be very usefull for any JS developer, but take care that could be changes in the next versions. **We are working in create our custom structure validation engine to avoid use JOI**.
