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

ts-expressions

v0.0.8

Published

A TypeScript transformer to convert TypeScript expressions into equivalent expression trees

Readme

ts-expressions [WORK IN PROGRESS]

A TypeScript transformer to convert TypeScript expressions into equivalent expression trees

Description

ts-expressions is a TypeScript transformer that helps you get information about an expression at run-time by creating an object structure representing that expression at compile-time.

How to install

npm i ts-expressions

How does it work

The transformer provided by ts-expressions will analyze TypeScript code and look for calls to functions that contain an overload which declares parameters of type Expression. If the function call being analyzed is passing arguments of types other than Expression, those arguments are converted to expressions during the compilation of the program.

You will need to use a custom TypeScript compiler to make use of the ts-expressions transformer. You can use ttypescript to compile your program using the following configuration in ts.config:

{
  "compilerOptions": {
    "plugins": [
      { "transform": "ts-expressions" }
    ]
  },
}

If you're feeling adventurous you can also create your own TypeScript compiler:

import * as ts from 'typescript';
import transformer from 'ts-expressions';

const sources = [
  //your source files
];
const compilerOptions = {
  //your options
};
const program = ts.createProgram(sources, compilerOptions);

const result = program.emit(undefined, undefined, undefined, false, {
  before: [ transformer(program) ],
});

It is currently not supported to use the out-of-the-box TypeScript compiler tsc with this plug-in. You can show some love here if you'd like to see plugin support built into the TypeScript compiler.

How to use

To declare a function that accepts expressions, you must declare one signature overload that uses parameters of type Expression<T> and another equivalent overload signature that uses parameters of type T which will be used by callers. ts-expressions will only convert supported expressions.

For example, to work with numeric expressions, you could write the following function:

import * as expr from 'ts-expressions';

function numeric(expression: number);
function numeric(expression: expr.Expression<number>);
function numeric(arg: expr.Expression<number> | number) {
  const expression = expr.checkExpressionParameter(arg, 'expression'); //this will check if arg is an expression and will return it, otherwise throws exception
  //do whatever you want with your numeric expression tree
}

Then call it using:

numeric(5 + 1);

Which would be translated by the transformer to:

import * as builder from 'ts-expressions/lib/expressions/ExpressionBuilder';

numeric(builder.createExpression(
  builder.binary(
    builder.constant(5), 
    BinaryOperator.plus, 
    builder.constant(1))));

Note that ts-expressions will only match overload signatures with the same number of parameters and where parameters have compatible expression types.

The following examples work:

function a(expression: number);
function a(expression: expr.Expression<number>);
function a(arg: any) { }

function b(p1: string, expression: number);
function b(p1: string, expression: expr.Expression<number>);
function b(p1: string, arg: any) { }

function c(p1: string, expression1: string, expression2: boolean);
function c(p1: string, expression1: expr.Expression<string>, expression2: expr.Expression<boolean>);
function c(p1: string, arg1: any, arg2: any) { }

The following examples will not work:

function a(expression: number);
function a(expression: expr.Expression<string>);
function a(arg: any) { }

function b(p1: string, expression: number);
function b(expression: expr.Expression<number>, p1: string);
function b(p1: string, arg: any) { }

function c(p1: string, expression1: string);
function c(p1: string, expression1: expr.Expression<string>, expression2: expr.Expression<boolean>);
function c(p1: string, arg1: any, arg2: any) { }