1. maxstache
Minimalist mustache template replacement
maxstache
Package: maxstache
Created by: yoshuawuyts
Last modified: Sun, 19 Jun 2022 17:00:58 GMT
Version: 1.0.7
License: MIT
Downloads: 644,442
Repository: https://github.com/yoshuawuyts/maxstache

Install

npm install maxstache
yarn add maxstache

maxstache stability

NPM version
build status
Test coverage
Downloads
js-standard-style

Minimalist mustache template replacement. Works extremely fast on one-off
replacements and doesn't escape any values.

Installation

 $ npm install maxstache

Usage

 const maxstache = require('maxstache')

const str = 'My name is {{name}}'
const ctx = { name: 'jjjohnny' }
maxstache(str, ctx)
// => 'My name is jjjohnny'

API

nwStr = maxstache(str, ctx)

Replace {{<var>}} style variables in a string with values from a context.
Variable replacement doesn't escape values.

FAQ

Why not use {mus,min}stache?

minstache was built as a minimalist replacement for mustache, but is
unfortunately no longer maintained. This package is built as a smaller, faster
alternative to minstache that makes no assumptions about the file types (e.g.
no HTML-style escaping by default).

Why doesn't maxstache escape values?

Template string escaping is useful for more than HTML. When building templates
for a variety of languages, escaping assumptions merely get in the way. If you
want to escape values, it's easy to pass the string result through an escape
function or escape the variable values before passing them into this function.
Hurray for composition!

25 lines is too much, make it shorter!

:rotating_light: CODE GOLF INITIATED :rotating_light:

 module.exports = function maxstache (str, ctx) {
  return str.split(/\{\{|\}\}/).map((t, i) => !(i % 2) ? t : ctx[t]).join('')
}

Shout out to @divinegod and
@someoneweird for thinking of ways to do
this in less lines.

See Also

License

MIT

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin