UNPKG

objectypes

Version:

A type-safe library to transform and validate objects

24 lines (23 loc) 768 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isTypeValid = void 0; function isTypeValid(target, propertyKey, value) { const propertyType = typeof value; const expectedType = Reflect.getMetadata('design:type', target, propertyKey).name.toLowerCase(); if (expectedType === 'date' && typeof value === 'string') { if (!isNaN(new Date(value).getTime())) { return; } } if (expectedType === 'number' && ['string', 'number'].includes(typeof value)) { if (!isNaN(Number(value))) { return; } } if (expectedType === propertyType) { return; } return { expectedType, propertyKey, propertyType }; } exports.isTypeValid = isTypeValid;