Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
a tpl engine for html template with directives attributes
npm install d-tpl
mocha test/test.js
if we have a HTML fragment with directives like this:
<div q-cname="test">
<div q-repeat="list | getList">
<div q-text="name" q-show="isShow" q-class="red: isRed, bold: size | isBold"></div>
<input type="text" q-value="pwd" />
<input type="checkbox" q-value="isCheck" />
<img src="" alt="" q-src="imgSrc" />
<img src="" alt="" q-attr="src: imgSrc, attrs"/>
<div q-text="list | insert 234 | length"></div>
</div>
</div>
we can compile it to a tpl fun with filters:
var tpl = require('d-tpl');
var src = getSrc(); // get the HTML fragment
var filters = require('./filters');
var tplFun = tpl.compile({
raw: src,
filters: filters
});
and the filters resource like this:
// filters.js
module.exports = {
test: {
getList: function(list) {
list.forEach(function(item) {
item.name += '_long';
});
return list;
},
isBold: function(size) {
return size > 10;
},
insert: function(list, item) {
list.push(item);
return list;
},
length: function(list) {
return list.length;
}
}
};
then, we can use this tpl function to output the HTML by datas:
var data = getData(); // get the data
var output = tplFun(data);
if the data like this:
// data.json
{
"test": {
"list": [{
"name": "Jack",
"isShow": true,
"isRed": true,
"size": 12,
"pwd": "123456",
"isCheck": true,
"imgSrc": "http://www.baidu.com/logo1.png",
"attrs": {
"width": 30,
"height": 30
},
"list": [1, 2, 3]
}, {
"name": "John",
"isShow": true,
"isRed": false,
"size": 12,
"pwd": "123451231236",
"isCheck": false,
"imgSrc": "http://www.baidu.com/logo2.png",
"attrs": {
"width": 300,
"height": 300
},
"list": [1, 2]
}, {
"name": "Anne",
"isShow": false,
"isRed": false,
"size": 7,
"pwd": "123412312356",
"isCheck": false,
"imgSrc": "http://www.baidu.com/logo3.png",
"attrs": {
"width": 300,
"height": 300
},
"list": [1, 2, 3, 222]
}]
}
}
we will get the HTML like this:
<div q-cname="test">
<div>
<div q-text="name" q-show="isShow" q-class="red: isRed, bold: size | isBold" style="display: block;" class="red bold">Jack_long</div>
<input type="text" q-value="pwd" value="123456">
<input type="checkbox" q-value="isCheck" checked>
<img src="http://www.baidu.com/logo1.png" alt="" q-src="imgSrc">
<img src="http://www.baidu.com/logo1.png" alt="" q-attr="src: imgSrc, attrs" width="30" height="30" >
<div q-text="list | insert 234 | length">4</div>
</div><div>
<div q-text="name" q-show="isShow" q-class="red: isRed, bold: size | isBold" style="display: block;" class=" bold">John_long</div>
<input type="text" q-value="pwd" value="123451231236">
<input type="checkbox" q-value="isCheck" >
<img src="http://www.baidu.com/logo2.png" alt="" q-src="imgSrc">
<img src="http://www.baidu.com/logo2.png" alt="" q-attr="src: imgSrc, attrs" width="300" height="300" >
<div q-text="list | insert 234 | length">3</div>
</div><div>
<div q-text="name" q-show="isShow" q-class="red: isRed, bold: size | isBold" style="display: none;" class=" ">Anne_long</div>
<input type="text" q-value="pwd" value="123412312356">
<input type="checkbox" q-value="isCheck" >
<img src="http://www.baidu.com/logo3.png" alt="" q-src="imgSrc">
<img src="http://www.baidu.com/logo3.png" alt="" q-attr="src: imgSrc, attrs" width="300" height="300" >
<div q-text="list | insert 234 | length">5</div>
</div>
</div>
FAQs
a tpl engine for html template with directives attributes
The npm package d-tpl receives a total of 0 weekly downloads. As such, d-tpl popularity was classified as not popular.
We found that d-tpl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.