npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

generathor

v2.0.1

Published

Generate files from templates and data sources automatically.

Downloads

422

Readme

⚡ Generathor

Generathor is a flexible and simple file generator. It automates the process of creating multiple files from a single data source, keeping your codebase standardized and preventing manual copy-paste errors.


🚀 Quick Start in 3 Steps

1. Install Generathor

Install it as a dev dependency in your project:

npm i -D generathor

2. Configure your Generators

Create a generathor.config.js file at the root of your project. This file tells Generathor where to get data (Sources) and how to generate files (Generators).

Generathor uses EJS (Embedded JavaScript) for templates.

const path = require('path');
const { ArraySource, GeneratorForItem, GeneratorForCollection } = require('generathor');

module.exports = {
  // 📥 Sources: Where your data comes from
  sources: {
    db: new ArraySource([
      { table: 'users', columns: ['id', 'name', 'email'] },
      { table: 'posts', columns: ['id', 'title', 'content'] },
    ]),
  },
  
  // 📤 Generators: How your files will be built
  generators: {
    // Generates ONE file combining all data from the source
    exportModels: new GeneratorForCollection({
      template: './templates/export.ejs',
      source: 'db',
      file: './output/index.js',
      overwriteFiles: true,
    }),
    
    // Generates MULTIPLE files (one per item in the source)
    models: new GeneratorForItem({
      template: path.resolve('./templates/model.ejs'),
      source: 'db',
      directory: path.resolve('./output'),
      fileName: (item) => `${item.table}.js`,
      overwriteFiles: true,
    }),
  },
};

3. Run the CLI

Execute Generathor from your terminal. It will automatically detect your config file and map the sources to your templates.

npx generathor

You can also run specific generators directly:

npx generathor -g "models exportModels"

🧩 Core Concepts

Generathor is built around two simple concepts:

1️⃣ Sources (ArraySource | CustomSource)

Sources act as the data provider. The built-in ArraySource takes a simple JSON array. Need to fetch data from an API or database? Just extend the base Source class!

import { Source } from 'generathor';

class CustomApiSource extends Source {
  public async load(): Promise<void> {
    const data = await fetch('https://api.example.com/data');
    this.itemsList = await data.json();
  }
}

2️⃣ Generators

Generators combine the data items from your source with your EJS templates to output files!

GeneratorForCollection

Takes all the data from the source and passes it as an array to your template. Perfect for generating index.ts export files or centralized registries.

| Option | Required | Description | |---|---|---| | template | ✅ Required | Path to the .ejs template file. | | source | ✅ Required | Name of the source key to pull data from. | | file | ✅ Required | Output file path for the generated file. | | overwriteFiles | ⬜ Optional | Whether to overwrite if the file already exists. Defaults to true. | | prepareItems | ⬜ Optional | Callback to transform the items before passing them to the template. |

GeneratorForItem

Iterates over every single item in your source and passes it individually to your template. Ideal for generating individual Models, Controllers, or Components.

| Option | Required | Description | |---|---|---| | template | ✅ Required | Path to the .ejs template file. | | source | ✅ Required | Name of the source key to pull data from. | | directory | ✅ Required | Output directory where files will be written. | | fileName | ✅ Required | Function that returns the file name for each item: (item) => string. | | overwriteFiles | ⬜ Optional | Whether to overwrite if the file already exists. Defaults to true. | | prepareItems | ⬜ Optional | Callback to transform the items before passing them to the template. |


✨ Other Features

Data Transformations (prepareItems)

You can transform data before it hits the template without modifying the original source using the prepareItems callback:

new GeneratorForItem({
  // ...
  prepareItems(items) {
    return items.map(item => ({
      ...item,
      // Create a capitalized class name for the template to use
      className: item.table.charAt(0).toUpperCase() + item.table.slice(1)
    }));
  }
});

🌍 Ecosystem

Explore related packages to power up your generathor workflows: