{"id":16426745,"url":"https://github.com/toddmotto/interpolate","last_synced_at":"2025-03-21T04:30:35.221Z","repository":{"id":18405620,"uuid":"21587234","full_name":"toddmotto/interpolate","owner":"toddmotto","description":"Micro templating engine, maps Object property values to a String template","archived":false,"fork":false,"pushed_at":"2014-07-23T15:40:26.000Z","size":305,"stargazers_count":56,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-17T20:43:46.911Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toddmotto.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}},"created_at":"2014-07-07T21:22:29.000Z","updated_at":"2023-04-13T14:26:33.000Z","dependencies_parsed_at":"2022-08-28T19:01:19.647Z","dependency_job_id":null,"html_url":"https://github.com/toddmotto/interpolate","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddmotto%2Finterpolate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddmotto%2Finterpolate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddmotto%2Finterpolate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toddmotto%2Finterpolate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toddmotto","download_url":"https://codeload.github.com/toddmotto/interpolate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244738103,"owners_count":20501773,"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-10-11T08:10:10.273Z","updated_at":"2025-03-21T04:30:34.905Z","avatar_url":"https://github.com/toddmotto.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# interpolate.js [![Build Status](https://travis-ci.org/toddmotto/interpolate.svg)](https://travis-ci.org/toddmotto/interpolate)\n\nMicro templating engine module weighing \u0026lt;1KB, maps `Object` property values to a handlebar templated `String`. Returns a `closure` which calls a unique `Object` as single argument against the cached template. Doesn't compile to DOM nodes, merely interpolates to `String`, if you want to compile to live DOM [use this additional function](http://jsfiddle.net/toddmotto/2QZz4).\n\n\u003e [Live demo](http://jsfiddle.net/toddmotto/F4k2F)\n\n```javascript\nvar template = [\n  '\u003cli data-location=\"{{ location }}\"\u003e',\n    '{{ name }}',\n    '\u003cspan\u003e{{ age }}\u003c/span\u003e',\n  '\u003c/li\u003e'\n].join('');\n\nvar data = {\n  name: 'Todd Motto',\n  age: 23,\n  location: 'United Kingdom'\n};\n\n// \u003cli data-location=\"United Kingdom\"\u003eTodd Motto\u003cspan\u003e23\u003c/span\u003e\u003c/li\u003e\ninterpolate(template)(data);\n```\n\nThe initial `interpolate()` call caches the template internally, further calls will reference this template whilst mapping Object values:\n\n```javascript\nvar template = [\n  '\u003cli data-location=\"{{ location }}\"\u003e',\n    '{{ name }}',\n    '\u003cspan\u003e{{ age }}\u003c/span\u003e',\n  '\u003c/li\u003e'\n].join('');\n\nvar data = [{\n  name: 'Todd Motto',\n  age: 23,\n  location: 'United Kingdom'\n},{\n  name: 'Travis Barker',\n  age: 38,\n  location: 'United States'\n}];\n\nvar render = interpolate(template);\nfor (var i = 0; i \u003c data.length; i++) {\n  // iterated Objects called against same template\n  var done = render(data[i]);\n  // 0: \u003cli data-location=\"United Kingdom\"\u003eTodd Motto\u003cspan\u003e23\u003c/span\u003e\u003c/li\u003e\n  // 1: \u003cli data-location=\"United States\"\u003eTravis Barker\u003cspan\u003e38\u003c/span\u003e\u003c/li\u003e\n  console.log(done);\n}\n```\n\nSupport for deep Object properties is also there:\n\n```javascript\nvar template = [\n  '\u003cspan\u003e',\n    '{{ favourite.language }}',\n  '\u003c/span\u003e'\n].join('');\n\nvar data = {\n  favourite: {\n    language: 'JavaScript'\n  }\n}\n\nvar render = interpolate(template);\nconsole.log(render(data)); // \u003cspan\u003eJavaScript\u003c/span\u003e\n```\n\n## Installing with Bower\n\n```\nbower install https://github.com/toddmotto/interpolate.git\n```\n\n## Manual installation\nEnsure you're using the files from the `dist` directory (contains compiled production-ready code). Ensure you place the script before the closing `\u003c/body\u003e` tag.\n\n```html\n\u003cbody\u003e\n  \u003c!-- html above --\u003e\n  \u003cscript src=\"dist/interpolate.js\"\u003e\u003c/script\u003e\n  \u003cscript\u003e\n  // interpolate module available\n  \u003c/script\u003e\n\u003c/body\u003e\n```\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Gulp.\n\n## Release history\n\n- 1.1.0\n  - Add support for deep Object properties\n- 1.0.0\n  - Initial release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoddmotto%2Finterpolate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoddmotto%2Finterpolate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoddmotto%2Finterpolate/lists"}