Skip to content

Commit

Permalink
Fix JSDoc to match Nunjucks filter log
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Nov 30, 2023
1 parent 14dc963 commit d82277b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/filters/core-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
const { runWhenEnvIsAvailable, external } = require('./api')
const { addFilter, getFilter } = external

/**
* Logs an object in the template to the console in the browser.
* @param {Any} a any type
* @return {String} a script tag with a console.log call.
* @example {{ "hello world" | log }}
* @example {{ "hello world" | log | safe }} [for environments with autoescaping turned on]
*/
runWhenEnvIsAvailable(() => {
const nunjucksSafe = getFilter('safe')
addFilter('log', a => nunjucksSafe('<script>console.log(' + JSON.stringify(a, null, '\t') + ');</script>'))

addFilter(
'log',
/**
* Logs an object in the template to the console in the browser.
*
* @example
* ```njk
* {{ "hello world" | log }}
* ```
* @param {any} a - any type
* @returns {string} a script tag with a console.log call.
*/
a => nunjucksSafe('<script>console.log(' + JSON.stringify(a, null, '\t') + ');</script>'))
})

0 comments on commit d82277b

Please sign in to comment.