faker-create-factory
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

faker-create-factory

🏭 Factory creator utility to Faker.js

Build Status NPM Uses TypeScript

Installing

yarn add faker faker-create-factory
 
# If you're using NPM: 
# npm install faker faker-create-factory 

Basic Usage

import { createFactory } from 'faker-create-factory';
 
export const UserFactory = createFactory<User>((faker) => ({
  id: faker.random.uuid(),
  email: faker.internet.email(),
  username: faker.internet.userName(),
  password: '123'
}));
 
// And the use it as:
UserFactory.generate(); // User
UserFactory.generateMany(5); // Array<User>

If needed, you can override the default schema:

import { createFactory } from 'faker-create-factory';
 
export const Factory = createFactory<Interface>((faker) => ({
  // ...
}));
 
// Plain object:
Factory.generate({
  // ...
});
 
// With a faker instance:
Factory.generateMany(5, (faker) => {
  // ...
});

The two options (plain object and with a faker instance) described above are available in both generate and generateMany methods.

Authors and License

lffg and contributors.

MIT License, see the included MIT file.

/faker-create-factory/

    Package Sidebar

    Install

    npm i faker-create-factory

    Weekly Downloads

    114

    Version

    1.3.0

    License

    MIT

    Unpacked Size

    7.14 kB

    Total Files

    9

    Last publish

    Collaborators

    • lffg