DEV Community

Soner Çökmen
Soner Çökmen

Posted on

Generating Customizable Mock Data with a Fluent Interface

I just published a mock data library for javascript fluentfixture.

Why we made this?

Generating mock data is hard, and customizing the fake data is more challenging. Libraries like Faker provide rich and realistic data but lack fluent interface and extensibility. In this project, we aim to provide programmability and extensibility.

An E-Commerce Scenario

Create ten products. Each product's barcode must be similar to ids. Sort the products by id.

import { alphabetic, int, obj, pick } from '@fluentfixture/core';

const price = obj({
  amount: int(1, 100),
  currency: pick(['USD', 'EUR', 'GBP', 'TRY']),

const product = obj({
  id: int(100, 999),
  name: alphabetic(10).capitalCase(),

const productWithBarcode = product
  .lazy('barcode', (p) => `##${}`);

const products = productWithBarcode
  .sort((p1, p2) => -;

Enter fullscreen mode Exit fullscreen mode


Thank you for feedback and contributions :)

Top comments (0)