Code style

This commit is contained in:
nobody 2021-12-05 07:30:31 +01:00
parent aa521e879e
commit 10c0887057
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
4 changed files with 36 additions and 24 deletions

View File

@ -141,13 +141,14 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) {
manipulateDOM._searchCharset = function (str, charset) {
if (str.indexOf(`charset="${charset}"`) > 0) {
return str.replace(`charset="${charset}"`, 'charset="utf8"');
} else if (str.indexOf(`charset='${charset}'`) > 0) {
return str.replace(`charset='${charset}'`, 'charset=\'utf8\'');
} else if (str.indexOf(`charset=${charset}`) > 0) {
return str.replace(`charset=${charset}`, 'charset=utf8');
} else {
return str;
}
if (str.indexOf(`charset='${charset}'`) > 0) {
return str.replace(`charset='${charset}'`, 'charset=\'utf8\'');
}
if (str.indexOf(`charset=${charset}`) > 0) {
return str.replace(`charset=${charset}`, 'charset=utf8');
}
return str;
};
/**

View File

@ -106,7 +106,7 @@ requestAnalyzer.getLocalTarget = function (requestDetails, initiator) {
};
}
basePath = requestAnalyzer._matchBasePath(hostMappings, destinationPath);
basePath = requestAnalyzer._matchBasePath(hostMappings, destinationPath)['result'];
resourceMappings = hostMappings[basePath];
if (!resourceMappings) {
@ -135,11 +135,15 @@ requestAnalyzer.getLocalTarget = function (requestDetails, initiator) {
requestAnalyzer._matchBasePath = function (hostMappings, channelPath) {
for (let basePath of Object.keys(hostMappings)) {
if (channelPath.startsWith(basePath)) {
return basePath;
return {
'result': basePath,
};
}
}
return false;
return {
'result': false,
};
};
// eslint-disable-next-line max-len
@ -165,7 +169,7 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
}
shorthandResource = shorthands.specialFiles(channelHost, channelPath, destinationSearchString);
if (shorthandResource) {
if (shorthandResource['result'] !== false) {
if (requestAnalyzer.logging) {
console.log(`${LogString.PREFIX} ${LogString.REPLACED_RESOURCE} ${shorthandResource.path}`);
log.append(initiator, channelHost + channelPath, shorthandResource.path, false);
@ -186,12 +190,12 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
targetPath = targetPath.replace(Resource.VERSION_PLACEHOLDER, versionNumber);
// Replace the requested version with the latest depending on major version
versionDelivered = targets.setLastVersion(targetPath, versionNumber);
if (versionDelivered === false) {
if (versionDelivered === '') {
return {
'result': false,
};
}
versionDelivered = versionDelivered.toString();
targetPath = targetPath.replace(versionNumber, versionDelivered);
if (versionNumber === null) {
@ -206,7 +210,7 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
if (bundle !== '') {
targetPath = requestAnalyzer._getPathOfBundle(initiator, channelHost, channelPath, targetPath, bundle);
}
if (targetPath === false) {
if (targetPath['result'] === false) {
break;
}
@ -241,7 +245,9 @@ requestAnalyzer._getPathOfBundle = function (initiator, channelHost, channelPath
if (!MathJaxFiles[filename]) {
console.warn(`${LogString.PREFIX} ${LogString.MISSING_RESOURCE} ${channelHost + channelPath}`);
log.append(initiator, channelHost + channelPath, '-', true);
return false;
return {
'result': false,
};
}
}
return helpers.formatFilename(filename.endsWith('.js')

View File

@ -204,8 +204,10 @@ shorthands.specialFiles = function (channelHost, channelPath, searchString) {
} else if ((/cdn\.jsdelivr\.net\/npm\/vue@(2|3)/).test(CompleteURL)) {
let version = CompleteURL.match(Resource.VERSION_EXPRESSION);
lastVersion = targets.setLastVersion(`/vue/${version}.`);
if (lastVersion === false) {
return false;
if (lastVersion === '') {
return {
'result': false,
};
}
return {
'source': channelHost,
@ -232,7 +234,8 @@ shorthands.specialFiles = function (channelHost, channelPath, searchString) {
'path': 'resources/jquery/1.11.2/jquery.min.jsm',
'bundle': ''
};
} else {
return false;
}
return {
'result': false,
};
};

View File

@ -95,16 +95,18 @@ statistics._filterAndSortData = function () {
statistics._mergeObjects = function (obj, arr) {
for (let [key, value] of Object.entries(obj)) {
let bundle = targets.determineBundle(key);
let domain, bundle;
domain = key;
bundle = targets.determineBundle(domain);
if (bundle !== '') {
bundle = key.split('/');
key = `${bundle[0]}/${bundle[1]}/${bundle[2]}/`;
bundle = domain.split('/');
domain = `${bundle[0]}/${bundle[1]}/${bundle[2]}/`;
}
// If CDN/Framework exists, add it, otherwise create new one
if (arr[key]) {
arr[key] += value;
if (arr[domain]) {
arr[domain] += value;
} else {
arr[key] = value;
arr[domain] = value;
}
}
};