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

maudite

v1.3.0

Published

streaming templates using template literals

Downloads

6

Readme

maudite

maudite (moe-DEET) is a templating system using template literals. It returns a stream of buffers, or a string, for sending the resulting data to its destination.

maudite is pretty quick

Usage

A single function is exported, which acts as a template tag. This tag returns a function taking in a context object, which is then passed to any functions that are inlined into the template literal.

const m = require('maudite');
const template = m`Hello, ${c=>c.name}!\n`;
template({name: 'World'}).pipe(process.stdout);

// Hello, World!

Your inlined functions can return a buffer or a string or another template, and these will be sent to the stream. This means you can do any kind of conditional logic you want to determine what to render.

As a shortcut, you can simply put a property name (as a string that's parsed with deep-access) for the context object, rather than a function accessing it.

const m = require('maudite');
const template = m`Hello, ${'name'}!\n`;
template({name: 'World'}).pipe(process.stdout);

// Hello, World!

You can also use the special m.each function to iterate over arrays in your context object.

const m = require('maudite');
const template = m`Hello,${m.each('things', m` Thing ${c=>c.name}`)}!\n`;
template({
  things: [
    {name: '1'},
    {name: '2'}
  ]
}).pipe(process.stdout);

// Hello, Thing 1 Thing 2!

The first argument to m.each is a context accessor string (see Accessing Properties, below), giving the property that is an array to iterate over. The next argument is a template to apply to each element of the array.

To return a compiled and ready-to-go string, rather than a stream, just call the asString function on the template, passing in the context object.

const m = require('maudite');
const template = m`Hello, ${'name'}!\n`;
console.log(template.asString({name: 'World'}));

// Hello, World!

Accessing properties

For both inline values (like ${'foo'}) and for the first argument to m.each, strings can be used to access properties of the context object. These are dot-separated strings that are compatible with their usage in [deep-access][].

In addition, you can use the @ symbol to refer to the current context object.

Here's an example, where the context object passed in is the string `'World':

const m = require('maudite');
const template = m`Hello, ${'@'}!\n`;
console.log(template.asString('World'));


// Hello, World!

License

See LICENSE.txt