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 🙏

© 2026 – Pkg Stats / Ryan Hefner

m4

v0.1.4

Published

M4 macro processor in pure Javascript

Readme

m4

Work in progress!

m4 is a pure Javascript implementation of an m4 macro language processor. You can use it with Node.js or in the browser, via browserify. It is exposed as a transformation Stream. As such, you can easily pipe from any input and to any output.

A command-line version is also provided, usable as a drop-in replacement for a native version (such as GNU M4).

Installation

npm install m4

If installed locally, the binary is available as node_module/.bin/m4. You can directly refer to m4 in npm-scripts.

Example usage

From a shell

echo "define(\`beep', \`boop')dnl\nbeep\n" | m4
#=>  boop

From JavaScript

// example.js
'use strict';

var M4 = require('m4');

var input = new M4();
input.pipe(M4()).pipe(process.stdout);

input.write("define(`beep', `boop')dnl\nbeep\n");
input.end();

Then, in a shell:

node example.js
#=>  boop

API

Class: M4

Inherit stream.Transform. As such this is a duplex stream you can pipe, write and read.

new M4(opts)

  • opts Object Options:

Event: 'error'

Signal a non-recuperable error. The stream will not produce further output in the case of an error.

Event: 'warning'

Signal a warning. The steam continues to produce output normally, but there may be some unwanted behavior.

m4.define(name, {fn|str})

  • name String Identifier.
  • fn Fonction Called with (name, [arg1, arg2 ... ]), must return the macro expansion result as a string. name is the macro defined name itself.
  • str String Macro content, just like you were defining the macro in M4.

Define a M4 macro as a Javascript function.

m4.divert([index=0])

  • index Number Diversion index.

Change how the output is processed. If the index is zero, output is directly emitted by the stream. If the index is a positive integer, the output is stored in an internal buffer — a "diversion" — instead.

m4.undivert([diversions...])

  • diversions Number Diversion indices.

Output the content of the specified diversions. They are emptied. If no diversion is specified, all of them are undiverted, in numerical order.

m4.dnl()

Put the stream into a special mode where all the tokens are ignored until the next newline.

m4.changeQuote([left], [right])

  • left String Characters delimiting the beginning of a string.
  • right String Characters delimiting the end of a string.

Delimiters can be of any length.