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 🙏

© 2025 – Pkg Stats / Ryan Hefner

polycompiler

v1.0.0

Published

Merge Python and JS code into one file that can be run in both languages.

Downloads

19

Readme

Polycompiler

See how it works on YouTube.

An experimental project to attempt to merge arbitrary Python and JS code into one source file.

For example, the following code prints Hello JS when run with Node, and Hello Python when run with Python 3.

1 // (lambda: exec("print('Hello Python')", globals()) or 1)()
lambda: eval("console.log('Hello JS')")

Installation & Use

Here's how you can get started with Polycompiler in a few simple steps.

Install polycompiler on NPM:

npm i polycompiler

Merge your files

Now, run the polycompiler command, providing the path to a JS file, a Python file, and an optional result file path.

  • When the output is run with Node.js: It will run your JS file
  • When the output is run with Python: It will run your Python file
polycompiler in.js in.py out.py.js

🚧 WIP: The current file convention for Polycompiler output file extension is .py.js. This is becuase Node refuses to parse files of other file extensions, so it has to end in js.

Test it out

First, running it in Node should execute your JS

node out.py.js

And, running it with python3 will execute the Python

python3 out.py.js

Why Polycompiler?

The best answer for this is honestly "for fun". However, it could also possibly be a possible solution for a single file that can be targeted to both Python and JS audiences (who may perhaps not have the other installed).

How does this work?

See my thought process in developing this on YouTube.

Let's work through this code to see how Polycompiler works:

1 // (lambda: exec("print('Hello Python')", globals()) or 1)()
lambda: eval("console.log('Hello JS')")

Running the Output in Python

First, let's consider what happens when we run this in Python:

  • The first statement in of itself returns nothing, but the lambda function is executed, containing the eval with our target code
  • The second statement is not run at all, since the lambda expression is not called. Thus, the "incorrect" JS code in the eval is never run

This effectively only runs the Python code.

Running the Output in JS

Now, let's consider what happens if you run the code in JS. It's shown in a JS syntax-highlighted codeblock for clarity.

1; // (lambda: exec("print('Hello Python')", globals()) or 1)()
lambda: eval("console.log('Hello JS')");
  • The first statement, ignoring the JS comment, is simply an integer. It does nothing.
  • The second statement utilizes a clever trick with JS Labeled Statements: The lambda: at the start is treated as a label and is ignored. The eval is executed like normal and delivers the execution of the JS code in a string.

This effectively only runs the JavaScript code.

Summary

And just like that, we've managed to ignore the JS portion in Python and the Python portion in JS. Pretty neat!

While it seems simple in hindsight, this solution took a long time to figure out (even though some aspects of it are hiding in plain sight), so I hope it's interesting!