Skip to content

jsmodule/simple-string-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-string-template

A simple string template.

Current Status:

NPM Version NPM Downloads Build Status

NPM

Installation

$ npm install simple-string-template

Usage

import SimpleTemplate from 'simple-string-template';

SimpleTemplate.render(templateFile, data);

SimpleTemplate.format(templateString, data);

API

SimpleTemplate

  • render

    Defined: function render(templateFile: String, data: Object): String

    Describe: Render a template from file with data.

    Examples:

    A template file like this:

    Hello {{ name }}
    
    import SimpleTemplate from 'simple-string-template';
    
    let data = { name: 'World' };
    SimpleTemplate.render(templateFile, data); // return "Hello World"
  • format

    Defined: function format(templateString: String, data: Object): String

    Describe: Render a template string with data.

    Examples:

    import SimpleTemplate from 'simple-string-template';
    
    let templateString = "Hello {{ name }}";
    let data = { name: 'World' };
    SimpleTemplate.render(templateString, data); // return "Hello World"

More

  1. If you want custom your format pattern. you can like this:
import SimpleTemplate from 'simple-string-template';

let simpleTemplate = new SimpleTemplate('\\$\\{', '\\}'); // In here must be a String of RegExp.
let data = { name: 'World' };

simpleTemplate.render(templateFile, data);
simpleTemplate.format('Hello ${ name }', data);

License

simple-string-template is released under the MIT license.