Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-creator

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-creator

A code generator to generate TypeScript code generator from TypeScript code

  • 1.2.0-c9e6aafe
  • npm
  • Socket score

Version published
Weekly downloads
13
Maintainers
1
Weekly downloads
 
Created
Source

ts-creator

A code generator to generate TypeScript code generator from TypeScript code

Build Status NPM version

👉 Try It! 👈

How to use it:

npm install ts-creator

1. generate from code

import creator from 'ts-creator'

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

2. transform source file

import { transformSourceFile } from 'ts-creator'

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

3. transform node

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:

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;
}

Cli usage

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

Installation

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

Cli options

optiondescriptiontypedefault
--colorcolorful printbooleanfalse
--output, -ooutput to filepathstringundefined
--version, -vshow ts-creator versionbooleanfalse
--help, -hshow helpbooleanfalse

TODO:

  • JSDoc

FAQs

Package last updated on 12 Feb 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc