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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@computerwwwizards/di-code-generator

v0.2.0

Published

Code generator for @computerwwwizards/dependency-injection - generates TypeScript boilerplate for DI containers

Readme

DI Code Generator

A minimal, focused code generator written in Zig for creating TypeScript/JavaScript dependency injection boilerplate.

Overview

This project provides primitives for string interpolation and name manipulation - the foundational building blocks needed to generate DI registration files and related boilerplate code.

Features

String Interpolation

  • Parse template strings with {param} placeholders
  • Apply parameter values to generate final strings
  • Concatenate strings with customizable separators

Name Utilities

  • Case Conversions: Convert between different naming conventions
    • camelCase
    • PascalCase
    • snake_case
    • kebab-case
    • SCREAMING_SNAKE_CASE
  • Name Parameterization: Apply names to templates with automatic case conversion
  • Name Concatenation: Join multiple name parts with patterns

Building

# Build the project
zig build

# Run the example
zig build run

# Run all tests
zig build test

Testing

Tests are organized by concern:

  • interpolation tests: String template parsing and parameter application
  • name_utils tests: Case conversion and name manipulation
  • module tests: Integration tests
zig build test

Usage Example

const std = @import("std");
const di_gen = @import("di-code-generator");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    // Template interpolation with case conversion
    const result = try di_gen.name_utils.parameterizeName(
        allocator,
        "register{Name}",
        "user_service",
        .PascalCase,
    );
    defer allocator.free(result);
    // Result: "registerUserService"

    // Case conversions
    const snake = try di_gen.name_utils.toSnakeCase(allocator, "HelloWorld");
    defer allocator.free(snake);
    // Result: "hello_world"
}

Project Structure

zig/di-code-generator/
├── build.zig              # Build configuration
├── build.zig.zon          # Package metadata
├── src/
│   ├── root.zig           # Module exports
│   ├── main.zig           # CLI executable
│   ├── interpolation.zig  # String interpolation primitives
│   └── name_utils.zig     # Name manipulation utilities
└── README.md

API Reference

Interpolation Module (interpolation.zig)

InterpolationPart

Union type representing either literal text or a parameter placeholder.

parseTemplate(allocator, template) ![]InterpolationPart

Parse a template string into parts. Template format: "Hello {name}!"

applyParams(allocator, parts, params) ![]u8

Apply parameter values to interpolation parts.

concat(allocator, separator, strings) ![]u8

Concatenate multiple strings with a separator.

Name Utils Module (name_utils.zig)

Case Conversion Functions

  • toCamelCase(allocator, input) ![]u8
  • toPascalCase(allocator, input) ![]u8
  • toSnakeCase(allocator, input) ![]u8
  • toKebabCase(allocator, input) ![]u8

parameterizeName(allocator, pattern, name, case) ![]u8

Apply a name to a pattern with automatic case conversion.

  • pattern: Template string like "register{Name}"
  • name: The name to insert
  • case: Target naming convention

Design Decisions

Minimal Scope

This implementation focuses solely on the primitives needed for code generation:

  1. String interpolation - Building strings from templates
  2. Name manipulation - Converting and parameterizing names

These are the most fundamental operations required to generate any boilerplate code. Higher-level features (file generation, directory structure, etc.) can be built on top of these primitives.

No Dependencies

The project uses only Zig's standard library, making it lightweight and easy to integrate.

Test Organization

Tests are separated by concern into different executables, allowing focused testing and faster iteration during development.

License

See repository root for license information.

Related

This generator is designed to work with @computerwwizards/dependency-injection - a reflection-free IoC container for JavaScript/TypeScript.

NPM Package Usage

This tool is also available as an npm package: @computerwwwizards/di-code-generator

Installation

npm install @computerwwwizards/di-code-generator
# or
pnpm add @computerwwwizards/di-code-generator

CLI Usage

# Auto-discover config.json in current directory
npx di-code-gen

# Specify config file
npx di-code-gen --config ./services.config.json

# Override output directory  
npx di-code-gen --config ./config.json --output ./src/di

Quick CLI Generation (Auto-inferred Interface)

Generate a service directly via CLI without a config file. The interface name is automatically inferred from the service name (e.g., userServiceIUserService):

# Single service
npx di-code-gen --service userService --output ./src/di

# Multiple services
npx di-code-gen --service userService --service paymentGateway --output ./src/di

# Custom interface name (optional; defaults to I + PascalCase of service name)
npx di-code-gen --service userService:IUserAuthService --output ./src/di

# Combination: CLI services override config
npx di-code-gen --config config.json --service customService --output ./src/di

Auto-inference examples:

  • userServiceIUserService
  • paymentGatewayIPaymentGateway
  • auth_serviceIAuthService
  • DBConnectionIDbconnection

When --service is provided, CLI services take precedence over config file services.

Concrete Example (UserService)

  1. Create a config file di.config.json:
{
  "output": "./src/di",
  "services": [
    { "name": "userService", "interface": "IUserService" }
  ]
}
  1. Run the generator:
npx di-code-gen --config ./di.config.json
  1. Generated structure:
src/di/
  userService/
    types.ts
    registerUserService.ts
  1. types.ts (empty ServicesList with augmentation elsewhere):
import { PreProcessDependencyContainerWithUse } from '@computerwwwizards/dependency-injection'

export interface ServicesList {}
export type ContainerCtx = PreProcessDependencyContainerWithUse<ServicesList>
  1. registerUserService.ts includes IUserService, default register() stub, a mock() helper, and augments ServicesList:
export interface IUserService {}

export default function register(ctx: ContainerCtx) {
  // TODO: register real implementation
}

export function mock(ctx: ContainerCtx) {
  // TODO: register mock for tests
}

declare module './types' {
  interface ServicesList {
    userService: IUserService
  }
}

register.mock = mock

Programmatic API

ESM:

import { execute } from '@computerwwwizards/di-code-generator'

const exitCode = await execute([
  '--config', './my-config.json',
  '--output', './src/generated'
])

CommonJS:

const { execute } = require('@computerwwwizards/di-code-generator')

const exitCode = await execute(['--config', './config.json'])

Platform Support

Includes pre-compiled binaries for Linux, macOS, and Windows (x64, arm64).