Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Browserify middleware to be able to require() text files (including templates) inside of your client-side JavaScript files.
Browserify plugin to require() text files (like templates) inside of your client-side JavaScript files.
npm install stringify
Setup Browserify to use this middleware in your app:
var browserify = require('browserify'),
stringify = require('stringify');
var bundle = browserify()
.use(stringify(['.hjs', '.html', '.whatever']))
.addEntry('my_app_main.js');
app.use(bundle);
You might have noticed that you can pass stringify an optional array of file-extensions that you want to require() in your Browserify packages as strings. By default these are used: .html, .txt, .text, and .tmpl
NOTE: You MUST call this as I have above. The Browserify .use() method HAS to plug this middleware in to Browserify BEFORE you add the entry point (your main client-side file) for Browserify.
Now, in your clientside files you can use require() as you would for JSON and JavaScript files, but include text files that have just been parsed into a JavaScript string:
var my_text = require('../path/to/my/text/file.txt');
console.log(my_text);
The reason I created this was to get string versions of my Handlebars templates required in to my client-side JavaScript. You can theoretically use this for any templating parser though.
Here is how that is done:
application.js:
var browserify = require('browserify'),
stringify = require('stringify');
var bundle = browserify()
.use(stringify(['.hbs', '.handlebars']))
.addEntry('my_app_main.js');
app.use(bundle);
my_app_main.js:
var Handlebars = require('handlebars'),
template = require('my/template/path.hbs'),
data = require('data.json');
var hbs_template = Handlebars.compile(template);
// Now I can use hbs_template like I would anywhere else, passing it data and getting constructed HTML back.
var constructed_template = hbs_template(data);
/*
Now 'constructed_template' is ready to be appended to the DOM in the page!
The result of it should be:
<p>This is my string!</p>
*/
my/template/path.hbs:
<p>{{ json_data }}</p>
data.json
{
"json_data": "This is my string!"
}
FAQs
Browserify middleware to be able to require() text files (including templates) inside of your client-side JavaScript files.
The npm package stringify receives a total of 22,012 weekly downloads. As such, stringify popularity was classified as popular.
We found that stringify 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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.