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

template-file

Package Overview
Dependencies
Maintainers
10
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

template-file - npm Package Compare versions

Comparing version 5.0.0 to 5.0.1

24

dist/index.js

@@ -34,8 +34,20 @@ "use strict";

exports.renderGlob = renderGlob;
const tagRegEx = /\{\{\s*(.*?)\s*\}\}/g;
const sectionRegEx = /\{\{\s*(?:#(.*?))\s*\}\}\n*([\s\S]*?)\s*\{\{\s*\/\1\s*\}\}/g;
const combinedRegEx = new RegExp(`${sectionRegEx.source}|${tagRegEx.source}`, 'g');
function getTemplateRegEx() {
const anything = '([\\s\\S]*?)';
const optionalNewLines = '\\n*';
const optionalWhitespace = '\\s*';
const spaceNotNewLines = `[ \t]*`;
const tagStart = `{{${optionalWhitespace}`;
const tagEnd = `${optionalWhitespace}}}`;
const sectionStart = `${spaceNotNewLines}${tagStart}(?:#(.*?))${tagEnd}${optionalNewLines}`;
const sectionEnd = `${optionalWhitespace}${tagStart}\\/\\1${tagEnd}`;
const repeatingSectionTag = `${sectionStart}${anything}${sectionEnd}`;
const replacementTag = `${tagStart}(.*?)${tagEnd}`;
const combinedRegEx = new RegExp(`${repeatingSectionTag}|${replacementTag}`, 'g');
return combinedRegEx;
}
function render(template, data) {
return template.replace(combinedRegEx, (_match, sectionTag, sectionContents, basicTag) => {
// Tag is for an array section
const templateRegEx = getTemplateRegEx();
return template.replace(templateRegEx, (_match, sectionTag, sectionContents, replacementTag) => {
// Tag is for a repeating section
if (sectionTag !== undefined) {

@@ -49,3 +61,3 @@ const replacements = deep_1.get(sectionTag, data);

}
const replacement = deep_1.get(basicTag, data);
const replacement = deep_1.get(replacementTag, data);
// If a template variable is found but nothing is supplied to fill it, remove it

@@ -52,0 +64,0 @@ if (replacement === null || replacement === undefined) {

{
"name": "template-file",
"version": "5.0.0",
"version": "5.0.1",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "description": "🔀 Replace {{ variables }} in all your files",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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