# proposal-factory-decorator

> This module was made to decorate fields to furder create a Factory for that class.

Latest version **1.0.0** (published 2021-04-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install proposal-factory-decorator
pnpm add proposal-factory-decorator
yarn add proposal-factory-decorator
bun add proposal-factory-decorator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-04-08 |
| First published | 2021-04-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | David Alen |
| Maintainers | alendavid |
| Keywords | Factory, Decorators, Classes, Typescript |

## Links

- npm: https://www.npmjs.com/package/proposal-factory-decorator
- Repository: https://github.com/AlenDavid/proposal-factory-decorator
- Issues: https://github.com/AlenDavid/proposal-factory-decorator/issues
- Funding: https://www.patreon.com/davidalen
- npm.io page: https://npm.io/package/proposal-factory-decorator

## Dependencies (2)

- [ts-node](https://npm.io/package/ts-node.md) ^9.1.1
- [typescript](https://npm.io/package/typescript.md) ^4.2.4

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2021-04-08
- 0.2.9 — 2021-04-08
- 0.2.8 — 2021-04-08
- 0.2.7 — 2021-04-08
- 0.2.6 — 2021-04-08
- 0.2.5 — 2021-04-08
- 0.2.4 — 2021-04-08
- 0.2.3 — 2021-04-08
- 0.2.2 — 2021-04-08
- 0.2.1 — 2021-04-08
- 0.2.0 — 2021-04-08

## README

# Class Factory Decorators

This package is aimed to testing and seeding at your projects. It's easy to implement and create your own class factory.

- [Class Factory Decorators](#class-factory-decorators)
  - [Install through cli via command](#install-through-cli-via-command)
  - [Example code](#example-code)
  - [Recommends](#recommends)
  - [Caution](#caution)

## Install through cli via command

You might want to use this quick cli command to install the package.

```bash
npm i --save proposal-factory-decorator
```

## Example code

In this example, we can see how the @Factory decorator works. It's quite simple and easy to duplicate.

```ts
import { Factory, CreateFactory } from "proposal-factory-decorator";

class User {
  @Factory(() => "name")
  field: string;

  @Factory(() => false)
  isTrue: boolean;
}

const userFact = new CreateFactory() < User > User;

(async () => {
  const user = await userFact.generate(); // Creates an User

  console.log(user); // { field: "name", isTrue: false }
})();
```

## Recommends

It's highly recommended to use faker package. The faker package provides useful evaluations to our @Factory method.

```bash
npm i --save faker @types/faker
```

One simple example (extending the example above) to use faker lib

```ts
import { Factory, CreateFactory } from "proposal-factory-decorator";
import faker from "faker";

class User {
  @Factory(() => faker.name.findName())
  name: string;

  @Factory(() => faker.internet.email())
  email: boolean;
}

const userFact = new CreateFactory() < User > User;

(async () => {
  const user = await userFact.generate(); // Creates a faker User

  console.log(user); // { name: "Some random name", email: "some@random.email" }
})();
```

## Caution

The @Factory decorator only works with the CreateFactory class.
If you try to do something like

```ts
class DontWork {
  @Factory(() => somevalue)
  field: any;
}

console.log(new DontWork()); // it will print this empty value {}
```

If you want to support me, go check my [Patreon](https://www.patreon.com/davidalen)!

Happy coding you all 🖥️🙇!

---
_Source: https://npm.io/package/proposal-factory-decorator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
