npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ts-docs/jsx-to-str

v0.1.11

Published

A typescript transformer which transforms JSX into template literals.

Downloads

16

Readme

jsx-to-str

A typescript transformer which transforms JSX into template literal strings during the compilation phase of your program.

  • Can't be bothered to learn the syntax of a template engine like pug, ejs or eta?
  • Worried about the performance overhead of said templating engines (parsing + compiling)?
  • Tired of working with outdated and barely working VSCode plugins for said templating engines?
  • Want something more closely integrated to typescript, allowing you to write safe, clean and reusable code?

... then this is perfect for you! jsx-to-str turns JSX syntax to regular template strings during compilation! Use the speed of V8 for parsing and running the templates!

Usage

Install:

npm i --save-dev @ts-docs/jsx-to-str

In order for this transformer to work, make sure you set the following options in your tsconfig.json file:

"jsx": "react-native",

and also place this at the start of your main file:

/// <reference path="path_to_root/node_modules/@ts-docs/jsx-to-str/jsx.d.ts" />

You can use this either by using ttypescript or webpack

TTypescript

  • Install ttypescript: npm i --save-dev ttypescript
  • Add this to your compiler options:
        "plugins": [
            { "transform": "@ts-docs/jsx-to-str" },
        ]
  • Run ttypescript: ttsc

Webpack (with ts-loader)

const TsxToJs = require("@ts-docs/jsx-to-str");

options: {
      getCustomTransformers: program => {
        before: [TsxToJs(program, { customConfig: true })],
        after: [TsxToJs(program, { customConfig: true })],
      }
}

A taste

Original:

type User = { name: string, age: number };

function User(props: User) {
    return <div>name: {props.name}, age: {props.age}</div>;
}

export function UserList(props: { users: Array<User> }) {
    return <ul>
        {...props.users.map(user => <li><User {...user}></User></li>)}
    </ul>;
}

console.log(UserList({
    users: [
        { name: "Google", age: 72 },
        { name: "Yahoo", age: 19 },
        { name: "Hidden", age: 33 }
    ]
}));

Transpiled:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserList = void 0;
function User(props) {
    return `<div>name: ${props.name}, age: ${props.age}</div>`;
}
function UserList(props) {
    return `<ul>\r\n        ${props.users.map(user => `<li>${User(user, "")}</li>`).join("")}\r\n    </ul>`;
}
exports.UserList = UserList;

Console log:

<ul>
        <li><div>name: Google, age: 72</div></li><li><div>name: Yahoo, age: 19</div></li><li><div>name: Hidden, age: 33</div></li>
</ul>