UNPKG

ez-validation

Version:
32 lines (31 loc) 1.16 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.schemaValidation = function (values, schema, schemaValidationKey) { if (schemaValidationKey === void 0) { schemaValidationKey = null; } var tempSchema = schema; if (schemaValidationKey) { tempSchema = Object.keys(schema).reduce(function (prev, key) { var _a; return __assign({}, prev, (_a = {}, _a[key] = schema[key][schemaValidationKey], _a)); }, {}); } return Object.keys(tempSchema) .reduce(function (previous, key) { var obj = __assign({}, previous); if (tempSchema[key] && tempSchema[key](values[key])) { obj[key] = tempSchema[key](values[key]); } return obj; }, {}); };