always use template strings instead of string concatenation

This commit is contained in:
zadam
2022-12-21 15:19:05 +01:00
parent ea006993f6
commit 1b24276a4a
154 changed files with 433 additions and 437 deletions

View File

@@ -13,8 +13,7 @@ const attributeService = require("../attributes");
// date format is e.g. 20181121T193703Z
function parseDate(text) {
// insert - and : to make it ISO format
text = text.substr(0, 4) + "-" + text.substr(4, 2) + "-" + text.substr(6, 2)
+ " " + text.substr(9, 2) + ":" + text.substr(11, 2) + ":" + text.substr(13, 2) + ".000Z";
text = `${text.substr(0, 4)}-${text.substr(4, 2)}-${text.substr(6, 2)} ${text.substr(9, 2)}:${text.substr(11, 2)}:${text.substr(13, 2)}.000Z`;
return text;
}
@@ -101,7 +100,7 @@ function importEnex(taskContext, file, parentNote) {
saxStream.on("error", e => {
// unhandled errors will throw, since this is a proper node
// event emitter.
log.error("error when parsing ENEX file: " + e);
log.error(`error when parsing ENEX file: ${e}`);
// clear the error
this._parser.error = null;
this._parser.resume();
@@ -311,7 +310,7 @@ function importEnex(taskContext, file, parentNote) {
content += imageLink;
}
} catch (e) {
log.error("error when saving image from ENEX file: " + e);
log.error(`error when saving image from ENEX file: ${e}`);
createFileNote();
}
} else {

View File

@@ -25,7 +25,7 @@ async function importOpml(taskContext, fileBuffer, parentNote) {
});
if (!['1.0', '1.1', '2.0'].includes(xml.opml.$.version)) {
return [400, 'Unsupported OPML version ' + xml.opml.$.version + ', 1.0, 1.1 or 2.0 expected instead.'];
return [400, `Unsupported OPML version ${xml.opml.$.version}, 1.0, 1.1 or 2.0 expected instead.`];
}
const opmlVersion = parseInt(xml.opml.$.version);
@@ -48,7 +48,7 @@ async function importOpml(taskContext, fileBuffer, parentNote) {
content = outline.$._note; // _note is already HTML
}
else {
throw new Error("Unrecognized OPML version " + opmlVersion);
throw new Error(`Unrecognized OPML version ${opmlVersion}`);
}
content = htmlSanitizer.sanitize(content || "");
@@ -88,7 +88,7 @@ function toHtml(text) {
return '';
}
return '<p>' + text.replace(/(?:\r\n|\r|\n)/g, '</p><p>') + '</p>';
return `<p>${text.replace(/(?:\r\n|\r|\n)/g, '</p><p>')}</p>`;
}
module.exports = {

View File

@@ -111,7 +111,7 @@ function convertTextToHtml(text) {
text = text.replace(/<br>\s*<br>/g, "</p><p>");
// 4: Wrap in Paragraph Tags
text = "<p>" + text + "</p>";
text = `<p>${text}</p>`;
return text;
}

View File

@@ -135,15 +135,15 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
if (attr.type === 'label-definition') {
attr.type = 'label';
attr.name = 'label:' + attr.name;
attr.name = `label:${attr.name}`;
}
else if (attr.type === 'relation-definition') {
attr.type = 'label';
attr.name = 'relation:' + attr.name;
attr.name = `relation:${attr.name}`;
}
if (!attributeService.isAttributeType(attr.type)) {
log.error("Unrecognized attribute type " + attr.type);
log.error(`Unrecognized attribute type ${attr.type}`);
continue;
}
@@ -157,7 +157,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
}
if (taskContext.data.safeImport && attributeService.isAttributeDangerous(attr.type, attr.name)) {
attr.name = 'disabled:' + attr.name;
attr.name = `disabled:${attr.name}`;
}
if (taskContext.data.safeImport) {
@@ -223,7 +223,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
absUrl = '';
}
absUrl += (absUrl.length > 0 ? '/' : '') + url;
absUrl += `${absUrl.length > 0 ? '/' : ''}${url}`;
const {noteMeta} = getMeta(absUrl);
const targetNoteId = getNoteId(noteMeta, absUrl);
@@ -526,7 +526,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
new Attribute(attr).save();
}
else {
log.info("Relation not imported since target note doesn't exist: " + JSON.stringify(attr));
log.info(`Relation not imported since target note doesn't exist: ${JSON.stringify(attr)}`);
}
}