{"id":20555882,"url":"https://github.com/conjurelabs/dot-template","last_synced_at":"2026-01-02T07:54:30.428Z","repository":{"id":57103691,"uuid":"230532094","full_name":"ConjureLabs/dot-template","owner":"ConjureLabs","description":"templatized files in Node","archived":false,"fork":false,"pushed_at":"2024-07-15T16:25:03.000Z","size":255,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-05T00:34:17.947Z","etag":null,"topics":["flatfile","javascript-template-literals","node","templates"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ConjureLabs.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-27T23:25:50.000Z","updated_at":"2024-07-15T16:25:04.000Z","dependencies_parsed_at":"2024-07-15T19:45:27.459Z","dependency_job_id":"549f1c35-1a61-45b5-8917-7128184e957c","html_url":"https://github.com/ConjureLabs/dot-template","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConjureLabs%2Fdot-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConjureLabs%2Fdot-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConjureLabs%2Fdot-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConjureLabs%2Fdot-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ConjureLabs","download_url":"https://codeload.github.com/ConjureLabs/dot-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243738985,"owners_count":20340002,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flatfile","javascript-template-literals","node","templates"],"created_at":"2024-11-16T03:21:41.027Z","updated_at":"2026-01-02T07:54:30.398Z","avatar_url":"https://github.com/ConjureLabs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dot-template\n\n`dot-template` allows you to save templatized flatfiles, with added niceties\n\nthis library uses built-in [javascript template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals)\n\n## install\n\n```\nnpm install @conjurelabs/dot-template\n```\n\n## use\n\nsay you have the following file:\n\n_index.html_\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003ctitle\u003e${title}\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cdiv\u003eHello ${name}\u003c/div\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nyou can then use `dot-template` to pull up the file and pass arguments\n\n```js\nimport dotTemplate from '@conjurelabs/dot-template'\n\nasync function main() {\n  const template = dotTemplate('index.html')\n\n  const result = await template({\n    title: 'Conjure Labs',\n    name: 'Tim'\n  })\n\n  return result\n}\n```\n\n### subtemplates\n\nyou can embed subtemplates as well\n\n_index.html_\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003ctitle\u003e${title}\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    @divs(\u003cdiv\u003e${content}\u003c/div\u003e)\u0026()\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nin this example `divs` is expected to be an array of values, that will be passed into the subtemplate `\u003cdiv\u003e${content}\u003c/div\u003e`\n\n```js\nimport dotTemplate from '@conjurelabs/dot-template'\n\nasync function main() {\n  const template = dotTemplate('index.html')\n\n  const result = await template({\n    title: 'Conjure Labs',\n    divs: [{\n      content: 'Tim'\n    }, {\n      content: 'Marshall'\n    }]\n  })\n\n  return result\n}\n```\n\nthis will end up generating `\u003cdiv\u003eTim\u003c/div\u003e\u003cdiv\u003eMarshall\u003c/div\u003e`\n\nthe `\u0026()` is telling the subtemplate to join with an empty string\n\nyou can omit `\u0026()` - by default it will join subtemplates with `, `\n\n### missing variables\n\nif you attempt to fill a template, and a variable is missing, a `ReferenceError` will be thrown.\n\nthis is consistent with how javascript templates work.\n\n## custom template expressions\n\nin addition to `${regular}` expressions, you can add in your own 'handlers'\n\n```js\nimport dotTemplate from '@conjurelabs/dot-template'\n\ndotTemplate.addHandler({\n  // `expressionPrefix` is required\n  // this example would support `@{expression}`s\n  expressionPrefix: '@',\n\n  // mutates each value as it goes into the template\n  // templateArgs is the original {} values passed to template()\n  // additionalArgs is any other trailing args passed to template()\n  valueMutator: (value, templateArgs, ...additionalArgs) =\u003e value.toUppercase(),\n\n  // mutates each value, only when being console.log'd\n  // if this function is not set, the default return will\n  // be the value given by `valueMutator`\n  // templateArgs is the original {} values passed to template()\n  // additionalArgs is any other trailing args passed to template()\n  logMutator: (value, templateArgs, ...additionalArgs) =\u003e value.toLowercase(),\n\n  // mutates the entire values object,\n  // for both applied values and logged values\n  // useful if you need to Proxy `values\n  // type is either 'applied' or 'logged'\n  // additionalArgs is any other trailing args passed to template()\n  valuesObjectMutator: (values, type, ...additionalArgs) =\u003e new Proxy(value, {\n    get: (target, property) =\u003e {\n      const actualValue = Reflect.get(target, property)\n\n      if (type === 'logged') {\n        return actualValue.toLowercase()\n      } else {\n        return actualValue.toUppercase()\n      }\n    }\n  })\n})\n```\n\nhandlers are run in-order, after the built-in `${}`\n\n### usecase : redactions\n\na simple use of the difference between `valueMutator` and `logMutator` is when you want to redact sensitive data, like PII\n\nyou can support this easily:\n\n```js\ndotTemplate.addHandler({\n  expressionPrefix: '!',\n  logMutator: () =\u003e '\u003cREDACTED\u003e'\n})\n```\n\nnow, if you have a template like:\n\n```txt\nHello !{name},\nThank you for your purchase. Your credit card ending in !{ccLastFour} will be charged in two days.\n\nBest,\n${company}\n```\n\nthe filled in template will be as expected, while the value logged to terminal will be munged.\n\n```js\nconst template = dotTemplate('email.txt')\n\n// content is:\n/*\nHello Tim,\nThank you for your purchase. Your credit card ending in 4564 will be charged in two days.\n\nBest,\nConjure Labs\n */\nconst content = await template({\n  name: 'Tim',\n  ccLastFour: 4564,\n  company: 'Conjure Labs'\n})\n\n// prints to terminal:\n/*\nHello \u003cREDACTED\u003e,\nThank you for your purchase. Your credit card ending in \u003cREDACTED\u003e will be charged in two days.\n\nBest,\nConjure Labs\n */\nconsole.log(content)\n```\n\n### usecase : pg sql\n\nsee [pg-dot-template](https://github.com/ConjureLabs/pg-dot-template) for more","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconjurelabs%2Fdot-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconjurelabs%2Fdot-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconjurelabs%2Fdot-template/lists"}