@byndyusoft/dto-factory
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

node-dto-factory

npm@latest test workflow code style: prettier semantic-release

Factory to generate various DTO for unit tests. Inspired by factory.ts.

Requirements

  • Node.js v12 LTS or later
  • npm or yarn

Install

npm install @byndyusoft/dto-factory

or

yarn add @byndyusoft/dto-factory

Usage

Example usage:

import { makeDtoFactory } from "@byndyusoft/dto-factory";
import { faker } from "@faker-js/faker";

class CharacterDto {
  public readonly id!: number;

  public readonly name!: string;
}

const characterDtoFactory = makeDtoFactory<CharacterDto>(() => ({
  id: faker.datatype.number(),
  name: faker.name.fullName(),
}));

// Build character without override
console.log(characterDtoFactory.build());

// Build character with override
console.log(
  characterDtoFactory.build({
    name: "Mage",
  }),
);

// Build characters without override
console.log(characterDtoFactory.buildList(10));

// Build characters with override
console.log(
  characterDtoFactory.buildList(10, {
    name: "Mage",
  }),
);

Maintainers

License

This repository is released under version 2.0 of the Apache License.

Readme

Keywords

none

Package Sidebar

Install

npm i @byndyusoft/dto-factory

Weekly Downloads

6

Version

1.0.2

License

Apache-2.0

Unpacked Size

38.4 kB

Total Files

49

Last publish

Collaborators

  • alexanderbyndyu
  • sadcitizen
  • dmitriy.litichevskiy
  • razonrus