Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

underscore-template-loader

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

underscore-template-loader - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

80

index.js
var _ = require('underscore');
var loaderUtils = require('loader-utils');
var path = require('path');
var fs = require('fs');
function resolveContent(content, root) {
var includeRegex = /<!--include\s+([\/\w\.]*?[\w]+\.[\w]+)-->/g;
var matches = includeRegex.exec(content);
module.exports = function() {
var loaderUtils = require('loader-utils');
var path = require('path');
var fs = require('fs');
var includeRegex = /<!--include\s+([\/\w\.]*?[\w]+\.[\w]+)-->/g;
var readFile = function(filepath, root) {
var self = readFile;
self.buffer = {} || self.buffer;
if (filepath in self.buffer) {
return self.buffer[filepath];
}
var content = resolveContent(fs.readFileSync(path.join(root, filepath), 'utf8'), root);
self.buffer[filepath] = content;
return self.buffer[filepath];
};
var readContent = function(content, root) {
var matches = includeRegex.exec(content);
while (matches != null) {
var file = loaderUtils.urlToRequest(matches[1]);
var basename = path.basename(file);
var dirname = path.join(root, path.dirname(file));
var rawContent = readFile(basename, dirname);
content = content.replace(matches[0], rawContent);
matches = includeRegex.exec(content);
}
while (matches != null) {
var file = loaderUtils.urlToRequest(matches[1]);
var rawContent = readFile(path.basename(file), path.join(root, path.dirname(file)));
content = content.replace(matches[0], rawContent);
matches = includeRegex.exec(content);
}
return content;
}
return content;
};
return function(content) {
this.cacheable && this.cacheable();
var callback = this.async();
content = readContent(content, this.context);
var fn = _.template(content);
callback(null, "module.exports = " + fn.source + ";");
};
}();
function readFile(filepath, root) {
var self = readFile;
if (typeof(self.buffer) == "undefined") {
self.buffer = {};
}
if (filepath in self.buffer) {
return self.buffer[filepath];
}
var content = resolveContent(fs.readFileSync(path.join(root, filepath), 'utf8'), root);
self.buffer[filepath] = content;
return self.buffer[filepath];
}
module.exports = function(content) {
this.cacheable && this.cacheable();
var callback = this.async();
content = resolveContent(content, this.context);
var fn = _.template(content);
callback(null, "module.exports = " + fn.source + ";");
};
module.exports._ = _;
module.exports._ = _;
{
"name": "underscore-template-loader",
"version": "0.2.1",
"version": "0.2.2",
"description": "A Underscore template loader for Webpack",

@@ -19,5 +19,7 @@ "main": "index.js",

"dependencies": {
"underscore": "^1.6.0",
"loader-utils": "^0.2.5"
},
"peerDependencies": {
"underscore": "^1.6.0"
},
"keywords": [

@@ -31,2 +33,2 @@ "underscore",

"readmeFilename": "README.md"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc