{"id":22428482,"url":"https://github.com/momsfriendlydevco/template","last_synced_at":"2025-03-27T06:43:53.093Z","repository":{"id":57127887,"uuid":"191068136","full_name":"MomsFriendlyDevCo/template","owner":"MomsFriendlyDevCo","description":"Simple ES6 template renderer","archived":false,"fork":false,"pushed_at":"2023-02-16T05:09:16.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-22T15:50:17.860Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/MomsFriendlyDevCo.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-06-10T00:04:15.000Z","updated_at":"2023-02-16T04:17:18.000Z","dependencies_parsed_at":"2024-10-27T06:38:26.879Z","dependency_job_id":"e5f222ec-c7fa-4c81-83eb-396f21219775","html_url":"https://github.com/MomsFriendlyDevCo/template","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"34ccb749828198ee600c7d5f75b8a83f39fa37ae"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Ftemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Ftemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Ftemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Ftemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MomsFriendlyDevCo","download_url":"https://codeload.github.com/MomsFriendlyDevCo/template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245798538,"owners_count":20673901,"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":[],"created_at":"2024-12-05T20:14:56.433Z","updated_at":"2025-03-27T06:43:53.049Z","avatar_url":"https://github.com/MomsFriendlyDevCo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"@MomsFriendlyDevCo/Template\n===========================\nSimple ES6 template renderer.\n\nFeatures:\n\n* Optional compile step\n* Supports `{{handlebars}}` style formatting as well as `${es6Templates}}`\n* Supports dotted style adressing - even with arrays e.g. `{{foo.0.bar.1.baz}}`\n* Tiny with no-dependencies\n\n\n\n```javascript\nvar template = require('@momsfriendlydevco/template');\n\ntemplate('Hello ${name}`, {name: 'Matt'}) //= \"Hello Matt\"\ntemplate('Hello {{name}}`, {name: 'Matt'}) //= \"Hello Matt\" (same with handlebars syntax)\ntemplate('Random chance: ${Math.floor(100 * Math.random())}%') //= \"Random Chance: XX%\"\n```\n\n\nSafe undefined\n--------------\nBy default this module enables \"safe undefined\" variables, which means accessing any variable from the global scope which is not defined will simply return `undefined` rather than raise an error.\n\nThe objective here is that template expressions should be _forgiving_ and at least compile if a variable is not defined.\n\n\nFor example:\n\n```javascript\n// With the default {safeUndefined: true}\nvar template = require('@momsfriendlydevco/template');\ntemplate('${foo}', {}); //= \"undefined\"\ntemplate('${foo || 'Nope'}', {}); //= \"Nope\"\ntemplate('${foo ? 'Yes' : 'No'}', {}); //= \"No\"\ntemplate('${foo || bar || baz || 'Nothing'}', {baz: 'Baz!'}); //= \"Baz!\"\n```\n\n```javascript\n// With {safeUndefined: false}\nvar template = require('@momsfriendlydevco/template');\ntemplate('${foo}', {}); //= Raises an error \"foo is undefined\"\n// All of the above examples also raise as accessing \"foo\" is not available in the global scope\n```\n\n\n\nAPI\n===\nThis module exposes two main functions, the global will immediately execute a template and return its value, whereas `.compile()` will return a reusable function which can be called multiple times.\n\n\ntemplate(template, locals, options)\n-----------------------------------\nCompile and run the template using the provided locals.\nIf options are not provided they are imported from `template.defaults`.\n\n\ntemplate.compile(template, options)\n-----------------------------------\nCompile and return a function which can take different sets of locals.\n\n```javascript\nvar template = require('@momsfriendlydevco/template');\n\nvar compiled = template.compile('Hello ${name}');\ncompiled({name: 'Matt'}); //=\u003e 'Hello Matt'\ncompiled({name: 'Joe'})); //=\u003e 'Hello Joe'\n```\n\ntemplate.defaults\n-----------------\nDefault options to use.\n\n| Option          | Type      | Default        | Description                                                            |\n|-----------------|-----------|----------------|------------------------------------------------------------------------|\n| `globals`       | `Object`  | `{Date, Math}` | Global level objects to use when evaluating templates                  |\n| `dotted`        | `boolean` | `true`         | Enable dotted notation                                                 |\n| `handlebars`    | `boolean` | `true`         | Support simple handlebars syntax (e.g. `{{variable}}`)                 |\n| `script`        | `Object`  | `{}`           | Additional settings to pass to `vm.Script()` when compiling the script |\n| `safeUndefined` | `boolean` | `true`         | Wrap the context in a proxy so accessing top level undefined aliases doesn't throw |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomsfriendlydevco%2Ftemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmomsfriendlydevco%2Ftemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomsfriendlydevco%2Ftemplate/lists"}