Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
ts-creator
Advanced tools
A code generator to generate TypeScript code generator from TypeScript code
npm install ts-creator
import creator from 'ts-creator'
const generatedFactoryCode = creator(`const foo = "your code here"`)
import { transformSourceFile } from 'ts-creator'
declare const file: ts.SourceFile
const factoryFile = transformSourceFile(file)
import { transformNode } from 'ts-creator'
declare const node: ts.Expression
const factoryNode = transformNode(node)
If you want to write a TypeScript codegen.
You got TypeScript code:
function foo(bar: number): number {
return bar + 1
}
ts-creator generate TypeScript factory from given code to:
ts.createFunctionDeclaration(
undefined,
undefined,
undefined,
ts.createIdentifier('foo'),
undefined,
[
ts.createParameter(
undefined,
undefined,
undefined,
ts.createIdentifier('bar'),
undefined,
ts.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
undefined
)
],
ts.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
ts.createBlock(
[
ts.createReturn(
ts.createBinary(
ts.createIdentifier('bar'),
ts.createToken(ts.SyntaxKind.PlusToken),
ts.createNumericLiteral('1')
)
)
],
true
)
)
Result after run the generated factory code:
function foo(bar: number): number {
return bar + 1;
}
Use ts-creator
cli to generate code:
ts-creator <input> [options]
Simple usage:
# print generate code
ts-creator foo.ts
# or read data from pipeline
echo 42 | ts-creator
cat foo.ts | ts-creator
ts-creator < foo.ts
# write to file
ts-creator foo.ts -o foo.js
ts-creator foo.ts > foo.js
You can install ts-creator
globally.
npm i -g ts-creator
# or yarn
yarn global add ts-creator
If you install locally, may prepend npx
or yarn
you need.
# use npm
npm i ts-creator
npx ts-creator -h
# use yarn
yarn add ts-creator
yarn ts-creator -h
option | description | type | default |
---|---|---|---|
--color | colorful print | boolean | false |
--output, -o | output to filepath | string | undefined |
--version, -v | show ts-creator version | boolean | false |
--help, -h | show help | boolean | false |
FAQs
A code generator to generate TypeScript code generator from TypeScript code
We found that ts-creator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.