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

typescript-to-vba

v1.0.1

Published

Professional TypeScript to VBA transpiler for Excel/Office automation

Readme

TypeScript to VBA (TSTVBA)

Transpile modern TypeScript into VBA modules (.bas + .cls) for Excel/Office automation.

Installation

npm install -g typescript-to-vba

Quick start

tstvba --init
tstvba check -p .
tstvba -p .

Local development usage (without global install):

npm install
npm run build
node dist/cli.js --init
node dist/cli.js check -p .
node dist/cli.js -p .

Generated VBA output: dist/vba/MyProject.bas

Build now also generates a bundle manifest: dist/vba/tstvba-manifest.json.

Config model

tstvbaOptions are stored directly inside tsconfig.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "CommonJS",
    "strict": true,
    "outDir": "dist/vba"
  },
  "tstvbaOptions": {
    "entry": "example/main.ts",
    "targetApplication": "Excel",
    "moduleStyle": "StandardModule",
    "vbaLibraryPath": "./lib/vbalib.bas",
    "namespacePrefix": "TS_",
    "emitSourceMaps": true,
    "bundle": true,
    "outputFileName": "MyProject.bas"
  }
}

Commands

  • node dist/cli.js -p . — build using project directory (tsconfig.json or tsconfig.tstvba.json)
  • node dist/cli.js --watch -p . — watch mode
  • node dist/cli.js --init — create tsconfig.tstvba.json + lib/vbalib.bas stub
  • node dist/cli.js check -p . — validate and print resolved config

Namespacing strategy (VBA global scope)

Template now uses Static Prefixing for exported function declarations:

  • TS: export function init() in main.ts
  • VBA: Public Sub TS_main_init()

Formula: <namespacePrefix><moduleName>_<functionName>

This avoids collisions between modules with identical function names.

Object bridge: Class Module Mirroring

Current template includes first implementation of TS class -> VBA .cls generation:

  • each top-level class generates a dedicated .cls file in output directory;
  • generated class name uses namespacing pattern (<namespacePrefix><moduleName>_<ClassName>);
  • constructor is mapped to Public Sub Init(...);
  • class fields become Private m_<field> + Property Get/Let accessors;
  • methods are emitted as Public Sub/Public Function stubs.

Import note for .cls files

Class module files contain metadata header (VERSION/BEGIN/END + Attribute ...) and must be imported via VBE -> File -> Import File....

  • If you copy/paste manually into a class code window, do not paste header lines above Option Explicit.
  • Use generated .cls files from dist/vba directly for reliable class properties (MultiUse, VB_Name, etc.).

Error handling bridge: Try/Catch -> On Error

Template now includes first pass of exception mapping:

  • try/catch/finally is emitted using unique label blocks (TS_CATCH_n, TS_FINALLY_n, TS_ENDTRY_n);
  • throw is mapped to Err.Raise vbObjectError + 513, "TSTVBA", ...;
  • runtime auto-injects error.stack helpers (TS_PushError, TS_LastErrorMessage, TS_ClearError) when try/throw is detected.

Iteration bridge: For...Of

Template now includes first pass of advanced iteration mapping:

  • for...of emits hybrid VBA loop strategy:
    • arrays: For i = LBound(...) To UBound(...);
    • non-array collections: For Each item In collection;
  • runtime auto-injects iterator.protocol helper TS_HasArrayBounds when ForOfStatement is detected.

Packaging strategy (Production bundle)

Current build pipeline includes packaging polish:

  • dist/vba is cleaned before each transpile run;
  • generated .bas file gets metadata header:
    • DO NOT EDIT - GENERATED CODE
    • compiler version
    • build timestamp
    • project path
  • build writes tstvba-manifest.json with runtime features and all generated output files.

Project structure

  • src/cli.ts — CLI entrypoint
  • src/config.ts — tsconfig + tstvbaOptions loader
  • src/transpile.ts — transpilation pipeline template
  • src/emitter/vbaEmitter.ts — basic AST emitter skeleton