Format with prettier

This commit is contained in:
Dan Mindru 2021-09-01 21:36:29 +02:00
parent 27d92ec469
commit 2387d542e7
1 changed files with 106 additions and 107 deletions

View File

@ -18,7 +18,7 @@ function inlineimg(options = {}) {
var attribute = options.attribute || 'src';
var getHTTP = options.getHTTP || false;
return through.obj(function (file, encoding, callback) {
return through.obj(function(file, encoding, callback) {
if (file.isStream()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!'));
return callback();
@ -33,7 +33,7 @@ function inlineimg(options = {}) {
var img_tags = inline_flag.length ? inline_flag : $(selector);
var count = 0;
img_tags.each(function () {
img_tags.each(function() {
var $img = $(this);
var src = $img.attr(attribute);
// Save the file format from the extension
@ -55,7 +55,7 @@ function inlineimg(options = {}) {
// Count async ops
count++;
getSrcBase64(options.basedir || file.base, getHTTP, src, function (err, result, res_format, skip_formatting) {
getSrcBase64(options.basedir || file.base, getHTTP, src, function(err, result, res_format, skip_formatting) {
if (err) {
console.error(err);
} else {
@ -91,7 +91,7 @@ function getHTTPBase64(url, callback) {
// Get applicable library
var lib = url.startsWith('https') ? https : http;
// Initiate a git request to our URL
var req = lib.get(url, (res) => {
var req = lib.get(url, res => {
// Check for redirect
if (res.statusCode >= 301 && res.statusCode < 400 && res.headers.location) {
// Redirect
@ -112,14 +112,14 @@ function getHTTPBase64(url, callback) {
var body = Buffer.from([]);
// Append each chunk to the body
res.on('data', (chunk) => body = Buffer.concat([body, chunk]));
res.on('data', chunk => (body = Buffer.concat([body, chunk])));
// Done callback
res.on('end', () => callback(null, body.toString('base64'), format));
});
// Listen for network errors
req.on('error', (err) => callback(err));
req.on('error', err => callback(err));
}
function getSrcBase64(base, getHTTP, src, callback) {
@ -128,8 +128,7 @@ function getSrcBase64(base, getHTTP, src, callback) {
var file_path = path.join(base, src);
if (fs.existsSync(file_path)) {
fs.readFile(file_path, 'base64', callback);
}
else {
} else {
callback(null);
}
} else {
@ -137,7 +136,7 @@ function getSrcBase64(base, getHTTP, src, callback) {
if (getHTTP) {
getHTTPBase64(src, callback);
} else {
callback(null, src, null, true)
callback(null, src, null, true);
}
}
}