{"_id":"@briandouglasie/literal-templates","_rev":"3-2df04313d513c11b7bb8ef03b5ae512d","name":"@briandouglasie/literal-templates","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@briandouglasie/literal-templates","version":"1.0.0","keywords":["view","engine","templates"],"author":{"name":"BrianDouglasIE"},"license":"Apache-2.0","_id":"@briandouglasie/literal-templates@1.0.0","maintainers":[{"name":"briandgls","email":"briandgls92@gmail.com"}],"dist":{"shasum":"533072131e735c1eb03aa967e6e21ab473cf1ff8","tarball":"https://registry.npmjs.org/@briandouglasie/literal-templates/-/literal-templates-1.0.0.tgz","fileCount":8,"integrity":"sha512-hfuQRD9SKh6RAjW9BpcoUE1K1zATpN2QElNvGemV4PVqiTNIuvGm0bA2knb3oNbBoFAYWlWcAZcEu1UgQzEDkw==","signatures":[{"sig":"MEUCIGEIaLwSj+cM5EDE9e4uQCMzduifmpKo5jJUgQ8B8+E1AiEAyOj9RL+btegQthBFsngAxV/fcspANImu7W28ILw/YM4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12460},"main":"engine.js","type":"module","gitHead":"6794f367a27d2c47c724e70db2cc4a00c9547146","private":false,"scripts":{"test":"node --test tests.js"},"_npmUser":{"name":"briandgls","email":"briandgls92@gmail.com"},"_npmVersion":"10.9.3","description":"JS template string view engine","directories":{},"_nodeVersion":"22.18.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/literal-templates_1.0.0_1755769013910_0.4992524789900794","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@briandouglasie/literal-templates","version":"1.0.1","keywords":["view","engine","templates"],"author":{"name":"BrianDouglasIE"},"license":"Apache-2.0","_id":"@briandouglasie/literal-templates@1.0.1","maintainers":[{"name":"briandgls","email":"briandgls92@gmail.com"}],"homepage":"https://github.com/BrianDouglasIE/literal-templates#readme","bugs":{"url":"https://github.com/BrianDouglasIE/literal-templates/issues"},"dist":{"shasum":"e9b6fc566988a9e2255e012022bd19a0083b1744","tarball":"https://registry.npmjs.org/@briandouglasie/literal-templates/-/literal-templates-1.0.1.tgz","fileCount":8,"integrity":"sha512-jDS0OhbtTzm7aL8mQwoTaDZfk2m2B4dKj54SQkSTy28UHmcMzOdO54QYHXl8QpteZI9aaLWGnU2chFc2J3wYSg==","signatures":[{"sig":"MEYCIQC7CImPmKIRinAahVtdn+GtyqtSrq0RV+qvJSfQhCbMywIhAIk7f62k+aQT8ls7DGoZiiov+cEk4s2p7Xsw5L2IuAeu","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12531},"main":"engine.js","type":"module","gitHead":"c6a81d2a88bdb5b1f28e9c463a54a3b95cf4f2a7","private":false,"scripts":{"test":"node --test tests.js"},"_npmUser":{"name":"briandgls","email":"briandgls92@gmail.com"},"repository":{"url":"git+https://github.com/BrianDouglasIE/literal-templates.git","type":"git"},"_npmVersion":"10.9.3","description":"JS template string view engine","directories":{},"_nodeVersion":"22.18.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/literal-templates_1.0.1_1755769093004_0.6603092710396594","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@briandouglasie/literal-templates","version":"1.0.2","description":"JS template string view engine","main":"engine.js","type":"module","types":"index.d.ts","private":false,"scripts":{"test":"node --test tests.js"},"repository":{"type":"git","url":"git+https://github.com/BrianDouglasIE/literal-templates.git"},"keywords":["view","engine","templates"],"author":{"name":"BrianDouglasIE"},"license":"Apache-2.0","_id":"@briandouglasie/literal-templates@1.0.2","gitHead":"795bff5ebdca955638cf242e2bf89509c402c46f","bugs":{"url":"https://github.com/BrianDouglasIE/literal-templates/issues"},"homepage":"https://github.com/BrianDouglasIE/literal-templates#readme","_nodeVersion":"22.17.1","_npmVersion":"11.5.2","dist":{"integrity":"sha512-jdICHhf7DtXTYZrG0Q/jIEtvnSUC7uytJKJ8R44fSQSAQ1fs/82I3aG/0pSaS1wRBIYPIEhFatueqYbhwISS6A==","shasum":"f14683a3b46764346326844916ebdd48821c2ffb","tarball":"https://registry.npmjs.org/@briandouglasie/literal-templates/-/literal-templates-1.0.2.tgz","fileCount":9,"unpackedSize":14237,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCLtzjKqdysBSsL1xJeGwOzLLjHQYniq8HfokAkRTA9mQIgBbuOK9c/u3d9W6GftfgnPuSXwwYa94GcfRsMKWDJsJ4="}]},"_npmUser":{"name":"briandgls","email":"briandgls92@gmail.com"},"directories":{},"maintainers":[{"name":"briandgls","email":"briandgls92@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/literal-templates_1.0.2_1757338002968_0.8891124256622682"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-21T09:36:53.780Z","modified":"2025-09-08T13:26:43.346Z","1.0.0":"2025-08-21T09:36:54.074Z","1.0.1":"2025-08-21T09:38:13.225Z","1.0.2":"2025-09-08T13:26:43.147Z"},"bugs":{"url":"https://github.com/BrianDouglasIE/literal-templates/issues"},"author":{"name":"BrianDouglasIE"},"license":"Apache-2.0","homepage":"https://github.com/BrianDouglasIE/literal-templates#readme","keywords":["view","engine","templates"],"repository":{"type":"git","url":"git+https://github.com/BrianDouglasIE/literal-templates.git"},"description":"JS template string view engine","maintainers":[{"name":"briandgls","email":"briandgls92@gmail.com"}],"readme":"# literal-templates\r\n\r\nA lightweight, flexible template engine for Node.js, offering dynamic registration and rendering of template views, includes, and helpers.\r\n\r\n## Features\r\n\r\n- **Views**: Register, render, or remove named template views.\r\n- **Includes**: Register reusable template snippets (\"includes\") and use them within your views.\r\n- **Helpers**: Register custom helper functions accessible in your templates.\r\n- **Directory Registration**: Bulk-register views or includes from a directory of files.\r\n- **Template Compilation**: Templates are compiled to JavaScript functions for efficiency, using ES6 template literals for variable interpolation.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @briandouglasie/literal-templates\r\n```\r\n\r\n## Usage\r\n\r\n### Basic Example\r\n\r\n```js\r\nimport {\r\n  registerView,\r\n  view,\r\n  registerHelper,\r\n  create\r\n} from '@briandouglasie/literal-templates'\r\n\r\n// Register a helper\r\nregisterHelper('upper', str => str.toUpperCase())\r\n\r\n// Register a view\r\nregisterView('greeting', create('Hello ${data.name}!'))\r\n\r\n// Render the view\r\nconsole.log(view('greeting', { name: 'World' })) // Output: Hello World!\r\n```\r\n\r\n### Registering Views and Includes from Directories\r\n\r\nYou can bulk-register all `.html` files in a directory as views or includes:\r\n\r\n```js\r\nimport { registerViewDir, registerIncludeDir } from '@briandouglasie/literal-templates'\r\n\r\nawait registerViewDir('./views')    // Registers all .html files as views\r\nawait registerIncludeDir('./includes') // Registers all .html files as includes\r\n```\r\n\r\n## API Reference\r\n\r\n### Views\r\n\r\n- **registerView(name, func)**: Register a new view by name.\r\n- **removeView(name)**: Remove a view by name.\r\n- **clearViews()**: Remove all registered views.\r\n- **getViews()**: Get a shallow copy of all registered views.\r\n- **registerViewDir(dirPath, recursive = true, ext = '.html')**: Register all files with the given extension from a directory as views.\r\n- **view(name, vars)**: Render a view with the provided variables.\r\n\r\n### Includes\r\n\r\n- **registerInclude(name, func)**: Register a new include by name.\r\n- **removeInclude(name)**: Remove an include by name.\r\n- **clearIncludes()**: Remove all registered includes.\r\n- **getIncludes()**: Get a shallow copy of all registered includes.\r\n- **registerIncludeDir(dirPath, recursive = true, ext = '.html')**: Register all files with the given extension from a directory as includes.\r\n\r\n### Helpers\r\n\r\n- **registerHelper(name, func)**: Register a new helper function.\r\n- **removeHelper(name)**: Remove a helper by name.\r\n- **clearHelpers()**: Remove all registered helpers.\r\n- **getHelpers()**: Get a shallow copy of all registered helpers.\r\n\r\n### Templates\r\n\r\n- **create(template, varNames = ['data'])**: Compile a template string into a render function.\r\n    - `template`: The template string (can use `${}` for variable interpolation).\r\n    - `varNames`: Array of argument names passed to the template (default: `['data']`).\r\n    - Helpers and includes are always available as `helpers` and `include` in the template context.\r\n\r\n## Template Syntax\r\n\r\nTemplates use [ES6 template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) for variable interpolation:\r\n\r\n```js\r\ncreate('Hello ${data.name}, today is ${helpers.upper(data.day)}!')\r\n```\r\n\r\n- `helpers`: Access any registered helper functions.\r\n- `include(name, vars)`: Render an include (only available within templates).\r\n- Variables are passed as the first argument (`data` by default) when rendering.\r\n\r\n## Example: Using Includes and Helpers\r\n\r\nSuppose you have the following in `includes/header.html`:\r\n\r\n```html\r\n<h1>${helpers.upper(data.title)}</h1>\r\n```\r\n\r\nRegister and use it:\r\n\r\n```js\r\nawait registerIncludeDir('./includes')\r\nconst template = create('${include(\"header\", { title: data.header })} Hello, ${data.name}!')\r\nconsole.log(template({ header: 'welcome', name: 'Alice' }))\r\n// Output: <h1>WELCOME</h1> Hello, Alice!\r\n```\r\n\r\n## License\r\n\r\nSee [LICENSE](./LICENSE) for details.\r\n","readmeFilename":"README.md"}