Socket
Socket
Sign inDemoInstall

ttypescript

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ttypescript

Over TypeScript tool to use custom transformers in the tsconfig.json


Version published
Weekly downloads
181K
increased by13.05%
Maintainers
1
Weekly downloads
 
Created

What is ttypescript?

ttypescript is a TypeScript transformer tool that allows you to customize the TypeScript compiler by adding custom transformers. It provides a way to extend the TypeScript compiler's capabilities, enabling you to modify the Abstract Syntax Tree (AST) during the compilation process.

What are ttypescript's main functionalities?

Custom Transformer

This feature allows you to create custom transformers that can modify the TypeScript AST during the compilation process. The code sample demonstrates how to create a simple transformer that visits each node in the AST.

const ttypescript = require('ttypescript');
const ts = require('typescript');

function myTransformer(context) {
  return (sourceFile) => {
    function visitor(node) {
      // Custom transformation logic
      return ts.visitEachChild(node, visitor, context);
    }
    return ts.visitNode(sourceFile, visitor);
  };
}

const options = { transformers: { before: [myTransformer] } };
ttypescript.transpileModule('const x: number = 42;', options);

Integration with TypeScript Compiler

This feature demonstrates how to integrate ttypescript with the TypeScript compiler to create a program and emit the compiled output. It also shows how to handle diagnostics and errors during the compilation process.

const ttypescript = require('ttypescript');
const ts = require('typescript');

const program = ttypescript.createProgram(['./src/index.ts'], {});
const emitResult = program.emit();

const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);

allDiagnostics.forEach(diagnostic => {
  if (diagnostic.file) {
    const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
    const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
    console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
  } else {
    console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
  }
});

Other packages similar to ttypescript

Keywords

FAQs

Package last updated on 09 Dec 2022

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