百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

ts-creator

> 编程语言
开源

一个代码生成器,用于从 TypeScript 代码生成 TypeScript 代码

391 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个代码生成器,用于从 TypeScript 代码生成 TypeScript 代码

How to use it:

bash
npm install ts-creator

1. generate from code

typescript
import creator from 'ts-creator'

const generatedFactoryCode = creator(`const foo = "your code here"`)

2. transform source file

typescript
import { transformSourceFile } from 'ts-creator'

declare const file: ts.SourceFile
const factoryFile = transformSourceFile(file)

3. transform node

typescript
import { transformNode } from 'ts-creator'

declare const node: ts.Expression
const factoryNode = transformNode(node)

How does it work?

If you want to write a TypeScript codegen.

You got TypeScript code:

typescript
function foo(bar: number): number {
  return bar + 1
}

ts-creator generate TypeScript factory from given code to:

…

Result after run the generated factory code:

typescript
function foo(bar: number): number {
    return bar + 1;
}

Cli usage

Use ts-creator cli to generate code:

bash
ts-creator  [options]

Simple usage:

bash
# print generate code
ts-creator foo.ts

# or read data from pipeline
echo 42 | ts-creator
cat foo.ts | ts-creator
ts-creator  foo.js

Installation

You can install ts-creator globally.

bash
npm i -g ts-creator
# or yarn
yarn global add ts-creator

If you install locally, may prepend npx or yarn you need.

bash
# use npm
npm i ts-creator
npx ts-creator -h

# use yarn
yarn add ts-creator
yarn ts-creator -h

Cli options

option description type default
--target, -t generate targets Enum { expression, runnable, esmodule, commonjs } expression
--output, -o output to filepath String undefined
--tsx tsx support Boolean false
--color colorful print Boolean true
--semi print semicolons at the ends of statements Boolean false
--single-quote use single quotes instead of double quotes Boolean true
--jsx-single-quote use single quotes in JSX Boolean false
--bracket-spacing print spaces between brackets in object literals Boolean true
--tab-width pecify the number of spaces per indentation-level Number 2
--use-tabs indent lines with tabs instead of spaces Boolean false
--trailing-comma print trailing commas wherever possible Enum { none, es5, all } none
--prose-wrap how to wrap output Enum { always, never, preserve } preserve
--version, -v show ts-creator versions Boolean false
--help, -h show helper Boolean false

TODO:

  • JSDoc

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言