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

pug-template-tag

v2.0.2

Published

Declare safe Pug templates inline in JavaScript

Downloads

4

Readme

Pug Template Tag

npm

A template tag that allows defining safe Pug templates inline in JavaScript or TypeScript code.

Installation

$ npm install pug-template-tag

Usage

// Load the template tag.
const pug = require('pug-template-tag');

// Define a function using inline Pug code.
const templateFunction = pug({ /* pug options */ })`
  doctype html
  p
    =text
`;

// Apply a template to get HTML.
const html = templateFunction({ text: 'Hello, World!' });

Alternatively, you can configure the template tag once and reuse it.

// Load the template tag.
const pugTemplateTag = require('pug-template-tag');

// Create a configured template tag.
const pug = pugTemplateTag({ /* pug options */ });


const templateFoo = pug`
  doctype html
  .foo= text`;

const templateBar = pug`
  doctype html
  .bar= text`;

API

Package pug-template-tag exports a function that may either be called as a template tag to define a template or as a function that takes an options bundle.

pug(pugOptions)

When called with a Pug options bundle, the exported function returns an instance of the same function but which uses the given options bundle.

pug...

When called as a template tag:

  1. Reuses a previously compiled version if available.
  2. Strip common leading whitespace so you can indent Pug templates to match the indentation of surrounding code.
  3. Compiles the Pug source to a function.
  4. Creates a CommonJS module for the template code under the namespace @pug-template.
  5. Returns the template function.

Escaping

The pug template tag behaves like String.raw.

Module System

The pug template functions makes sure that error trace will point to the source file.

Plugins

Regardless of options, the pug template function always attaches two plugins:

  1. A debug plugin that rewrites line numbers and files so that error messages point to the JavaScript code that defined the template.
  2. The Trusted Types plugin makes the template resistant to XSS since it is not a goal of this project to make it easier to produce unsafe templates.