Implement support for ING transfers

This commit is contained in:
2025-04-02 21:37:57 +02:00
parent 019a3e7cd4
commit 89b59dee50
9 changed files with 312 additions and 89 deletions

View File

@@ -2,8 +2,8 @@ const standardContext = {
};
export function jsMapper<I, O>(code: string, context: Record<string, unknown>): (task: I) => O {
export function js2<I1, I2, O>(code: string, i1: string, i2: string, context: Record<string, unknown> = {}): (i1: I1, i2: I2) => O {
const ctx = { ...standardContext, ...context };
const filter = new Function('$', ...Object.keys(ctx), code);
return (task: I) => filter(task, ...Object.values(ctx));
const filter = new Function(i1, i2, ...Object.keys(ctx), code);
return (i1: I1, i2: I2) => filter(i1, i2, ...Object.values(ctx));
}

66
src/util/parser.ts Normal file
View File

@@ -0,0 +1,66 @@
export function mapCombine<T extends object, E>(
items: T[],
property: keyof T,
map: (item: T) => E,
combine: (a: T, b: T) => E | undefined,
): E[] {
// Helper function to check if a value is nullish
const isNullish = (value: any): boolean =>
value === undefined ||
value === null ||
(typeof value === 'string' && value.trim() === '');
const result: Array<{
value: T | E;
combined: boolean;
skip: boolean;
}> = items.map(item => ({
value: item,
combined: false,
skip: false
}));
for (let i = 0; i < result.length; i++) {
if (result[i].combined || result[i].skip) continue;
const propValueI = (result[i].value as T)[property];
if (isNullish(propValueI)) continue; // Skip items with nullish property values
for (let j = i + 1; j < result.length; j++) {
if (result[j].skip) continue;
const propValueJ = (result[j].value as T)[property];
if (isNullish(propValueJ)) continue; // Skip if second item has nullish property
if (propValueI === propValueJ) {
const combinedValue = combine(result[i].value as T, result[j].value as T);
if (combinedValue !== undefined) {
result[i].value = combinedValue;
result[i].combined = true;
result[j].skip = true;
break;
}
}
}
}
return result
.filter(item => !item.skip)
.map(item => item.combined ? item.value as E : map(item.value as T));
}
export function parseAmount(input?: string): number|undefined {
if (input === undefined) {
return undefined;
}
const v = Number.parseFloat(input.replaceAll(",", "."));
if (isNaN(v)) {
return undefined;
}
return v;
}