https://github.com/Byndyusoft/node-dto-factory
Factory to generate various DTO for unit tests
https://github.com/Byndyusoft/node-dto-factory
dto factory nodejs typescript
Last synced: 5 months ago
JSON representation
Factory to generate various DTO for unit tests
- Host: GitHub
- URL: https://github.com/Byndyusoft/node-dto-factory
- Owner: Byndyusoft
- License: apache-2.0
- Created: 2021-12-04T07:20:37.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-12T12:28:20.000Z (over 1 year ago)
- Last Synced: 2024-10-07T16:34:32.310Z (7 months ago)
- Topics: dto, factory, nodejs, typescript
- Language: TypeScript
- Homepage:
- Size: 336 KB
- Stars: 1
- Watchers: 11
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-dto-factory
[](https://www.npmjs.com/package/@byndyusoft/dto-factory)
[](https://github.com/Byndyusoft/node-dto-factory/actions/workflows/test.yaml)
[](https://github.com/prettier/prettier)
[](https://github.com/semantic-release/semantic-release)Factory to generate various DTO for unit tests.
Inspired by [factory.ts](https://github.com/willryan/factory.ts).## Requirements
- Node.js v12 LTS or later
- npm or yarn## Install
```bash
npm install @byndyusoft/dto-factory
```or
```bash
yarn add @byndyusoft/dto-factory
```## Usage
Example usage:
```typescript
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(() => ({
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
- [@Byndyusoft/owners](https://github.com/orgs/Byndyusoft/teams/owners) <>
- [@Byndyusoft/team](https://github.com/orgs/Byndyusoft/teams/team)
- [@KillWolfVlad](https://github.com/KillWolfVlad)## License
This repository is released under version 2.0 of the
[Apache License](https://www.apache.org/licenses/LICENSE-2.0).