🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

template-strings

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

template-strings - npm Package Compare versions

Comparing version
0.0.4
to
0.0.5
+1
cmd/index.js
module.exports = (template, data) => new Function('return `' + template + '`').call(data);
const fetch = require('node-fetch');
String.template = require('./index.js');
const template = '<div>Hello ${this.name}!</div>';
const json = { name: 'World' };
const html = String.template(template, json);
console.log(html);
const menuItems = [
'Home',
'About',
'Portfolio',
'Contact'
];
const menuItemTemplate = '<div class="item" itemprop="name"><a href="${this.menuItem}" itemprop="url">${this.menuItem}</a></div>';
const menuItemsHTML = menuItems.map(menuItem => String.template(menuItemTemplate, { menuItem })).join('');
console.log(menuItemsHTML);
const url = 'https://api.saoir.se/track/tidal/66522953';
const mediaItemTemplate = '${this.artist} - ${this.name}';
fetch(url).then(response => response.json())
.then(json => String.template(mediaItemTemplate, json))
.then(html => console.log(html));
/* Result: Eva Weel Skram - Selmas sang (fra Snøfall) */
export default function stringTemplator (template, data) {
return new Function('return `' + template + '`').call(data);
};
import fetch from 'node-fetch';
import stringTemplator from './index.mjs';
const template = '<div>Hello ${this.name}!</div>';
const json = { name: 'World' };
const html = stringTemplator(template, json);
console.log(html);
const menuItems = [
'Home',
'About',
'Portfolio',
'Contact'
];
const menuItemTemplate = '<div class="item" itemprop="name"><a href="${this.menuItem}" itemprop="url">${this.menuItem}</a></div>';
const menuItemsHTML = menuItems.map(menuItem => stringTemplator(menuItemTemplate, { menuItem })).join('');
console.log(menuItemsHTML);
const url = 'https://api.saoir.se/track/tidal/66522953';
const mediaItemTemplate = '${this.artist} - ${this.name}';
fetch(url).then(response => response.json())
.then(json => stringTemplator(mediaItemTemplate, json))
.then(html => console.log(html));
/* Result: Eva Weel Skram - Selmas sang (fra Snøfall) */
+16
-11
{
"name": "template-strings",
"version": "0.0.4",
"author": {
"name": "Jeremy Karlsson",
"email": "karlsson@jeremy.se"
},
"description": "String template",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"devDependencies": {
"node-fetch": "^1.6.3"
},

@@ -15,8 +16,12 @@ "keywords": [

],
"author": "Jeremy Karlsson <jeremy.karlsson@tidal.com>",
"license": "UNLICENCED",
"devDependencies": {
"node-fetch": "^1.6.3",
"whatwg-fetch": "^2.0.2"
}
"license": "MIT",
"main": "cmd/index.js",
"module": "esm/index.mjs",
"name": "template-strings",
"scripts": {
"test:node-esm": "node --experimental-modules esm/test.mjs",
"test:node-cmd": "node cmd/test.js",
"test": "npm run test:node-cmd && npm run test:node-esm"
},
"version": "0.0.5"
}

@@ -13,3 +13,3 @@ # Template Strings

Full usage example;
Usage example (Node);

@@ -27,2 +27,28 @@ ```

Usage example (Node ESM);
```
import stringTemplator from 'template-strings';
const template = '<div>Hello ${this.name}!</div>';
const json = { name: 'World' };
const html = String.template(template, json);
console.log(html);
```
Usage example (Browser ESM);
```
import stringTemplator from 'https://unpkg.com/template-strings?module';
const template = '<div>Hello ${this.name}!</div>';
const json = { name: 'World' };
const html = String.template(template, json);
console.log(html);
```
## Why?

@@ -29,0 +55,0 @@

Sorry, the diff of this file is not supported yet

module.exports = (template, data) => new Function('return `' + template + '`').call(data);
const fetch = require('node-fetch');
String.template = require('./index.js');
const template = '<div>Hello ${this.name}!</div>';
const json = { name: 'World' };
const html = String.template(template, json);
console.log(html);
const menuItems = [
'Home',
'About',
'Portfolio',
'Contact'
];
const menuItemTemplate = '<div class="item" itemprop="name"><a href="${this.menuItem}" itemprop="url">${this.menuItem}</a></div>';
const menuItemsHTML = menuItems.map(menuItem => String.template(menuItemTemplate, { menuItem })).join('');
console.log(menuItemsHTML);
const url = 'https://api.saoirse.audio/track/tidal/66522953';
const mediaItemTemplate = '${this.artist} - ${this.name}';
fetch(url).then(response => response.json())
.then(json => String.template(mediaItemTemplate, json))
.then(html => console.log(html));
/* Result: Eva Weel Skram - Selmas sang (fra Snøfall) */