template-strings
Advanced tools
| module.exports = (template, data) => new Function('return `' + template + '`').call(data); |
+31
| 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); | ||
| }; |
+30
| 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" | ||
| } |
+27
-1
@@ -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
-1
| module.exports = (template, data) => new Function('return `' + template + '`').call(data); |
-31
| 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) */ |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Misc. License Issues
LicenseA package's licensing information has fine-grained problems.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
Unidentified License
LicenseSomething that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
5459
41.79%1
-50%6
20%0
-100%0
-100%46
109.09%2
-33.33%112
30.23%9
125%