Talt
Template functions to generate TypeScript AST node object
Install / Use
/learn @Quramy/TaltREADME
Talt
Template functions to generate TypeScript AST, inspired from @babel/template .
Install
$ npm i talt typescript
Usage
import ts from "typescript";
import { template } from "talt";
const typeNode = template.typeNode("{ readonly hoge: string }")();
// You can use `template` as tag function.
const typeNodeUsingTagFn = template.typeNode`
{
readonly hoge: string;
}
`();
// The following returns ts.BinaryExpression
const binaryExpression = template.expression<ts.BinaryExpression>("60 * 1000")();
// You can use identifier placeholder.
const compiledFn = template.expression`
60 * SOME_PLACEHOLDER_KEY
`;
const generatedAst = compiledFn({
SOME_PLACEHOLDER_KEY: binaryExpression,
}); // returns expression node, `60 * 60 * 1000`
const generetedOtherNode = compiledFn({
SOME_PLACEHOLDER_KEY: ts.factory.createNumericLiteral("200"),
}); // returns expression node, `60 * 200`
// You can use any function which returns ts.Node instead of identifier placeholder.
const altCompiledFn = template.expression`
60 * ${() => binaryExpression}
`; // returns expression node, `60 * 60 * 1000`
API
template has the following tag functions. Each tag function compiles and provides corresponding type AST.
template.typeNodetemplate.expressiontemplate.statementtemplate.sourceFiletemplate.jsxAttribute
License
MIT
Related Skills
node-connect
352.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
111.1kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
100.6kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
