Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
knockout-template-helper
Advanced tools
A small node.js library that compresses a nested directory of html snippets into one knockout.js template.
A small node.js library that combines a master template and some knockout templates into one html file. This is very useful useful if you're writing applications with node and knockout.js.
The concept is fairly basic, a master template is an html document which must include a body tag, this is the page which hosts and makes use of your knockout templates.
A template file is an html document with one or more script tags representing a knockout template.
A template has an id attribute unique to its template file. Koth rewrites these ids to provide a dot-path namespace for templates, using the template filename, and directory names in the case of nested directories.
For instance, a directory of templates:
templates/common.html
templates/admin/users.html
with contents:
<!-- common.html -->
<script type="text/html" id="messages">
<div class="message">
<h3 data-bind="text: title">Message Title </h3>
<p data-bind="text: body">Message Body</p>
</div>
</script>
<script type="text/html" id="actions">
<ul class="actions" data-bind="foreach: actions" >
<a data-bind="attr: {href : url}, text: label">Action Label</li>
</ul>
</script>
<!-- users.html -->
<script type="text/html" id="groups">
<div class="group">
<h3 data-bind="text: name">Group name</h3>
<ul data-bind="foreach: members">
<li>...</li>
</ul>
</div>
</script>
Would remap these templates to make them available in master template like so:
<div data-bind="template: { name: 'common.messages', data: myMessages }"></div>
...
<div data-bind="template: { name: 'common.actions', data: actions }"></div>
...
<div data-bind="template: { name: 'admin.users.groups', data: groups }"></div>
This is a particularly simple way to manage templates with the added benefit of namespaces.
KOTH provides three ways to make use of its functionality:
For each of these there is a function which takes a directory of templates and sub-directories to compile, and a function which takes a mapping of {'dot.path.prefix' : '/absolute/file/path.html'}.
flatten(master, templates, callback)
combines a mapping of template files with a master template and calls the callback with the result as a string.
koth.flatten('index.html', {'admin.user' : '/path/to/file.html'}, function(out) {
console.log(out);
});
flattenDir(master, dir, callback)
combines a directory of template files with a master template and calls the callback with the result as a string.
koth.flattenDir('index.html', '/path/to/templates', function(out) {
console.log(out);
});
watch(master, templates, callback)
combines a mapping of template files with a master template and calls the callback with the result as a string initially and every time a file changes.
koth.watch('index.html', {'admin.user' : '/path/to/file.html'}, function(out) {
console.log(out);
});
watchDir(master, dir, callback)
combines a directory of template files with a master template and calls the callback with the result as a string initially and every time a file changes.
koth.watchDir('index.html', '/path/to/templates', function(out) {
console.log(out);
});
connectHandler(master, templates, watch, callback)
combines a mapping of template files with a master template and provides a connect resource handler which takes a request and response object and responds with the compiled result as a valid html response.
app = express.createServer();
koth.connectDirHandler('index.html', {'admin.user' : '/path/to/file.html'}, true, function(handler) {
app.get('/', handler);
app.listen(8000);
});
connectDirHandler(master, dir, watch, callback)
combines a directory of template files with a master template and provides a connect resource handler which takes a request and response object and responds with the compiled result as a valid html response.
app = express.createServer();
koth.connectDirHandler('index.html', '/path/to/templates', true, function(handler) {
app.get('/', handler);
app.listen(8000);
});
FAQs
A small node.js library that compresses a nested directory of html snippets into one knockout.js template.
The npm package knockout-template-helper receives a total of 0 weekly downloads. As such, knockout-template-helper popularity was classified as not popular.
We found that knockout-template-helper 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.