substitute.js

1.0.3 • Public • Published

substitute.js

A javascript micro template, reference Dojo

Usage

Basic

    import substitute from 'substitute.js';
 
    const template = "<div>${name}</div><div>${age}</div>";
 
    const map = {
        name : "Linus Wang",
        age: 23
    };
 
    const string = substitute(template, map);

Use format

    const template = "${name:nameFmt} ${age:ageFmt}";
 
    const map = {
        name : "Linus Wang"
    };
 
    const thisObject = {
        nameFmt : function(value, key){
            return key + " is: " + value;
        }, 
        ageFmt : function(value, key){
            return key + " is: " + value;
        },
        transform : function(value, key){
            return value;
        }
    }
 
    const string = substitute(template, map, null, thisObject);

Readme

Keywords

Package Sidebar

Install

npm i substitute.js

Weekly Downloads

1

Version

1.0.3

License

none

Last publish

Collaborators

  • linus.wang