{"id":24383236,"url":"https://github.com/firstandthird/hapi-nunjucks-helpers","last_synced_at":"2025-07-25T20:36:17.796Z","repository":{"id":53677799,"uuid":"72674980","full_name":"firstandthird/hapi-nunjucks-helpers","owner":"firstandthird","description":"Helpers for clientkit","archived":false,"fork":false,"pushed_at":"2021-03-19T16:27:35.000Z","size":110,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-29T12:39:35.162Z","etag":null,"topics":["hapi-plugin","hapi-v17"],"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/firstandthird.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":"2016-11-02T19:40:29.000Z","updated_at":"2021-03-19T16:27:35.000Z","dependencies_parsed_at":"2022-09-14T08:13:48.259Z","dependency_job_id":null,"html_url":"https://github.com/firstandthird/hapi-nunjucks-helpers","commit_stats":null,"previous_names":["firstandthird/clientkit-helpers"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/firstandthird/hapi-nunjucks-helpers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-nunjucks-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-nunjucks-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-nunjucks-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-nunjucks-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firstandthird","download_url":"https://codeload.github.com/firstandthird/hapi-nunjucks-helpers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fhapi-nunjucks-helpers/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267057638,"owners_count":24028866,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["hapi-plugin","hapi-v17"],"created_at":"2025-01-19T10:13:57.648Z","updated_at":"2025-07-25T20:36:17.724Z","avatar_url":"https://github.com/firstandthird.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hapi-nunjucks-helpers\n\nA library of useful [nunjucks](https://mozilla.github.io/nunjucks/) helpers and filters, with a wrapper for use with [hapi](https://hapi.dev/)\n\n## Installation\n\n```\nnpm install hapi-nunjucks-helpers\n```\n\n## Usage\n\nhapi-nunjucks-helpers is designed to work with [vision](https://github.com/hapijs/vision) and\n[vision-nunjucks](https://github.com/firstandthird/vision-nunjucks), you just need to make sure to tell nunjucks to compile the helpers in 'async' mode:\n\n```js\nawait server.register(require('vision'));\n\nserver.views({\n  engines: {\n    njk: require('vision-nunjucks')\n  },\n  path: '/views',\n  isCached: false,\n  compileMode: 'async'\n});\n\nawait server.register(require('hapi-nunjucks-helpers'));\n```\n\nIs all you need to do, all of the following helpers will then be available for use in your views:\n\n## Asset Helper\n\n  When you register the plugin you can pass options to configure how your assets filter will work:\n\n```js\nawait server.register({\n  plugin: require('hapi-nunjucks-helpers'),\n  options: {\n    assets: {\n      endpoint: 'http://localhost:8080/',\n      cdn: 'http://localhost',\n      mappingFile: 'assets-map.json'\n    }\n  }\n});\n```\n  These options are as follows:\n\n  - `endpoint` The base asset directory, default is none.\n\n  - `dist` The root directory under _endpoint_ where compiled asset files reside, so `assets` will look for compiled asset files in the directory specified by _${endpoint}/${dist}_. Default is none.\n\n  - `mappingFile` A JSON file containing the map of source files to their corresponding hashed assets, this file should look like:\n    ```JS\n    {\n      \"common.js\": \"common.0d5714f897be66e21c18.js\",\n      \"common.css\": \"common.f7f029f8ee35aec7a7f6.css\",\n      \"script.js\": \"script.68e5e334aa4dcb31eece.js\"\n      ...\n    }\n    ```\n  - `cdn` - Optional CDN domain for assets. Default: none.\n  - `cache` - If `true`, caches contents of `mappingFile`. Default: `false` (you will generally want to leave cacheing off during development)\n\n## Filters:\n\n**asset**\n\nReads from the mapping file if available:\n\n```html\n\u003cscript src=\"{{ 'common.js' | asset }}\"\u003e\u003c/script\u003e\n```\n\nAlso possible to pass a version to force new fetch from cache:\n\n```html\n\u003cscript src=\"{{ 'common.js' | asset(2) }}\"\u003e\u003c/script\u003e\n\u003c!-- /common.js?v=2 ?\u003e\n```\n\n\n\n**cdn**\n\nPrefixes asset with cdn path taken from the `assets.cdn` property:\n\n```html\n\u003cimg src=\"{{ 'logos/logo.png' | cdn }}\"\u003e\n```\n\nWith css/js\n\n```html\n\u003cscript src=\"{{ 'common.js' | asset | cdn }}\"\u003e\u003c/script\u003e\n```\n\n**copyBlock**\n\nWill transform an array of text items into paragraph blocks, and optionally insert a css _class_ for the paragraphs:\n\nIf you have a context like:\n\n```js\n{ paragraphs: ['hello world', 'goodbye world'] }\n```\n\nand a view like:\n\n```\n{{ paragraph | copyBlock | safe }}\n{{ paragraph | copyBlock('bold') | safe }}\n```\n\nThis will result in:\n\n```html\n\u003cp\u003ehello world\u003c/p\u003e\u003cp\u003egoodbye world\u003c/p\u003e\n\u003cp class=\"bold\"\u003ehello world\u003c/p\u003e\u003cp class=\"bold\"\u003egoodbye world\u003c/p\u003e\n```\n\n**date**\n\nFormats a date-string with momentjs\n\n```html\nFrom Now: {{ new Date | date }}\nFormat String: {{ new Date | date(\"YYYY MM DD\") }}\n```\n\n**exclude**\n\nAllows you to filter items from an array based on whether they match a particular field or not.\n\nIf you have a context like:\n```js\n{\n  items: [\n    { name: 'mango', type: 'fruit' },\n    { name: 'peach', type: 'fruit' },\n    { name: 'lettuce', type: 'vegetable' }\n    { name: 'pineapple', type: 'fruit' },\n    { name: 'cucumber', type: 'vegetable' }\n  ],\n  exclude: [\n    { type: 'vegetable' }\n  ]\n}\n```\n\nthen you can call the exclude filter like this:\n```\n{% for entry in items | exclude(exclude, 'type') %}{{ entry.name }}{% endfor %}\n```\n\nand it will print out: ```mangopeachpineapple```.\n\n**inline**\n\nTakes a file and spits out the contents, very useful for when you want to have inline JS and CSS:\n\n```html\n\u003cscript\u003e{{ 'common.js' | inline }}\u003c/script\u003e\n```\n\n**securify**\n\nIf the plugin was registered with the `secureLinks: true` option, this will replace 'http' with 'https' in your embedded links, otherwise it will do nothing.  Useful for testing local links in a development environment.\n\n```js\nawait server.register({\n  plugin: require('hapi-nunjucks-helpers'),\n  options: {\n    secureLinks: true\n  }\n});\n```\n\nwill cause:\n```\n{{ 'http://myhost.com' | securify }}\n{{ 'http://myotherhost.com' | securify }}\n```\n\nto be rendered as:\n\n```\nhttps://myhost.com\nhttps://myotherhost.com\n```\n\n**slugify**\n\nSlugifies a string.  All chars are made lowercase, all spaces replaced with `-`, funny symbols are removed and the string is trimmed:\n\n```\n{{ '  hello@@  WORLD-!' | slugify }}\n```\n\nwill render as `hello-world`\n\n**script**\n\nRenders script tags using the `cdn` value, you can also ask it to 'defer' loading the script:\n\n```js\nawait server.register({\n  plugin: require('hapi-nunjucks-helpers'),\n  options: {\n    assets: {\n      cdn: 'http://localhost'\n    }\n  }\n});\n```\n\nand\n\n```\n{{ 'test.js' | script | safe }}\n{{ 'test2.js' | script(true) | safe }}\n```\n\nresults in:\n```html\n\u003cscript src=\"http://localhost/test.js\" crossorigin=\"anonymous\"\u003e\u003c/script\u003e\n\u003cscript src=\"http://localhost/test2.js\" crossorigin=\"anonymous\" defer\u003e\u003c/script\u003e\n```\n\n\n**style**\n\nJust like `script`, except renders style tags:\n\n```{{ 'test.css' | style }}```\n\nwill output:\n\n```html\n\u003clink rel=\"stylesheet\" href=\"http://localhost/test.css\"\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-nunjucks-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirstandthird%2Fhapi-nunjucks-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fhapi-nunjucks-helpers/lists"}