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

mirrorview

v1.0.10

Published

Template engine that works like PHP, to display data in HTML use <?js writeToDocument = 'Example' ?>

Downloads

4

Readme

MirrorView

MirrorView is a Node.js module that allows you to execute JavaScript code embedded within an HTML string and replace the code with the output.

Installation

To install MirrorView, use npm:

npm install mirrorview

Usage

To use MirrorView in your Node.js program, require the module and call the executeJS function:

const mirrorview = require('mirrorview');

let html = '<html><body><h1><?js "Hello, world!" ?></h1></body></html>';
let context = {};

html = mirrorview.executeJS(context, html);

The executeJS function takes two arguments: a context object and an HTML string. The context object can be used to provide variables or functions that the embedded JavaScript code can use. To output values in the HTML string you can use the echo function, it takes a string as a parameter.

For example, the following HTML string will output "2":

<html>
  <body>
    <h1><?js echo(1 + 1); ?></h1>
  </body>
</html>

Here is another example of how you could use the executeJS function in a Node.js program:

const mirrorview = require('mirrorview');

let html = `
  <html>
    <body>
      <h1><?js "Hello, world!" ?></h1>
      <p><?js echo("Today is " + new Date().toLocaleDateString()); ?></p>
      <ul>
        <?js
          for (let i = 1; i <= 5; i++) {
            echo('<li>Item ' + i + '</li>');
          }
        ?>
      </ul>
    </body>
  </html>
`;
let context = {};

html = mirrorview.executeJS(context, html);
console.log(html);

This code will output the following HTML string:

<html>
  <body>
    <h1>Hello, world!</h1>
    <p>Today is [current date]</p>
    <ul>
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
      <li>Item 4</li>
      <li>Item 5</li>
    </ul>
  </body>
</html>

Limitations

There are a few limitations to be aware of when using MirrorView:

  • Only JavaScript code embedded within tags will be executed.
  • The context object must be a plain JavaScript object. It cannot be a class or function, though it can include class or functions.
  • The executeJS function does not provide any way to catch or handle errors that may occur while executing the embedded code. If an error occurs, it will be thrown and may crash the program.

License

MirrorView is released under the GNU AGPL v3.0 license. See LICENSE for more information.