Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

precedent

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

precedent

Precedent Meta-Templating

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
96
decreased by-35.14%
Maintainers
1
Weekly downloads
 
Created
Source

Precedent

Precedent meta-templating engine, for when you want templates ... for templates.

Code Climate Build Status Dependency Status devDependency Status

Template Patterns

Precedent works on the concept of "Template Patterns". These are regions of text that are replaced by their template function. Because patterns are defined in a tree data structure, nested patterns (such as <%, <%=, <$$ and <) properly get parsed in the same process run.

So, for instance, you could create a pattern like so:

// Load the precedent library
var libPrecedent = require('../source/Precedent.js').new();

// Add the pattern
libPrecedent.addPattern('{Name', '}', 'David Bowie');

// Parse a string with the pattern
console.log(libPrecedent.parseString('This is just a short message for {Name}.');
// Anything inbetween the start and end is ignored in this case, since it is a string substitution.
console.log(libPrecedent.parseString('This is just a short message for {Name THIS TEXT IS IGNORED}.  We hope to ignore the previous text.');

This would output the following to the console:

This is just a short message for David Bowie.
This is just a short message for David Bowie.  We hope to ignore the previous text.

precedent.addPattern(patternStart, patternEnd, parser)

Add a pattern to the string processor.

// Pass in a string
libPrecedent.addPattern('{Name', '}', 'David Bowie');

// Or a function
libPrecedent.addPattern('{Name', '}', (pString)=>{return pString.length;});

Each time a pattern is matched, anything between the patternStart and patternEnd will be passed into the parse function.

patternStart

Type: String

The beginning portion of a pattern.

patternEnd

Type: String

The ending portion of a pattern.

parser

Type: String or Function Default: Echo content between the pattern start and end.


precedent.parseString(contentString)

Parse a string with the processor.

libPrecedent.parseString('This is just a short message for {Name}.'
contentString

Type: String

The string of content to parseg

Keywords

FAQs

Package last updated on 04 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc