forked from validatem/core
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
843 B
JavaScript
28 lines
843 B
JavaScript
"use strict";
|
|
|
|
const { validateArguments, RemainingArguments } = require(".");
|
|
const isString = require("@validatem/is-string");
|
|
const isBoolean = require("@validatem/is-boolean");
|
|
const isNumber = require("@validatem/is-number");
|
|
const required = require("@validatem/required");
|
|
const arrayOf = require("@validatem/array-of");
|
|
|
|
function testFunction(one, two, three, ... rest) {
|
|
validateArguments(arguments, {
|
|
one: [ required, isString ],
|
|
two: [ required, isNumber ],
|
|
three: [ required, isBoolean ],
|
|
[RemainingArguments]: [ required, arrayOf(isString) ],
|
|
});
|
|
}
|
|
|
|
testFunction("foo", "bar", null, "baz", 42);
|
|
|
|
/*
|
|
AggregrateValidationError: One or more validation errors occurred:
|
|
- At two: Must be a number
|
|
- At three: Required value is missing
|
|
- At array -> 1: Must be a string
|
|
- At mapping -> d -> (value): Must be a boolean
|
|
*/
|