@vitrical/utils
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -53,4 +53,4 @@ import { Request, Response, NextFunction } from 'express' | ||
} else { | ||
next(`Errors present in the request body:\n${errors.reduce((a, b) => ` ${a}\n ${b}`)}`) | ||
next(`Errors present in the request body:\n ${errors.reduce((a, b) => `${a}\n ${b}`)}`) | ||
} | ||
} |
{ | ||
"name": "@vitrical/utils", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Collection of useful functions and typings", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -12,3 +12,3 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports.validateObject = exports.isValidationType = exports.getSeason = exports.capitalize = exports.isValidNAPhoneNumber = exports.formatPhoneNumber = exports.isValidEmail = exports.removeSpaces = exports.removeSpecialCharacters = exports.isApiError = exports.objectHasProperty = void 0; | ||
exports.objectMatchesSchema = exports.validateObject = exports.isValidationType = exports.getSeason = exports.capitalize = exports.isValidNAPhoneNumber = exports.formatPhoneNumber = exports.isValidEmail = exports.removeSpaces = exports.removeSpecialCharacters = exports.isApiError = exports.objectHasProperty = void 0; | ||
var objectHasProperty = function (obj, property) { | ||
@@ -200,2 +200,10 @@ return !!obj && typeof obj === 'object' && property in obj; | ||
exports.validateObject = validateObject; | ||
function objectMatchesSchema(schema, data) { | ||
var errors = validateObject(schema, data); | ||
if (errors.length !== 0) { | ||
throw new Error("Object does not match what is expected\n ".concat(errors.reduce(function (a, b) { return "".concat(a, "\n ").concat(b); }))); | ||
} | ||
return true; | ||
} | ||
exports.objectMatchesSchema = objectMatchesSchema; | ||
//# sourceMappingURL=validation.js.map |
@@ -244,1 +244,11 @@ export const objectHasProperty = ( | ||
} | ||
export function objectMatchesSchema<T>(schema: ValidateObjectOptions, data: unknown): data is T { | ||
const errors = validateObject(schema, data) | ||
if (errors.length !== 0) { | ||
throw new Error( | ||
`Object does not match what is expected\n ${errors.reduce((a, b) => `${a}\n ${b}`)}` | ||
) | ||
} | ||
return true | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47499
876