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

pixie

v2.0.0

Published

Tiny template engine

Downloads

51

Readme

Tiny template engine

var pixie = require('pixie')

// Parse a template
var template = pixie.parse('foo {{bar}} baz', '{{', '}}')
// => [['foo ', ' baz'], ['bar']]

// Compile (using simple default)
pixie.compile(template, { bar: 'Baaar!' })
// => 'foo Baaar! baz'

Pixie is a tiny template engine (321 bytes uglified and 27 SLOC) that creates templates as arrays of strings. This lets you use alternative compilers to support only the syntax you want, precompile templates, or serialize templates as JSON. See the pixie keyword on npm for more packages.

Installation

$ npm i pixie

Usage

pixie.parse(source, open, close)

Parse the source into a template. This is passed off to a compile (e.g. pixie.compile or others)

  • source: The template string source being parsed
  • open: Tag for opening expressions
  • close: Tag for closing expressions
// Parse with tags
pixie.parse('Hello {{world}} foo {{bar}} baz.', '{{', '}}')

// Parse with alternative tags
pixie.parse('Hello <%world%>!', '<%', '%>')

pixie.compile(template, data)

A simple compiler, substitutes properties from an object by name

  • template: A template object that was returned from pixie.parse
  • data: An object/array that you want to insert the data into the expressions
// Parse a template
var template = pixie.parse('foo {{bar}} baz {{qux}}')

// Compile template
pixie.compile(template, { bar: 'baaar', qux: 'quuux' })
// => 'foo baaar baz quuux'

Template structure

The template structure is an array, containing two other arrays recognized as [fragments, expressions]

  • Expressions: Data between the opening and closing points. In Foo {{bar}} baz {{qux}} they would be ['bar', 'qux']
  • Fragments: Data around your expressions. In the same example, the fragments would be ['Foo ', ' baz', '']

Compilers can choose to interpret and compile these however they choose. The pixie.compile ones is just a simple point-n-place

License

MIT © Jamen Marz


version license downloads/month downloads support me follow