JSPM

  • Created
  • Published
  • Downloads 79
  • Score
    100M100P100Q58606F
  • License MIT

data generator

Package Exports

  • super-maker

Readme

Discord MIT License

superMaker

Data generator designed specifically for turboMaker. Uses Fisher-Yates shuffle.
It allows you to generate random texts, hashtags, words, full names, emails, url links, and much more.

Ideal for

  • Populating databases and creating fake content (posts, users, products, etc.)
  • Rapid prototyping

Features

  1. Ability to create a fully custom data storage to be used during generation.
  2. Uses Uses Fisher-Yates shuffle - a reliable shuffling algorithm.
  3. Text generation with hashtags.
  4. Automatic hashtag extraction.
  5. Generation of unique email, ID, etc., using randomBytes().
  6. Generation of random links (for example, for displaying images).
  7. Work with arrays and objects.

Installation & Usage

  1. Install the package:
npm i super-maker
  1. In the root of the project, create a file super-maker-storage.json.

Fill it with data, for example:

{
  "words": [
    "zorvian",
    "velthara",
    "quarnex"
  ],
  "hashtags": [
    "#Mercury",
    "#Venus",
    "#Moon"
  ],
  "fullName": [
    "James Smith",
    "John Johnson",
    "Robert Brown"
  ],
  "fullNames": {
    "name": [
      "James",
      "Emily",
      "Michael"
    ],
    "surname": [
      "Smith",
      "Johnson",
      "Williams"
    ]
  },
  "images": {
    "avatar": [
      "https://raw.githubusercontent.com/AndrewShedov/superMaker/refs/heads/main/storage/images/1.webp",
      "https://raw.githubusercontent.com/AndrewShedov/superMaker/refs/heads/main/storage/images/2.webp"
    ],
    "banner": [
      "https://raw.githubusercontent.com/AndrewShedov/superMaker/refs/heads/main/storage/images/1.webp",
      "https://raw.githubusercontent.com/AndrewShedov/superMaker/refs/heads/main/storage/images/2.webp"
    ]
  },
  "users": [
    "683a6251661f8f39765a75cc",
    "683a6220c57fe3aba56e3745",
    "683a622042fd1cb967541fb5",
    "683a62208355f4708ed7ed81"
  ]
}
  1. Generate data in turboMaker.

Example: posts generation:

import { superMaker } from 'super-maker';
import { ObjectId } from 'mongodb';

export const config = {
    uri: 'mongodb://127.0.0.1:27017',
    db: 'crystalTest',
    collection: 'posts',
    numberThreads: 'max',
    numberDocuments: 1_000_000,
    batchSize: 10_000,
    timeStepMs: 20
};

export async function generatingData({
    createdAt,
    updatedAt
}) {

    const user = superMaker.take.value({
        key: 'users'
    });

    const {
        title,
        text,
        hashtagsFromFullText
    } = superMaker.lorem.fullText.generate({

        titleOptions: {
            sentenceMin: 0,
            sentenceMax: 1,
            wordMin: 4,
            wordMax: 7,
            hashtagMin: 0,
            hashtagMax: 1
        },

        textOptions: {
            sentenceMin: 1,
            sentenceMax: 12,
            wordMin: 4,
            wordMax: 10,
            hashtagMin: 0,
            hashtagMax: 2
        }
    });

    return {

        title,
        text,
        hashtags: hashtagsFromFullText,

        views: superMaker.randomNumber({
            min: 120,
            max: 3125
        }),

        mainImage: superMaker.take.value({
            key: 'images.avatar'
        }),

        liked: superMaker.take.values({
            key: 'users',
            min: 3,
            max: 25
        }),

        user: new ObjectId(user),
        createdAt,
        updatedAt
    };
}

Examples of generations

Available methods

lorem: {
    words,
    sentences,
    fullText
  },

words

Takes words from the storage and outputs them in random order, uses - Fisher-Yates shuffle.

sentences

Takes words from the storage and turns them into sentences with or without hashtags and outputs them in random order, uses - Fisher-Yates shuffle.

fullText

Takes words from the storage and turns them into sentences with or without hashtags and outputs them randomly, uses - Fisher-Yates shuffle. You can split the sentence into parts: title, text, hashtagsFromFullText and output each part in a separate document field.

take: {
   value,
   values
 },

value

Returns a single value from storage, by key.

values

Outputs an array of values from storage, by key.

randomNumber,
randomDate,
randomBoolean,
randomCrypto,
randomEmailCrypto

randomNumber

Outputs a random number.

randomDate

Outputs a random date. Time format - 24 hour.

randomBoolean

Outputs a random boolean.

randomCrypto

Outputs generated cryptographically strong pseudo-random data with the given length. Uses - randomBytes().

randomEmailCrypto

Outputs generated cryptographically strong pseudo-random data with a given length and frames it in '....@gmail.com'. Uses - randomBytes().

Full description of methods

The video shows a simulation of CRYSTAL v2.0 in operation, using fake data generated with turboMaker and superMaker:

CRYSTAL v1.0 features

SHEDOV.TOP | CRYSTAL | Discord | Telegram | X | VK | VK Video | YouTube