refactor(core): Remove linting exceptions in nodes-base (no-changelog) (#4944)

This commit is contained in:
Michael Kret
2023-01-13 19:11:56 +02:00
committed by GitHub
parent d7732ea150
commit 6608e69457
254 changed files with 2687 additions and 2675 deletions

View File

@@ -14,6 +14,37 @@ import { set } from 'lodash';
import moment from 'moment-timezone';
function parseDateByFormat(this: IExecuteFunctions, value: string, fromFormat: string) {
const date = moment(value, fromFormat, true);
if (moment(date).isValid()) return date;
throw new NodeOperationError(
this.getNode(),
'Date input cannot be parsed. Please recheck the value and the "From Format" field.',
);
}
function getIsoValue(this: IExecuteFunctions, value: string) {
try {
return new Date(value).toISOString(); // may throw due to unpredictable input
} catch (error) {
throw new NodeOperationError(
this.getNode(),
'Unrecognized date input. Please specify a format in the "From Format" field.',
);
}
}
function parseDateByDefault(this: IExecuteFunctions, value: string) {
const isoValue = getIsoValue.call(this, value);
if (moment(isoValue).isValid()) return moment(isoValue);
throw new NodeOperationError(
this.getNode(),
'Unrecognized date input. Please specify a format in the "From Format" field.',
);
}
export class DateTime implements INodeType {
description: INodeTypeDescription = {
displayName: 'Date & Time',
@@ -399,7 +430,7 @@ export class DateTime implements INodeType {
newDate = moment.unix(currentDate as unknown as number);
} else {
if (options.fromTimezone || options.toTimezone) {
const fromTimezone = options.fromTimezone || workflowTimezone;
const fromTimezone = options.fromTimezone ?? workflowTimezone;
if (options.fromFormat) {
newDate = moment.tz(
currentDate,
@@ -517,34 +548,3 @@ export class DateTime implements INodeType {
return this.prepareOutputData(returnData);
}
}
function parseDateByFormat(this: IExecuteFunctions, value: string, fromFormat: string) {
const date = moment(value, fromFormat, true);
if (moment(date).isValid()) return date;
throw new NodeOperationError(
this.getNode(),
'Date input cannot be parsed. Please recheck the value and the "From Format" field.',
);
}
function parseDateByDefault(this: IExecuteFunctions, value: string) {
const isoValue = getIsoValue.call(this, value);
if (moment(isoValue).isValid()) return moment(isoValue);
throw new NodeOperationError(
this.getNode(),
'Unrecognized date input. Please specify a format in the "From Format" field.',
);
}
function getIsoValue(this: IExecuteFunctions, value: string) {
try {
return new Date(value).toISOString(); // may throw due to unpredictable input
} catch (error) {
throw new NodeOperationError(
this.getNode(),
'Unrecognized date input. Please specify a format in the "From Format" field.',
);
}
}