Skip to content

Repository files navigation

simple-string-template

A simple string template.

Current Status:

NPM VersionNPM DownloadsBuild Status

NPM

Installation

$ npm install simple-string-template

Usage

importSimpleTemplatefrom'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 }}
    
    importSimpleTemplatefrom'simple-string-template';letdata={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:

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

More

  1. If you want custom your format pattern. you can like this:
importSimpleTemplatefrom'simple-string-template';letsimpleTemplate=newSimpleTemplate('\\$\\{','\\}');// In here must be a String of RegExp.letdata={name: 'World'};simpleTemplate.render(templateFile,data);simpleTemplate.format('Hello ${ name }',data);

License

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

About

A simple template

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages