Skip to content

Lightweight JavaScript template engine.

License

Notifications You must be signed in to change notification settings

macie/smallstache

Repository files navigation

Smallstache

Build Status Test Coverage Code Climate

A lightweight, logic-less JavaScript template engine similar to Mustache/Handlebars. And look mummy, it has only 0.5kB minimized!

Features

  • Object-oriented approach
  • Very small footprint
  • No dependencies (only good old VanillaJS)
  • Fast and reliable (100% test coverage)
  • Easily debuggable (leaves original tag if can't find data)

Usage

Typical usage:

  var template = new Smallstache('Hello {{ something }}!');
  template.fill({something: 'World'});
  // > 'Hello World!'

You can also use an array as a data source:

  var title = new Smallstache('{{0}}, {{1}} and {{2}}');
  title.fill(['Me', 'Myself', 'I']);
  // > 'Me, Myself and I'

Or even a string!

  var question = new Smallstache('Food with 5 letters: {{0}}...{{4}}');
  question.fill('kebab');
  // > 'Food with 5 letters: k...b'

More examples of using Smallstache (with node and web browser) you can find in examples directory.

API

  • new Smallstache(string)

    Creates template object from given string.

  • .fill(obj): string

    Returns a string with template filled by an object, an array or a string.

License

MIT