How to use the mustache.Formatters function in mustache

To help you get started, we’ve selected a few mustache examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jvitela / mustache-wax / test / spec.js View on Github external
describe( "Expressions with parameters", () => {
        const fmt  =  Mustache.Formatters;
        const data = { name: "john", age:20 };
        
        it('Should call formatter with one additional integer parameter', () => {
            const result1 = Mustache.render("{{ name | lpad:30 }}", data);
            expect(result1).to.equal(fmt.lpad(data.name, 30));
        })

        it('Should call formatter with one additional decimal parameter', () => {
            const result1 = Mustache.render("{{ age | add:0.5 }}", data);
            expect(result1).to.equal('' + fmt.add(data.age, 0.5));
        })
    
        it('Should call the formatter with one additional string parameter', () => {
            const result2 = Mustache.render("{{ name | add:' doe' }}", data);
            expect(result2).to.equal(fmt.add(data.name, ' doe'));
        })
github jvitela / mustache-wax / test / spec.js View on Github external
"date": (dt) => {
            const lpad = Mustache.Formatters.lpad, 
                day   = lpad(dt.getDate(), 2, "0"),
                month = lpad(dt.getMonth()+1, 2, "0");
            return  day + "/" + month + "/" + dt.getFullYear();
        },
        "add": (one, two) => {
github odrick / free-tex-packer-core / exporters / index.js View on Github external
let list = require('./list.json');
let appInfo = require('../package.json');
let mustache = require('mustache');
let fs = require('fs');
let path = require('path');
let wax = require('@jvitela/mustache-wax');

wax(mustache);

mustache.Formatters = {
    add: (v1, v2) => {
        return v1 + v2;
    },
    subtract: (v1, v2) => {
        return v1 - v2;
    },
    multiply: (v1, v2) => {
        return v1 * v2;
    },
    divide: (v1, v2) => {
        return v1 / v2;
    },
    offsetLeft: (start, size1, size2) => {
        let x1 = start + size1 / 2;
        let x2 = size2 / 2;
        return x1 - x2;
github odrick / free-tex-packer / src / client / exporters / index.js View on Github external
import list from './list.json';
import appInfo from '../../../package.json';
import {GET} from '../utils/ajax';
import mustache from 'mustache';
import wax from '@jvitela/mustache-wax';

wax(mustache);

mustache.Formatters = {
    add: (v1, v2) => {
        return v1 + v2;
    },
    subtract: (v1, v2) => {
        return v1 - v2;
    },
    multiply: (v1, v2) => {
        return v1 * v2;
    },
    divide: (v1, v2) => {
        return v1 / v2;
    },
    offsetLeft: (start, size1, size2) => {
        let x1 = start + size1 / 2;
        let x2 = size2 / 2;
        return x1 - x2;