Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jstransformer-nunjucks

Package Overview
Dependencies
Maintainers
7
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jstransformer-nunjucks

Nunjucks support for JSTransformers

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.4K
increased by5.67%
Maintainers
7
Weekly downloads
 
Created
Source

jstransformer-nunjucks

Nunjucks support for JSTransformers.

Build Status Coverage Status NPM version

Installation

npm install jstransformer-nunjucks

API

const jstransformer = require('jstransformer')
const nunjucks = jstransformer(require('jstransformer-nunjucks'))

nunjucks.render('Hello, {{ name }}!', {name: 'World'}).body
//=> 'Hello, World!'

const options = {
  filters: { repeat: (str, num) => str.repeat(n || 2) }
};

nunjucks.render(
  '{{ "Hello, " | repeat(echoes + 1) }}{{ name }}!',
  options,
  {name: 'World', echoes: 2}
).body

//=> 'Hello, Hello, Hello, World!'

See the JSTransformers documentation for other API methods.

By default, this transformer matches the .njk and .nunjucks input file extensions, and outputs .html.

Available options

Many of the API methods accept an options dictionary object. The following option keys are supported:

  • filename: The filename and path of the Nunjucks template being compiled. Default is null, which disables any imports or includes using relative path names.

  • root: The base path used to configure the Nunjucks environment. This defines the highest-level directory that can be searched for templates and macros. Any import or include references to files outside this root directory will fail. Default is to use the parent directory of the filename path, if it is specified, or null (which causes Nunjucks to default to the current working directory).

  • path: Alternative name for root.

  • filters: A set of custom Nunjucks filters to add. The value of filters should be a dictionary object where the keys are the filter names to use in the templates. The dictionary values define the filter functions, either as JavaScript function objects, or as the name of a Node module (as a string). If you specify a module name, that module's default export will be used as the filter function.

  • extensions: A set of Nunjucks extensions to add. The value of extensions should be a dictionary object where the keys are the extension names to use in the templates. The dictionary values define the extension functions, either as JavaScript function objects, or as the name of a Node module (as a string).

  • globals: A set of global variables available to all templates. The value of globals is a dictionary object defining the keys and values of the global data properties.

  • Any other options supported by Nunjuck's configure method.

License

MIT

Keywords

FAQs

Package last updated on 18 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc