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

tsc-template

v0.2.3

Published

Utility to build TypeScript AST from a string, similar to @babel/template

Readme

tsc-template

This project provides utilities to facilitate the creation and manipulation of TypeScript Abstract Syntax Trees (ASTs). The key utility is the ast function that works similarly to the @babel/template package but for TypeScript.

Installation

To install the project, run:

npm install tsc-template

Features

AST Generation

Easily create TypeScript ASTs from template strings.

The creation of TypeScript AST is not trivial and has nuances. To simplify that, you can use ast function that consumes a string and returns an AST for it.

import ast from 'tsc-template';
import { isSourceFile } from 'typescript';

const file = ast`const foo = [1, 2, 3]`;
assert(isSourceFile(file));
assertEqual(file.getText(), 'const foo = [1, 2, 3]');

Mix of String and AST Nodes

Use TypeScript nodes directly in the code as if they are simple strings.

When you work with massive TS generation, sometimes you need to use nodes created in one place, in another. With the plain TypeScript, you would need to create a TS transformer or create all the tree manually. However, with power of template literals, you can use the nodes directly in the code you provide to ast function.

import ast from 'tsc-template';
import { factory } from 'typescript';

const fooId = factory.createIdentifier('foo');
const file = ast`const ${fooId} = [1, 2, 3]`;

assertEqual(file.getText(), 'const foo = [1, 2, 3]');

Smart Result Injection

Inject the result of one ast function to another; no complex selectors required.

What if you have created a good chunk of the code using the ast function and want to inject it into another chunk? No problem: just use the result of one ast function as a part of another! The smart injection system will find the correct node, so you don't need to create complex selectors.

import ast from 'tsc-template';

const file = ast`const foo = ${ast`[1, 2, 3]`}`;

assertEqual(file.getText(), 'const foo = [1, 2, 3];');

Tags for Custom AST Extractions

Use extractor tags to select only a part of the code you need.

Sometimes, the code you can create via ast function is represented incorrectly in TypeScript AST. E.g., when you declare a function in the module root, it will be FunctionDeclaration while the function assigned to the variable is FunctionExpression. What to do?

It's simple. Use extractor tags! %{ and }% would allow you to select the correct part of the code you want to have as AST.

import ast from 'tsc-template';

const functionExpression = ast`const b = %{ function b() {} }%`;
const file = ast`const x = ${functionExpression}`;
assertEquals(file.getText(), 'const x = function b() {};');

License

This project is licensed under the Apache-2.0 License.