1.0.0 • Published 5 years ago
funcvalidator v1.0.0
funcvalidator.js
Function validator
Install
Client
<script type="text/javascript" src="funcvalidator.js"></script>
Server
npm i funcvalidator
Usage
Displace
function someFunction(a, b, c) {
[ a, b, c ] = displace([ a, b, c ], [ 'number', 'string/number', 'array' ]);
// Function code here...
}
someFunction(1900, 'hello', [ 1, 2, 3]); // => (1900, 'hello', [ 1, 2, 3])
someFunction(1900, 1901, [ 1, 2, 3]); // => (1900, 1901, [ 1, 2, 3])
someFunction(1900); // => (1900, undefined, undefined)
someFunction(1900, [ 1, 2, 3]); // => (1900, undefined, [ 1, 2, 3])
Right
function someFunction(a, b, c) {
right({ a }, 'number');
right({ b }, 'string/number/object');
right({ c }, 'array/void'); // void equals null or undefined
// Function code here...
}
someFunction(1900, 'hello', [ 1, 2, 3]); // => OK
someFunction(1900, 1901); // => OK
someFunction(1900, 'hello', 'world'); // => ERROR
someFunction(1900); // => ERROR
Types
- array = default
- function = equals function or arrow function
- date = object of Date
- string = default
- number = default
- element = object of jQuery or HTMLElement
- object = default
- boolean = default
- void = equals null or undefined
1.0.0
5 years ago