ima-template
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

ima-template

A simple template function for generating great-looking code from great-looking TypeScript code.

Example

Let's say that you want to generate some Java code from a TypeScript tool. You want your source code to look great, but also the generated source code. This is where ima-template can help you!

Given the following example:

import { template } from "ima-template";

function generateCode() {
    return template`
        |class HelloWorld {
        |    public static void main(string[] args) {
        |        System.out.println("Hello world!");
        |    }
        |}
        |`
}

The output of generateCode would look as follows:

class HelloWorld {
    public static void main(string[] args) {
        System.out.println("Hello world!");
    }
}

Features

  • Lines that start with whitespace followed by a pipe (|) are included in the output. Other lines are ignored.
  • The whitespace up to and including the pipe character are not present in the output. This allows you to use proper indentation in the TypeScript code of the code generator, while also having control over the indentation of the generated code.
  • When using a nested template, the indentation is repeated for every line, so that the generated source code makes sense.

Package Sidebar

Install

npm i ima-template

Weekly Downloads

1

Version

0.0.2

License

Apache-2.0

Unpacked Size

19.9 kB

Total Files

7

Last publish

Collaborators

  • bvanreeven