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.0.5
  • 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

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.updateSourceFileNode(
  ts.createSourceFile('test.ts', '', ts.ScriptTarget.Latest),
  [
    ts.createFunctionDeclaration(
      undefined,
      undefined,
      undefined,
      ts.createIdentifier('foo'),
      undefined,
      [
        ts.createParameter(
          undefined,
          undefined,
          undefined,
          ts.createIdentifier('bar'),
          undefined,
          ts.createToken(ts.SyntaxKind.NumberKeyword),
          undefined
        )
      ],
      ts.createToken(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;
}

How to use it:

import creator from 'ts-creator'

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

TODO:

  • JSDoc
  • Jsx

FAQs

Package last updated on 12 Jan 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