From 08099521737db771a001360d66d48fe824b94181 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sun, 27 Dec 2020 20:33:46 +0100 Subject: [PATCH] :zap: Add "Ends With" and "Starts With" support to If and Switch Node --- packages/nodes-base/nodes/If.node.ts | 10 ++++++++++ packages/nodes-base/nodes/Switch.node.ts | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/nodes-base/nodes/If.node.ts b/packages/nodes-base/nodes/If.node.ts index f5965a877d..d36a875295 100644 --- a/packages/nodes-base/nodes/If.node.ts +++ b/packages/nodes-base/nodes/If.node.ts @@ -156,6 +156,10 @@ export class If implements INodeType { name: 'Contains', value: 'contains', }, + { + name: 'Ends With', + value: 'endsWith', + }, { name: 'Equal', value: 'equal', @@ -172,6 +176,10 @@ export class If implements INodeType { name: 'Regex', value: 'regex', }, + { + name: 'Starts With', + value: 'startsWith', + }, { name: 'Is Empty', value: 'isEmpty', @@ -252,12 +260,14 @@ export class If implements INodeType { } = { contains: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || '').toString().includes((value2 || '').toString()), notContains: (value1: NodeParameterValue, value2: NodeParameterValue) => !(value1 || '').toString().includes((value2 || '').toString()), + endsWith: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 as string).endsWith(value2 as string), equal: (value1: NodeParameterValue, value2: NodeParameterValue) => value1 === value2, notEqual: (value1: NodeParameterValue, value2: NodeParameterValue) => value1 !== value2, larger: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) > (value2 || 0), largerEqual: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) >= (value2 || 0), smaller: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) < (value2 || 0), smallerEqual: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) <= (value2 || 0), + startsWith: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 as string).startsWith(value2 as string), isEmpty: (value1: NodeParameterValue) => [undefined, null, ''].includes(value1 as string), regex: (value1: NodeParameterValue, value2: NodeParameterValue) => { const regexMatch = (value2 || '').toString().match(new RegExp('^/(.*?)/([gimy]*)$')); diff --git a/packages/nodes-base/nodes/Switch.node.ts b/packages/nodes-base/nodes/Switch.node.ts index 013c362dbc..c1c728d94f 100644 --- a/packages/nodes-base/nodes/Switch.node.ts +++ b/packages/nodes-base/nodes/Switch.node.ts @@ -340,6 +340,10 @@ export class Switch implements INodeType { name: 'Contains', value: 'contains', }, + { + name: 'Ends With', + value: 'endsWith', + }, { name: 'Equal', value: 'equal', @@ -356,6 +360,10 @@ export class Switch implements INodeType { name: 'Regex', value: 'regex', }, + { + name: 'Starts With', + value: 'startsWith', + }, ], default: 'equal', description: 'Operation to decide where the the data should be mapped to.', @@ -470,12 +478,14 @@ export class Switch implements INodeType { } = { contains: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || '').toString().includes((value2 || '').toString()), notContains: (value1: NodeParameterValue, value2: NodeParameterValue) => !(value1 || '').toString().includes((value2 || '').toString()), + endsWith: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 as string).endsWith(value2 as string), equal: (value1: NodeParameterValue, value2: NodeParameterValue) => value1 === value2, notEqual: (value1: NodeParameterValue, value2: NodeParameterValue) => value1 !== value2, larger: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) > (value2 || 0), largerEqual: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) >= (value2 || 0), smaller: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) < (value2 || 0), smallerEqual: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) <= (value2 || 0), + startsWith: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 as string).startsWith(value2 as string), regex: (value1: NodeParameterValue, value2: NodeParameterValue) => { const regexMatch = (value2 || '').toString().match(new RegExp('^/(.*?)/([gimy]*)$'));