Socket
Book a DemoSign in
Socket

@tryghost/tpl

Package Overview
Dependencies
Maintainers
29
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tryghost/tpl - npm Package Compare versions

Comparing version
2.0.0
to
2.0.1
+9
-3
lib/tpl.js

@@ -1,2 +0,1 @@

const template = require('lodash.template');
const interpolate = /(?<!{){([^{]+?)}/g;

@@ -23,6 +22,13 @@

let processedString = string.replace(/\\{/g, '\\U+007B');
// Let lodash do its thing
processedString = template(processedString, {interpolate})(data);
// Interpolate {key} patterns with data values
processedString = processedString.replace(interpolate, (_match, key) => {
const trimmed = key.trim();
if (!(trimmed in data)) {
// eslint-disable-next-line ghost/ghost-custom/ghost-error-usage
throw new ReferenceError(`${trimmed} is not defined`);
}
return data[trimmed];
});
// Replace our swapped out left braces and any escaped right braces
return processedString.replace(/\\U\+007B/g, '{').replace(/\\}/g, '}');
};
{
"name": "@tryghost/tpl",
"version": "2.0.0",
"version": "2.0.1",
"repository": {

@@ -14,3 +14,3 @@ "type": "git",

"dev": "echo \"Implement me!\"",
"test": "NODE_ENV=testing c8 --all --check-coverage --100 --reporter text --reporter cobertura mocha './test/**/*.test.js'",
"test": "NODE_ENV=testing vitest run --coverage --config ../../vitest.config.ts",
"lint": "eslint . --ext .js --cache",

@@ -27,9 +27,5 @@ "posttest": "yarn lint"

"devDependencies": {
"c8": "11.0.0",
"mocha": "11.7.5",
"sinon": "21.0.1"
"sinon": "21.0.2"
},
"dependencies": {
"lodash.template": "4.5.0"
}
"dependencies": {}
}