Skip to content

Instantly share code, notes, and snippets.

@kenjinp
Created November 2, 2020 08:13
Show Gist options
  • Save kenjinp/93c446a19b50cba50eb621aad1056f26 to your computer and use it in GitHub Desktop.
Save kenjinp/93c446a19b50cba50eb621aad1056f26 to your computer and use it in GitHub Desktop.

Revisions

  1. kenjinp renamed this gist Nov 2, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion gistfile1.txt → templater.ts
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    import { get } from 'lodash';

    // will result in template parsing inside js-like template-string literals: ${ }
    // for example ${myObject.name}

    const templateStringExpression = /\${([^}]*)}/g;

    const parseMarkdown = (sourceObject: object, templateString: string) => {
    const templater = (sourceObject: object, templateString: string) => {
    return templateString.replace(
    templateStringExpression,
    (match: string, group1: string) => {
  2. kenjinp created this gist Nov 2, 2020.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    // will result in template parsing inside js-like template-string literals: ${ }
    // for example ${myObject.name}

    const templateStringExpression = /\${([^}]*)}/g;

    const parseMarkdown = (sourceObject: object, templateString: string) => {
    return templateString.replace(
    templateStringExpression,
    (match: string, group1: string) => {
    const value = get(sourceObject, group1);
    return value;
    }
    );
    };