{"id":15681701,"url":"https://github.com/jonschlinkert/load-templates","last_synced_at":"2025-05-07T10:14:10.968Z","repository":{"id":19422626,"uuid":"22665165","full_name":"jonschlinkert/load-templates","owner":"jonschlinkert","description":"Load templates from file paths, globs or objects, and cache them as normalized objects.","archived":false,"fork":false,"pushed_at":"2018-03-05T08:56:24.000Z","size":305,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-14T09:06:56.339Z","etag":null,"topics":["filepath","glob","load","loader","templates","views"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","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/jonschlinkert.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-08-06T01:17:08.000Z","updated_at":"2021-04-12T22:27:04.000Z","dependencies_parsed_at":"2022-09-05T17:01:10.993Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/load-templates","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fload-templates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fload-templates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fload-templates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fload-templates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/load-templates/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249780393,"owners_count":21324533,"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":["filepath","glob","load","loader","templates","views"],"created_at":"2024-10-03T16:58:45.880Z","updated_at":"2025-04-19T19:34:07.384Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# load-templates [![NPM version](https://img.shields.io/npm/v/load-templates.svg?style=flat)](https://www.npmjs.com/package/load-templates) [![NPM monthly downloads](https://img.shields.io/npm/dm/load-templates.svg?style=flat)](https://npmjs.org/package/load-templates) [![NPM total downloads](https://img.shields.io/npm/dt/load-templates.svg?style=flat)](https://npmjs.org/package/load-templates) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/load-templates.svg?style=flat\u0026label=Travis)](https://travis-ci.org/jonschlinkert/load-templates)\n\n\u003e Load templates/views using globs, file paths, objects, arrays, or key-value pairs.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save load-templates\n```\n\n## Usage\n\nIn addition to what's shown in the below examples, if a glob pattern or valid filepath is passed, a `stat` object will be added to the `file` object as well.\n\n```js\nconst Loader = require('load-templates');\nconst loader = new Loader([options]);\nconst files = loader.load('*.hbs');\nconsole.log(files); //\u003c= object of vinyl files\n```\n\n## Supported formats\n\n```js\n// filepath\nloader.load('a/b/c/some-template.hbs'); \n\n// array of filepaths\nloader.load([\n  'a/b/c/some-template.hbs',\n  'a/b/c/other-template.hbs'\n]); \n\n// glob pattern\nloader.load('*.hbs'); \n\n// array of globs\nloader.load(['*.hbs', '*.tmpl']); \n\n// object\nloader.load({path: 'foo'});\n\n// key-value \nloader.load('d', {path: 'd'});\nloader.load('e', {path: 'e'});\nloader.load('f', {path: 'f'});\n\n// object of objects\nloader.load({\n  a: {path: 'a'},\n  b: {path: 'b'},\n  c: {path: 'c'}\n});\n\n// array of objects\nloader.load([\n  {path: 'a'},\n  {path: 'b'},\n  {path: 'c'}\n]);\n\n// array of nested objects\nloader.load([\n  {\n    a: {path: 'test/fixtures/a.md'},\n    b: {path: 'test/fixtures/b.md'},\n    c: {path: 'test/fixtures/c.md'},\n  },\n  {\n    d: {path: 'test/fixtures/d.md'},\n    e: {path: 'test/fixtures/e.md'},\n    f: {path: 'test/fixtures/f.md'},\n  }\n]);\n```\n\n## Options\n\n### options.cwd\n\nType: `String`\n\nDefault: `process.cwd()`\n\nPass the current working directory to use for resolving paths.\n\n### options.renameKey\n\nType: `Function`\n\nDefault: `file.path` The path that was given or globbed when the file was created.\n\nFunction to modify `file.key`, which is the property used for setting files on `loader.cache`.\n\n**Example**\n\n```js\nconst loader = new Loader({ renameKey: file =\u003e file.basename });\n```\n\nThis is functionally equivalent to:\n\n```js\nloader.cache[file.basename] = file;\n```\n\n### options.onLoad\n\nType: `Function`\n\nDefault: `undefined`\n\nFunction to run on each file before it's added to the cache.\n\n```js\nconst loader = new Loader({ \n  onLoad: file =\u003e {\n    // optionally return a new file, or just modify properties \n  }\n});\n```\n\n## API\n\n### [Loader](index.js#L31)\n\nCreate an instance of `Loader` with the given `options`.\n\n**Params**\n\n* `options` **{Object}**\n\n**Example**\n\n```js\nconst Loader = require('load-templates');\nconst loader = new Loader();\n```\n\n### [.load](index.js#L56)\n\nLoad one or more templates from a filepath, glob pattern, object, or array of filepaths, glob patterns or objects. This method detects the type of value to be handled then calls one of the other methods to do the actual loading.\n\n**Params**\n\n* `value` **{Object}**\n* `options` **{Object}**\n* `returns` **{Object}**: Returns the views from `loader.cache`\n\n**Example**\n\n```js\nconst loader = new Loader();\nconsole.log(loader.load(['foo/*.hbs', 'bar/*.hbs']));\nconsole.log(loader.load({path: 'a/b/c.md'}));\nconsole.log(loader.load('index', {path: 'a/b/c.md'}));\n```\n\n### [.addView](index.js#L97)\n\nCreate a view from the given `template` and cache it on `loader.cache`.\n\n**Params**\n\n* `template` **{String|Object}**\n* `options` **{Object}**\n* `returns` **{Object}**: Returns the `Loader` instance for chaining\n\n**Example**\n\n```js\nconst loader = new Loader();\nloader.addView('foo.hbs');\nconsole.log(loader.cache);\n```\n\n### [.addViews](index.js#L132)\n\nCreate from an array or object of `templates` and cache them on `loader.cache`.\n\n**Params**\n\n* `templates` **{Object}**\n* `options` **{Object}**\n\n**Example**\n\n```js\nconst loader = new Loader();\nloader.addViews([\n  {path: 'test/fixtures/a.md'},\n  {path: 'test/fixtures/b.md'},\n  {path: 'test/fixtures/c.md'},\n]);\nloader.addViews({\n  d: {path: 'test/fixtures/d.md'},\n  e: {path: 'test/fixtures/e.md'},\n  f: {path: 'test/fixtures/f.md'},\n});\nloader.addViews([{\n  g: {path: 'test/fixtures/g.md'},\n  h: {path: 'test/fixtures/h.md'},\n  i: {path: 'test/fixtures/i.md'},\n}]);\nconsole.log(loader.cache);\n```\n\n### [.createView](index.js#L184)\n\nCreate a `view` object from the given `template`. View objects are instances of [vinyl](https://github.com/gulpjs/vinyl).\n\n**Params**\n\n* `template` **{Object|String}**: Filepath or object with `path` or `contents` properties.\n* `options` **{Object}**\n* `returns` **{Object}**: Returns the view.\n\n**Example**\n\n```js\nconsole.log(loader.createView('test/fixtures/foo/bar.hbs'));\nconsole.log(loader.createView('foo/bar.hbs', {cwd: 'test/fixtures'}));\n```\n\n### [.globViews](index.js#L246)\n\nLoad templates from one or more glob `patterns` with the given `options`, then cache them on `loader.cache`.\n\n**Params**\n\n* `patterns` **{String|Array}**\n* `options` **{Object}**\n* `returns` **{Object}**: Returns `loader.cache`\n\n**Example**\n\n```js\nconst loader = new Loader();\nconst views = loader.globViews('*.hbs', {cwd: 'templates'});\n```\n\n## Release history\n\n**v2.0.0**\n\n* The `loaderFn` option has been deprecated and renamed to `onLoad`, use `options.onLoad` going forward.\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble \"Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit\")\n* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine… [more](https://github.com/jonschlinkert/templates) | [homepage](https://github.com/jonschlinkert/templates \"System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.\")\n* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb \"Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.\")\n\n### Contributors\n\n| **Commits** | **Contributor** | \n| --- | --- |\n| 220 | [jonschlinkert](https://github.com/jonschlinkert) |\n| 2 | [doowb](https://github.com/doowb) |\n\n### Author\n\n**Jon Schlinkert**\n\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on March 05, 2018._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fload-templates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fload-templates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fload-templates/lists"}