data-transfer-object
Advanced tools
| import { ValidationError, ValidatorOptions } from 'class-validator'; | ||
| export * from 'class-validator'; | ||
| declare type NonFunctionPropertyNames<T> = { | ||
| [K in keyof T]: T[K] extends Function ? never : K; | ||
| }[keyof T]; | ||
| /** Extract the data properties out of a Data Transfer Object. */ | ||
| export declare type Data<T extends DataTransferObject> = { | ||
| [K in keyof T]: T[K] extends Function ? never : T[K]; | ||
| }; | ||
| export declare type Data<T> = Pick<T, NonFunctionPropertyNames<T>>; | ||
| /** Cached validation errors from previous validation. */ | ||
@@ -8,0 +9,0 @@ declare const validationErrors: unique symbol; |
@@ -81,3 +81,3 @@ "use strict"; | ||
| toJSON() { | ||
| return Object.fromEntries(Object.entries(this).filter(([key, val]) => !key.startsWith('_') && typeof val !== 'function')); | ||
| return Object.fromEntries(Object.entries(this).filter(([_key, val]) => typeof val !== 'function')); | ||
| } | ||
@@ -84,0 +84,0 @@ } |
| import { ValidationError, ValidatorOptions } from 'class-validator'; | ||
| export * from 'class-validator'; | ||
| declare type NonFunctionPropertyNames<T> = { | ||
| [K in keyof T]: T[K] extends Function ? never : K; | ||
| }[keyof T]; | ||
| /** Extract the data properties out of a Data Transfer Object. */ | ||
| export declare type Data<T extends DataTransferObject> = { | ||
| [K in keyof T]: T[K] extends Function ? never : T[K]; | ||
| }; | ||
| export declare type Data<T> = Pick<T, NonFunctionPropertyNames<T>>; | ||
| /** Cached validation errors from previous validation. */ | ||
@@ -8,0 +9,0 @@ declare const validationErrors: unique symbol; |
@@ -68,5 +68,5 @@ var _a, _b; | ||
| toJSON() { | ||
| return Object.fromEntries(Object.entries(this).filter(([key, val]) => !key.startsWith('_') && typeof val !== 'function')); | ||
| return Object.fromEntries(Object.entries(this).filter(([_key, val]) => typeof val !== 'function')); | ||
| } | ||
| } | ||
| _a = validationErrors, _b = validated; |
+1
-1
| { | ||
| "name": "data-transfer-object", | ||
| "version": "0.2.1", | ||
| "version": "0.3.0", | ||
| "description": "Data Transfer Object class built on `class-validator`.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
| import { validate, validateSync, ValidationError, ValidatorOptions } from 'class-validator'; | ||
| export * from 'class-validator'; | ||
| /** Extract the data properties out of a Data Transfer Object. */ | ||
| export type Data<T extends DataTransferObject> = { | ||
| // Simple conditional mapping turns function types into `never` types | ||
| // In order to skip them entirely, we use the following: | ||
| // https://stackoverflow.com/a/55483981/3247259 | ||
| type NonFunctionPropertyNames<T> = { | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| [K in keyof T]: T[K] extends Function ? never : T[K]; | ||
| }; | ||
| [K in keyof T]: T[K] extends Function ? never : K; | ||
| }[keyof T]; | ||
| /** Extract the data properties out of a Data Transfer Object. */ | ||
| export type Data<T> = Pick<T, NonFunctionPropertyNames<T>>; | ||
| const defaultOpts: ValidatorOptions = { | ||
@@ -84,5 +90,5 @@ whitelist: true, | ||
| return Object.fromEntries( | ||
| Object.entries(this).filter(([key, val]) => !key.startsWith('_') && typeof val !== 'function'), | ||
| Object.entries(this).filter(([_key, val]) => typeof val !== 'function'), | ||
| ) as Data<this>; | ||
| } | ||
| } |
22924
1.25%348
1.75%