{"name":"jazz","type":"module","description":"A minimalistic template engine with zero runtime dependency","keywords":["template"],"version":"1.2.0","homepage":"https://github.com/cliffano/jazz","author":{"name":"Cliffano Subagio","email":"blah@cliffano.com","url":"https://cliffano.com"},"contributors":[{"name":"All contributors","url":"https://github.com/cliffano/jazz/graphs/contributors"}],"main":"./lib/jazz.js","bin":{"jazz":"bin/jazz.js"},"preferGlobal":true,"repository":{"type":"git","url":"git+https://github.com/cliffano/jazz.git"},"bugs":{"url":"https://github.com/cliffano/jazz/issues"},"directories":{"bin":"./bin","lib":"./lib","test":"./test"},"devDependencies":{"@sinonjs/referee":"^11.0.2","esmock":"^2.7.6","sinon":"^22.1.0"},"scripts":{},"engines":{"node":">= 22.0.0"},"license":"MIT","gitHead":"39251410a9724cf642cb8569a68ad227413ea2f6","_id":"jazz@1.2.0","_nodeVersion":"26.7.0","_npmVersion":"11.19.0","dist":{"integrity":"sha512-v7N8W9wiD2gkdiaWsS6KSJjqiWoayrY/BL6DXUOBSle0EetSEX0uTiAk83Yc6zMl46bX3/Y0tb07H0TxSBfapg==","shasum":"85d4b6a516aef8ffaeceb8749bb58b47d778ff0c","tarball":"http://registry-npm.ywwl.com/jazz/download/jazz-1.2.0.tgz","fileCount":62,"unpackedSize":145447,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/jazz@1.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD9X+Q0PgHD2P5+OzSkdcx5lOYSZ3jDvvdYqsD4uBEVHgIhANVDcHzKyrh0S80KDY2ir3BcMrPnuFKt0JZTHLRyQuip"}],"size":39193,"noattachment":false,"key":"/jazz/-/jazz-1.2.0.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:9643200e-f3c6-4607-9e70-c8ae6357a94c"}},"maintainers":[{"name":"cliffano","email":"cliffano@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jazz_1.2.0_1787397947639_0.9408401442269987"},"_hasShrinkwrap":false,"readme":"<!-- BEGIN:AVATAR -->\n![Avatar](avatar.jpg)\n<!-- END:AVATAR -->\n\n<!-- BEGIN:BADGES -->\n[![Build Status](https://github.com/cliffano/jazz/workflows/CI/badge.svg)](https://github.com/cliffano/jazz/actions?query=workflow%3ACI)\n[![Dependencies Status](https://img.shields.io/librariesio/release/npm/jazz)](https://libraries.io/npm/jazz)\n[![Code Scanning Status](https://github.com/cliffano/jazz/workflows/CodeQL/badge.svg)](https://github.com/cliffano/jazz/actions?query=workflow%3ACodeQL)\n[![Coverage Status](https://coveralls.io/repos/github/cliffano/jazz/badge.svg?branch=main)](https://coveralls.io/r/cliffano/jazz?branch=main)\n[![Security Status](https://snyk.io/test/github/cliffano/jazz/badge.svg)](https://snyk.io/test/github/cliffano/jazz)\n[![Published Version](https://img.shields.io/npm/v/jazz.svg)](https://www.npmjs.com/package/jazz)\n<!-- END:BADGES -->\n\n# Jazz\n\nJazz is a minimalistic template engine with zero runtime dependency.\n\nOne of the OG template engines with first commit from 2010.\n\n## Installation\n\n```shell\nnpm install jazz\n```\n\n## Usage\n\n```javascript\nimport jazz from \"jazz\";\nimport sys from \"sys\";\n\nconst template = jazz.compile(\"my template source code {someVariable}\");\ntemplate.eval({\"someVariable\": \"lolmuffin\"}, function(data) { sys.puts(data); });\n```\n\nThis example would output the following:\n\n```text\nmy template source code lolmuffin\n```\n\n### Printing variables\n\n```text\n{someVariable}\n```\n\nThis works for any type of expression, so the following should also work:\n\n```text\n{users.fred}\n{\"hello\"}\n{45}\n{a eq b}\n```\n\n### Filter functions\n\nYou can call filter functions like so:\n\n```text\n{someFilter(arg1, arg2)}\n```\n\nFilter functions are statements, NOT expressions so they cannot be chained\nnor used in if/forelse/etc. tests. However, calls can be made on any type\nof expression -- e.g.\n\n```text\n{math.sin(45)}\n```\n\n### Implementing filter functions\n\nFilter functions may block so rather than returning the value you want\nrendered as you might in other frameworks, jazz passes in a callback to\nyour filter function that you then call to indicate that you have a\nresult. e.g. here we simulate a blocking operation using setTimeout().\n\n```text\n// sum.jazz\n\n{sum(5, 10)}\n```\n\n```javascript\n// sum.js\n\nimport jazz = from \"jazz\";\n\nconst params = {\n    sum: function(arg1, arg2, cb) {\n        setTimeout(function() {\n            cb((arg1 + arg2).toString());\n        }, 2000);\n    }\n}\njazz.compile(\"sum.jazz\").eval(params, function(output) { console.log(output); });\n```\n\nNote that even though the execution of the callback is delayed, this example still\nworks.\n\n### Conditional Statements\n\nYou can check if a variable evaluates to a true value like so:\n\n```text\n{if name}\n    Hello, {name}\n{end}\n```\n\nElse clauses are also supported:\n\n```text\n{if name}\n    Hello, {name}\n{else}\n    Hello, Captain Anonymous\n{end}\n```\n\nAs are else..if clauses:\n\n```text\n{if firstName}\n    Hello, {firstName}\n{elif lastName}\n    Hello, Mr. {lastName}\n{else}\n    Hello, Captain Anonymous\n{end}\n```\n\nLimited logical expressions are also possible:\n\n```text\n{if user.lastName and user.isVip}\n    Hello, Mr. {user.lastName}, my good man!\n{end}\n\n{if fred.tired or fred.bored}\n    Fred: \"Yawn!\"\n{end}\n\n{if not awake}\n    Zzz\n{end}\n```\n\neq & neq comparison operators are available for comparing two values:\n\n```text\n{if config.feature eq \"enabled\"}\n    Feature is enabled!\n{end}\n\n{if status neq \"inactive\"}\n    Huzzah!\n{end}\n```\n\nYou can also group expressions using parentheses:\n\n```text\n{if (a and b) or c}\n    ...\n{end}\n```\n\n### Looping over an array\n\n```html\n{foreach item in someArray}\n    <p>{item}</p>\n{end}\n```\n\nThe value being iterated over can be any expression supporting\nan Array-like interface.\n\n### Looping over an object\n\n```html\n{foreach pair in someObject}\n    <p>{pair.key} = {pair.value}</p>\n{end}\n```\n\n### Synchronous functions\n\n```html\n{if @blah('a')}\n    <p>There were so many blahs in a</p>\n{end}\n```\n\nThe function is provided to the template the same way asynchronous functions are, just with a return instead of a cb.\n\n### Loop counters / index\n\n```html\n{foreach pair in someObject}\n    <p>Loop number (1 based): {__count}</p>\n    <p>Index (0 based): {__index}</p>\n    <p>{pair.key} = {pair.value}</p>\n{end}\n```\n\n### Looking into arrays/objects\n\n```html\n<p>{object['array'][0].cheese}</p>\n```\n\n## Credits\n\nJazz was created by the brilliant Thomas Lee and Daniel Brain during the era of Shine Technologies early adoption of node.\n\n## Colophon\n\n<!-- BEGIN:DEVELOPERS_GUIDE -->\n[Developer's Guide](https:/cliffano.github.io/developers-guide-nodejs.html)\n<!-- END:DEVELOPERS_GUIDE -->\n\n<!-- BEGIN:BUILD_REPORTS -->\nBuild reports:\n\n* [Code complexity report](https://cliffano.github.io/jazz/complexity/plato/index.html)\n* [Unit tests report](https://cliffano.github.io/jazz/test/mocha.txt)\n* [Test coverage report](https://cliffano.github.io/jazz/coverage/c8/index.html)\n* [Integration tests report](https://cliffano.github.io/jazz/test-integration/mocha.txt)\n* [API Documentation](https://cliffano.github.io/jazz/doc/jsdoc/index.html)\n\n<!-- END:BUILD_REPORTS -->\n","publish_time":1787397947771,"_cnpm_publish_time":1787397947771,"dist-tags":{"latest":"1.2.0"}}