npm package: @megaorm/faker
Description: This package provides a set of methods to generate realistic, randomized data for your database seeding needs.
Author: Mohamed
Latest version: 1.0.0

## MegaORM Faker

This package provides a set of methods to generate realistic, randomized data for your database seeding needs. Whether you need user details, location information, or internet-related data, **@megaorm/faker** has you covered.

## Table of Contents

1. **[Installation](#installation)**
2. **[MegaFaker API](#megafaker-api)**
   - **[Personal Information](#personal-information)**
   - **[Location Information](#location-information)**
   - **[Text Generation](#text-generation)**
   - **[Professional Information](#professional-information)**
   - **[Product Information](#product-information)**
   - **[Web and Internet Data](#web-and-internet-data)**
   - **[Other Data](#other-data)**
   - **[Random Functions](#random-functions)**
3. **[Extending MegaFaker](#extending-megafaker)**
   - **[Custom Faker Function](#custom-faker-function)**
   - **[Extending MegaFaker Class](#extending-megafaker-class)**
   - **[Why Extend MegaFaker?](#why-extend-megafaker)**

## Installation

To install this package, run the following command:

```bash
npm install @megaorm/faker
```

## MegaFaker API

Import `MegaFaker` from `@megaorm/faker`:

```js
const { MegaFaker } = require('@megaorm/faker');
```

Create an Instance:

```js
const faker = new MegaFaker();
```

Now you are ready to generate some fake data!

### Personal Information

Generate realistic user details:

```js
console.log(faker.firstName()); // e.g., "john"
console.log(faker.lastName()); // e.g., "Doe"
console.log(faker.name()); // e.g., "john Doe"
console.log(faker.email()); // e.g., "johndoe123@example.com"
console.log(faker.gmail()); // e.g., "johndoe123@gmail.com"
console.log(faker.password()); // e.g., "p@ssw0rd123"
console.log(faker.username()); // e.g., "johndoe92"
```

### Location Information

Generate data for geographic and address fields:

```js
console.log(faker.continent()); // e.g., "Asia"
console.log(faker.country()); // e.g., "Canada"
console.log(faker.city()); // e.g., "San Francisco"
console.log(faker.street()); // e.g., "River Street"
console.log(faker.address()); // e.g., "1234 Maple St, Toronto, Canada"
```

### Text Generation

Generate filler text for your database:

```js
console.log(faker.sentence()); // e.g., "Random sentence."
console.log(faker.paragraph()); // e.g., "Random paragraph."
console.log(faker.text()); // e.g., "Random text."
console.log(faker.lorem()); // e.g., "Random lorem."
```

### Professional Information

Generate data for job-related fields:

```js
console.log(faker.job()); // e.g., "Software Engineer"
console.log(faker.company()); // e.g., "Global Solutions"
```

### Product Information

Simulate realistic product data:

```js
console.log(faker.product()); // e.g., "Pro Laptop"
console.log(faker.sku()); // e.g., "123-456-789"
console.log(faker.price()); // e.g., 45.67
console.log(faker.category()); // e.g., "Sport" (45 unique categories)
console.log(faker.card('#### #### #### ###')); // e.g., "1234 5678 9012 345"
```

### Web and Internet Data

Generate realistic web-related details:

```js
console.log(faker.path()); // e.g., "blog/introduction"
console.log(faker.domain()); // e.g., "example.com"
console.log(faker.url()); // e.g., "https://shop.net/products/pricing"
console.log(faker.ipv4()); // e.g., "192.168.1.1"
console.log(faker.ipv6()); // e.g., "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
```

### Other Data

Generate a variety of additional data types:

```js
console.log(faker.boolean()); // e.g., 1 | 0
console.log(faker.date()); // e.g., "2024-11-01"
console.log(faker.time()); // e.g., "14:30:00"
console.log(faker.datetime()); // e.g., "2024-11-01 14:30:00"
console.log(faker.zip()); // e.g., "90210"
console.log(faker.phone('+1 (###) ###-####')); // e.g., "+1 (123) 612-3456"
console.log(faker.id(100)); // e.g., 13 (number between 0 and 100)
```

### Random Functions

The `MegaFaker` library includes helper functions for custom randomization:

```js
const {
  randomBetween, // Generate a random number in a range
  randomIndex, // Get a random index from an array
  randomSelect, // Select a random item from an array
  randomChar, // Generate a random character
} = require('@megaorm/faker');

console.log(randomBetween(0, 10)); // e.g., 3
console.log(randomIndex(['john', 'Doe'])); // e.g., 0
console.log(randomSelect(['john', 'Doe'])); // e.g., 'john'
console.log(randomChar()); // e.g., 'A'
```

## Extending MegaFaker

You can create custom faker methods and extend the functionality of `MegaFaker`. Here’s how you can do it:

### Custom Faker Function

Leverage the provided random functions to define your own data generators. For example, create a function to generate random TV shows:

```js
export function tvShow() {
  return randomSelect([
    'Breaking Bad',
    'Friends',
    'Game of Thrones',
    'Stranger Things',
  ]);
}

console.log('TV Show:', tvShow()); // e.g., "Friends"
```

### Extending MegaFaker Class

For more advanced use cases, extend the `MegaFaker` class to incorporate additional functionality directly into the faker instance.

```js
const { MegaFaker } = require('@megaorm/faker');

class BetaFaker extends MegaFaker {
  // Generate a random tv show
  tvShow() {
    return this.random.select([
      'The Office',
      'Parks and Recreation',
      'The Crown',
      'Black Mirror',
    ]);
  }

  // Generate a random 5 stars rating
  rating() {
    const left = this.random.between(1, 4); // 4
    const right = this.random.between(0, 9); // 5
    return Number(`${left}.${right}`); // 4.5
  }
}

module.exports = { BetaFaker };
```

Once extended, you can import your custom faker class, create an instance, and use the enhanced methods in your seeder files:

```js
// Import `BetaFaker`
const { BetaFaker } = require('./BetaFaker');

// Create instance
const faker = new BetaFaker();

console.log(faker.tvShow()); // e.g., "The Crown"
console.log(faker.rating()); // e.g., 4.9
```

### Why Extend MegaFaker?

- Add domain-specific faker methods.
- Maintain reusability by centralizing custom randomization logic.
- Enhance the default API for niche use cases, improving productivity.

The **MegaFaker** API is your ultimate tool for generating realistic and diverse mock data. Let your creativity flow and streamline your database seeding!