@adocasts.com/dto
Version:
Easily make and generate DTOs from Lucid Models
17 lines (16 loc) • 577 B
JavaScript
export default class BaseDto {
/**
* Creates an array of DTO objects from an array of source objects.
*
* @template SourceObject - The type of the source objects.
* @template Dto - The type of the DTO objects.
* @param {StaticDto<SourceObject, Dto>} this - The static DTO class.
* @param {SourceObject[]} sources - The array of source objects.
* @return {Dto[]} An array of DTO objects.
*/
static fromArray(sources) {
if (!sources)
return [];
return sources.map((source) => new this(source));
}
}