jstransformer-twig
Advanced tools
Comparing version 1.7.0 to 1.16.0
# Changelog | ||
## v1.16.0: 2023-02-28 | ||
- Updated to twig 1.16.0 | ||
- Remove xo coding style constraints | ||
- Dropped support for Node < 8.0.0 | ||
## v1.7.0: 2020-10-07 | ||
@@ -4,0 +10,0 @@ |
86
index.js
@@ -9,6 +9,34 @@ 'use strict' | ||
exports.name = 'twig' | ||
exports.outputFormat = 'html' | ||
const loadModuleFilter = (name, filterModule, extendFunctionName) => { | ||
// Validate that we're loading an actual package. | ||
if (!validPackageName(filterModule).validForNewPackages) { | ||
return | ||
} | ||
exports.compile = function (input, options) { | ||
try { | ||
// Load the filter module. | ||
const out = require(filterModule) | ||
// Check if the module is just a function. | ||
if (typeof out === 'function') { | ||
Twig[extendFunctionName](name, out) | ||
} else if (out && (typeof out === 'object')) { | ||
// Perhaps it is an associative array of functions? | ||
for (const outName in out) { | ||
if (typeof out[outName] === 'function') { | ||
Twig[extendFunctionName](outName, out[outName]) | ||
} | ||
} | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
const transformer = { | ||
name: 'twig', | ||
outputFormat: 'html', | ||
} | ||
transformer.compile = function (input, options) { | ||
// Construct the Twig options. | ||
@@ -25,7 +53,3 @@ options = options || {} | ||
const pathRoot = options.root || options.path.root | ||
if (pathRoot) { | ||
options.path = path.join(pathRoot, path.format(options.path)) | ||
} else { | ||
options.path = path.format(options.path) | ||
} | ||
options.path = pathRoot ? path.join(pathRoot, path.format(options.path)) : path.format(options.path) | ||
} | ||
@@ -36,6 +60,6 @@ | ||
filters: 'extendFilter', | ||
functions: 'extendFunction' | ||
functions: 'extendFunction', | ||
} | ||
// eslint-disable-next-line guard-for-in | ||
for (const extendableName in extendable) { | ||
for (const extendableName of Object.keys(extendable)) { | ||
const extendFunctionName = extendable[extendableName] | ||
@@ -52,34 +76,8 @@ // Allow options.filters to be a require() string. | ||
// Loop through all the given filters. | ||
for (const name in options[extendableName] || {}) { | ||
if ({}.hasOwnProperty.call(options[extendableName], name)) { | ||
switch (typeof options[extendableName][name]) { | ||
case 'string': | ||
// Validate that we're loading an actual package. | ||
if (validPackageName(options[extendableName][name]).validForNewPackages) { | ||
try { | ||
// Load the filter module. | ||
const out = require(options[extendableName][name]) | ||
// Check if the module is just a function. | ||
if (typeof out === 'function') { | ||
Twig[extendFunctionName](name, out) | ||
} else if (out && (typeof out === 'object')) { | ||
// Perhaps it is an associative array of functions? | ||
for (const outName in out) { | ||
if (typeof out[outName] === 'function') { | ||
Twig[extendFunctionName](outName, out[outName]) | ||
} | ||
} | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
break | ||
case 'function': | ||
default: | ||
Twig[extendFunctionName](name, options[extendableName][name]) | ||
break | ||
} | ||
for (const name of Object.keys(options[extendableName] || {})) { | ||
const filter = options[extendableName][name] | ||
if (typeof filter === 'string') { | ||
loadModuleFilter(name, options[extendableName][name], extendFunctionName) | ||
} else if (typeof filter === 'function') { | ||
Twig[extendFunctionName](name, options[extendableName][name]) | ||
} | ||
@@ -104,1 +102,3 @@ } | ||
} | ||
module.exports = transformer |
{ | ||
"name": "jstransformer-twig", | ||
"version": "1.7.0", | ||
"version": "1.16.0", | ||
"description": "Twig.js support for JSTransformers.", | ||
"dependencies": { | ||
"twig": "^1.15.2", | ||
"validate-npm-package-name": "^3.0.0" | ||
"twig": "^1.16.0", | ||
"validate-npm-package-name": "^5.0.0" | ||
}, | ||
@@ -17,12 +17,10 @@ "keywords": [ | ||
"phone-formatter": "0.0.2", | ||
"slugify": "^1.4.5", | ||
"test-jstransformer": "^1.1.0", | ||
"xo": "*" | ||
"slugify": "^1.6.5", | ||
"test-jstransformer": "^1.1.0" | ||
}, | ||
"scripts": { | ||
"test": "test-jstransformer", | ||
"posttest": "xo --space=2 --no-semicolon index.js" | ||
"test": "test-jstransformer" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=8" | ||
}, | ||
@@ -37,3 +35,8 @@ "repository": { | ||
}, | ||
"license": "MIT" | ||
"license": "MIT", | ||
"xo": { | ||
"rules": { | ||
"unicorn/prefer-module": 0 | ||
} | ||
} | ||
} |
@@ -7,3 +7,2 @@ # jstransformer-twig | ||
[![Coverage Status](https://img.shields.io/codecov/c/github/jstransformers/jstransformer-twig/master.svg)](https://codecov.io/gh/jstransformers/jstransformer-twig) | ||
[![Dependency Status](https://img.shields.io/david/jstransformers/jstransformer-twig/master.svg)](http://david-dm.org/jstransformers/jstransformer-twig) | ||
[![NPM version](https://img.shields.io/npm/v/jstransformer-twig.svg)](https://www.npmjs.org/package/jstransformer-twig) | ||
@@ -10,0 +9,0 @@ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
3
7169
84
25
+ Addedvalidate-npm-package-name@5.0.1(transitive)
- Removedbuiltins@1.0.3(transitive)
- Removedvalidate-npm-package-name@3.0.0(transitive)
Updatedtwig@^1.16.0