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

precedent

v1.0.16

Published

Precedent Meta-Templating

Readme

Precedent

A meta-templating engine for processing text streams with pattern-based template expressions. Define start/end pattern markers with string or function parsers, and Precedent handles nested pattern resolution automatically.

Coverage Status Build Status npm version License: MIT


Features

  • Pattern-Based Parsing - Define start/end markers to identify template regions in text
  • String or Function Parsers - Replace patterns with static strings or dynamic function output
  • Nested Pattern Support - Overlapping pattern prefixes (e.g. <%, <%=, <$$) resolve correctly in a single pass
  • Word Tree Architecture - Patterns are stored in a tree structure for efficient matching
  • Data Passing - Pass a data object through to parser functions for context-aware rendering
  • Browser Compatible - Works in both Node.js and browser environments
  • Zero Dependencies - No external runtime dependencies

Installation

npm install precedent

Quick Start

const Precedent = require('precedent');

const precedent = new Precedent();

// Add a simple string substitution pattern
precedent.addPattern('{Name', '}', 'David Bowie');

// Parse a string containing the pattern
precedent.parseString('Hello, {Name}!');
// => "Hello, David Bowie!"

Usage

String Substitution

Replace patterns with a fixed string value. Content between the start and end markers is ignored:

const precedent = new Precedent();

precedent.addPattern('{Name', '}', 'David Bowie');

precedent.parseString('A message for {Name}.');
// => "A message for David Bowie."

// Content between markers is ignored for string substitutions
precedent.parseString('A message for {Name IGNORED TEXT}.');
// => "A message for David Bowie."

Function-Based Parsing

Pass a function as the parser to dynamically process the content between markers:

const precedent = new Precedent();

precedent.addPattern('{Length', '}', (pString) => { return pString.length; });

precedent.parseString('The length is {Length some text}.');
// => "The length is  some text."  (length of " some text")

Passing Data to Parsers

A data object can be passed as the second argument to parseString, which is then available to parser functions:

const precedent = new Precedent();

precedent.addPattern('<%=', '%>', (pContent, pData) =>
{
	return pData[pContent.trim()] || '';
});

precedent.parseString('Hello, <%= username %>!', { username: 'Steven' });
// => "Hello, Steven!"

API

addPattern(patternStart, patternEnd, parser)

Add a pattern to the parse tree.

| Parameter | Type | Description | |-----------|------|-------------| | patternStart | String | The opening marker for the pattern | | patternEnd | String | The closing marker for the pattern | | parser | String or Function | Replacement string, or function receiving (content, data) |

Returns true if the pattern was added successfully.

parseString(contentString, data)

Parse a string against all registered patterns.

| Parameter | Type | Description | |-----------|------|-------------| | contentString | String | The text to parse | | data | Object | Optional data object passed to parser functions |

Returns the parsed string.

Part of the Retold Framework

Precedent is used throughout the Fable ecosystem for template processing:

Testing

Run the test suite:

npm test

Run with coverage:

npm run coverage

Related Packages

License

MIT

Contributing

Pull requests are welcome. For details on our code of conduct, contribution process, and testing requirements, see the Retold Contributing Guide.