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-load

v3.0.0

Published

The Pug loader is responsible for loading the depenendencies of a given Pug file.

Downloads

6,142,935

Readme

pug-load

The pug loader is responsible for loading the depenendencies of a given pug file. It adds fullPath and str properties to every Include and Extends node. It also adds an ast property to any Include nodes that are loading pug and any Extends nodes. It then recursively loads the dependencies of any of those included files.

Build Status Dependencies Status DevDependencies Status NPM version Coverage Status

Installation

npm install pug-load

Usage

var load = require('pug-load');

load(ast, options)

load.string(str, filename, options)

load.file(filename, options)

Loads all dependencies of the Pug AST. load.string and load.file are syntactic sugar that parses the string or file instead of you doing it yourself.

options may contain the following properties:

  • lex (function): (required) the lexer used
  • parse (function): (required) the parser used
  • resolve (function): a function used to override load.resolve. Defaults to load.resolve.
  • read (function): a function used to override load.read. Defaults to load.read.
  • basedir (string): the base directory of absolute inclusion. This is required when absolute inclusion (file name starts with '/') is used. Defaults to undefined.

The options object is passed to load.resolve and load.read, or equivalently options.resolve and options.read.

load.resolve(filename, source, options)

Callback used by pug-load to resolve the full path of an included or extended file given the path of the source file.

filename is the included file. source is the name of the parent file that includes filename.

This function is not meant to be called from outside of pug-load, but rather for you to override.

load.read(filename, options)

Callback used by pug-load to return the contents of a file.

filename is the file to read.

This function is not meant to be called from outside of pug-load, but rather for you to override.

load.validateOptions(options)

Callback used pug-load to ensure the options object is valid. If your overridden load.resolve or load.read uses a different options scheme, you will need to override this function as well.

This function is not meant to be called from outside of pug-load, but rather for you to override.

Example

var fs = require('fs');
var lex = require('pug-lexer');
var parse = require('pug-parser');
var load = require('pug-load');

// you can do everything very manually

var str = fs.readFileSync('bar.pug', 'utf8');
var ast = load(parse(lex(str, 'bar.pug'), 'bar.pug'), {
  lex: lex,
  parse: parse,
  resolve: function (filename, source, options) {
    console.log('"' + filename + '" file requested from "' + source + '".');
    return load.resolve(filename, source, options);
  }
});

// or you can do all that in just two steps

var str = fs.readFileSync('bar.pug', 'utf8');
var ast = load.string(str, 'bar.pug', {
  lex: lex,
  parse: parse,
  resolve: function (filename, source, options) {
    console.log('"' + filename + '" file requested from "' + source + '".');
    return load.resolve(filename, source, options);
  }
});

// or you can do all that in only one step

var ast = load.file('bar.pug', {
  lex: lex,
  parse: parse,
  resolve: function (filename, source, options) {
    console.log('"' + filename + '" file requested from "' + source + '".');
    return load.resolve(filename, source, options);
  }
});

License

MIT