This is the main file where I have schema and values. I have validation-type which returns true if type is string ect. Then there is validation file where I should validate values with schema.
import * as ValidationTypes from './lib/validation-types'
import {validate} from "./lib/validation";
const schema = {
name: ValidationTypes.string,
age: ValidationTypes.number,
extra: ValidationTypes.any,
};
const values = {
name: "John",
age: "",
extra: false,
};
let result = validate(schema, values); //return array of invalid keys
console.log(result.length === 0 ? "valid" : "invalid keys: " + result.join(", "));
//invalid keys: age
validation-type
export function string(param) {
return typeof param === "string"
}
export function number(param) {
return typeof param === "number"
}
export function any(param) {
return true;
}
and this is validation.js
export function validate(schema, values) {
let invalidValues = []
}
And I am stuck, don't know how to continue with validate function.