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

templyte

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

templyte - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

22

index.js

@@ -0,1 +1,3 @@

'use strict';
const escapeStringRegexp = require('escape-string-regexp');

@@ -15,3 +17,3 @@

*/
module.exports.renderString = function(str, data, delimiters) {
module.exports.renderString = function renderString(str, data, delimiters) {
let renderedStr = str;

@@ -29,12 +31,18 @@

while((entries = extractVarPattern.exec(renderedStr)) !== null) {
if(!data.hasOwnProperty(entries[1])) {
throw entries[1] +' is not defined';
const variables = renderedStr.match(extractVarPattern);
if (variables === null) {
return str;
}
for(let i = 0; i < variables.length; i++) {
entries = extractVarPattern.exec(str);
const attr = entries[1];
if(!data.hasOwnProperty(attr)) {
throw attr +' is not defined';
}
const itemPattern = new RegExp(d[0] + '\\s*' + entries[1] + '\\s*' + d[1], 'gm');
renderedStr = renderedStr.replace(itemPattern, data[entries[1]]);
const itemPattern = new RegExp(d[0] + '\\s*' + attr + '\\s*' + d[1], 'gm');
renderedStr = renderedStr.replace(itemPattern, data[attr]);
}
return renderedStr;
};
};
{
"name": "templyte",
"version": "1.0.0",
"version": "1.0.1",
"description": "Simple Javascript string template. Useful for simple string translations and text replacing.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -0,0 +0,0 @@ # templyte

@@ -107,2 +107,9 @@ 'use strict';

});
it('should render a url query string', () => {
params = {lang: 'es', q: 'google'};
const output = templyte.renderString('https://encrypted.google.com/search?hl={{lang}}&q={{q}}', params);
const expectedString = 'https://encrypted.google.com/search?hl=es&q=google';
expect(output).toEqual(expectedString);
});
});

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