{"id":13588727,"url":"https://github.com/HearTao/ts-creator","last_synced_at":"2025-04-08T06:32:38.006Z","repository":{"id":34032638,"uuid":"165227423","full_name":"HearTao/ts-creator","owner":"HearTao","description":"A code generator to generate TypeScript code generator from TypeScript code","archived":false,"fork":false,"pushed_at":"2023-03-06T18:46:51.000Z","size":1309,"stargazers_count":386,"open_issues_count":22,"forks_count":21,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-11-06T08:43:06.167Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ts-creator.js.org/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HearTao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-01-11T10:43:38.000Z","updated_at":"2024-11-01T01:37:23.000Z","dependencies_parsed_at":"2023-01-15T04:15:28.649Z","dependency_job_id":"8f9e3371-a482-41af-9431-7b1898b70737","html_url":"https://github.com/HearTao/ts-creator","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HearTao%2Fts-creator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HearTao%2Fts-creator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HearTao%2Fts-creator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HearTao%2Fts-creator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HearTao","download_url":"https://codeload.github.com/HearTao/ts-creator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247792150,"owners_count":20996878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:06:53.311Z","updated_at":"2025-04-08T06:32:32.997Z","avatar_url":"https://github.com/HearTao.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Tools","Compiler"],"sub_categories":["Optimization"],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"520\" src=\"./media/Logo.svg\"\u003e\n  \n  # ts-creator \n  \n  A code generator to generate TypeScript code generator from TypeScript code\n\n  [![Build Status](https://travis-ci.com/HearTao/ts-creator.svg?branch=master)](https://travis-ci.com/HearTao/ts-creator)  [![NPM version](https://img.shields.io/npm/v/ts-creator.svg)](https://www.npmjs.com/package/ts-creator)   [![codecov](https://codecov.io/gh/HearTao/ts-creator/branch/master/graph/badge.svg)](https://codecov.io/gh/HearTao/ts-creator)\n\n  👉 [Try It!](https://ts-creator.js.org/) 👈\n\u003c/div\u003e\n\n\n## How to use it:\n\n```shell\nnpm install ts-creator\n```\n\n\n### 1. generate from code\n\n```ts\nimport creator from 'ts-creator'\n\nconst generatedFactoryCode = creator(`const foo = \"your code here\"`)\n```\n\n### 2. transform source file\n\n```ts\nimport { transformSourceFile } from 'ts-creator'\n\ndeclare const file: ts.SourceFile\nconst factoryFile = transformSourceFile(file)\n```\n\n### 3. transform node\n\n```ts\nimport { transformNode } from 'ts-creator'\n\ndeclare const node: ts.Expression\nconst factoryNode = transformNode(node)\n```\n\n## How does it work?\n\nIf you want to write a TypeScript codegen.\n\nYou got TypeScript code: \n\n```ts\nfunction foo(bar: number): number {\n  return bar + 1\n}\n```\n\nts-creator generate TypeScript factory from given code to:\n\n```ts\nts.createFunctionDeclaration(\n  undefined,\n  undefined,\n  undefined,\n  ts.createIdentifier('foo'),\n  undefined,\n  [\n    ts.createParameter(\n      undefined,\n      undefined,\n      undefined,\n      ts.createIdentifier('bar'),\n      undefined,\n      ts.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n      undefined\n    )\n  ],\n  ts.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n  ts.createBlock(\n    [\n      ts.createReturn(\n        ts.createBinary(\n          ts.createIdentifier('bar'),\n          ts.createToken(ts.SyntaxKind.PlusToken),\n          ts.createNumericLiteral('1')\n        )\n      )\n    ],\n    true\n  )\n)\n\n```\n\nResult after run the generated factory code: \n\n```ts\nfunction foo(bar: number): number {\n    return bar + 1;\n}\n```\n\n## Cli usage\n\nUse `ts-creator` cli to generate code:\n\n```sh\nts-creator \u003cinput\u003e [options]\n```\n\nSimple usage:\n\n```sh\n# print generate code\nts-creator foo.ts\n\n# or read data from pipeline\necho 42 | ts-creator\ncat foo.ts | ts-creator\nts-creator \u003c foo.ts\n\n# write to file\nts-creator foo.ts -o foo.js\nts-creator foo.ts \u003e foo.js\n```\n\n### Installation\n\nYou can install `ts-creator` globally.\n\n```sh\nnpm i -g ts-creator\n# or yarn\nyarn global add ts-creator\n```\n\nIf you install locally, may prepend `npx` or `yarn` you need. \n\n```sh\n# use npm\nnpm i ts-creator\nnpx ts-creator -h\n\n# use yarn\nyarn add ts-creator\nyarn ts-creator -h\n```\n\n### Cli options\n\n| option | description | type | default |\n|---|---|---|---|\n| --target, -t | generate targets | Enum { `expression`, `runnable`, `esmodule`, `commonjs` } | `expression` |\n| --output, -o | output to filepath | String | `undefined` |\n| --tsx | tsx support | Boolean | `false` |\n| --color | colorful print | Boolean | `true` |\n| --semi | print semicolons at the ends of statements | Boolean | `false` |\n| --single-quote | use single quotes instead of double quotes | Boolean | `true` |\n| --jsx-single-quote | use single quotes in JSX | Boolean | `false` |\n| --bracket-spacing | print spaces between brackets in object literals | Boolean | `true` |\n| --tab-width | pecify the number of spaces per indentation-level | Number | `2` |\n| --use-tabs | indent lines with tabs instead of spaces | Boolean | `false` |\n| --trailing-comma | print trailing commas wherever possible | Enum { `none`, `es5`, `all` } | `none` |\n| --prose-wrap | how to wrap output | Enum { `always`, `never`, `preserve` } | `preserve` |\n| --version, -v | show ts-creator versions | Boolean | `false` |\n| --help, -h | show helper | Boolean | `false` |\n\n## TODO:\n\n- [ ] JSDoc\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHearTao%2Fts-creator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHearTao%2Fts-creator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHearTao%2Fts-creator/lists"}