1.0.0 • Published 4 years ago

reversible-template-string v1.0.0

Weekly downloads
120
License
MIT
Repository
github
Last release
4 years ago

reversible-template-string

Encode and decode data to string using mustache-like template strings

Usage

Functions

encodeTemplate(template, values) ⇒ String

Encode a template with the given variables. NOTE: values must not include curly braces or commas.

Kind: global function
Returns: String - The template with the values encoded. E.g. 'employee_12_months_growth'

ParamTypeDescription
templateStringTemplate string. E.g. 'employee_{period}_months_growth'
valuesStringObject of values to insert in the string. E.g. { period: 12 }

decodeTemplate(template, string) ⇒ Object

Decode a template string given the given template.

Kind: global function
Returns: Object - An object given the matched template values. E.g. { period: '12' }

ParamTypeDescription
templateStringTemplate string. E.g. 'employee_{period}_months_growth'
stringStringA string to be decoded with the given template. E.g. 'employee_12_months_growth'