Add support for submitting the transactions to Actual server
This commit is contained in:
9
src/util/code.ts
Normal file
9
src/util/code.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
const standardContext = {
|
||||
|
||||
};
|
||||
|
||||
export function jsMapper<I, O>(code: string, context: Record<string, unknown>): (task: I) => O {
|
||||
const ctx = { ...standardContext, ...context };
|
||||
const filter = new Function('$', ...Object.keys(ctx), code);
|
||||
return (task: I) => filter(task, ...Object.values(ctx));
|
||||
}
|
||||
17
src/util/config.ts
Normal file
17
src/util/config.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
const specialOptions: Record<string, (text: string) => string> = {
|
||||
$__file: (arg: string) => readFileSync(arg, 'utf8').trim()
|
||||
};
|
||||
|
||||
export const enhancedStringConfig = (value: string) => {
|
||||
const trimmed = value.trim();
|
||||
|
||||
for(const opt of Object.keys(specialOptions)) {
|
||||
if(trimmed.startsWith(`${opt}:`) && opt in specialOptions) {
|
||||
return specialOptions[opt](trimmed.slice(opt.length + 1).trim());
|
||||
}
|
||||
}
|
||||
|
||||
return trimmed;
|
||||
};
|
||||
Reference in New Issue
Block a user