summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/util/talerconfig.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/util/talerconfig.ts')
-rw-r--r--packages/taler-wallet-core/src/util/talerconfig.ts53
1 files changed, 51 insertions, 2 deletions
diff --git a/packages/taler-wallet-core/src/util/talerconfig.ts b/packages/taler-wallet-core/src/util/talerconfig.ts
index 8c740e1e2..e9a67287c 100644
--- a/packages/taler-wallet-core/src/util/talerconfig.ts
+++ b/packages/taler-wallet-core/src/util/talerconfig.ts
@@ -26,7 +26,6 @@
import { AmountJson } from "./amounts";
import * as Amounts from "./amounts";
import fs from "fs";
-import { acceptExchangeTermsOfService } from "../operations/exchanges";
export class ConfigError extends Error {
constructor(message: string) {
@@ -56,6 +55,26 @@ export class ConfigValue<T> {
}
return this.converter(this.val);
}
+
+ orUndefined(): T | undefined {
+ if (this.val !== undefined) {
+ return this.converter(this.val);
+ } else {
+ return undefined;
+ }
+ }
+
+ orDefault(v: T): T | undefined {
+ if (this.val !== undefined) {
+ return this.converter(this.val);
+ } else {
+ return v;
+ }
+ }
+
+ isDefined(): boolean {
+ return this.val !== undefined;
+ }
}
/**
@@ -197,7 +216,7 @@ export class Configuration {
getString(section: string, option: string): ConfigValue<string> {
const secNorm = section.toUpperCase();
const optNorm = option.toUpperCase();
- const val = (this.sectionMap[section] ?? {})[optNorm];
+ const val = (this.sectionMap[secNorm] ?? {})[optNorm];
return new ConfigValue(secNorm, optNorm, val, (x) => x);
}
@@ -210,6 +229,36 @@ export class Configuration {
);
}
+ getYesNo(section: string, option: string): ConfigValue<boolean> {
+ const secNorm = section.toUpperCase();
+ const optNorm = option.toUpperCase();
+ const val = (this.sectionMap[secNorm] ?? {})[optNorm];
+ const convert = (x: string): boolean => {
+ x = x.toLowerCase();
+ if (x === "yes") {
+ return true;
+ } else if (x === "no") {
+ return false;
+ }
+ throw Error(`invalid config value for [${secNorm}]/${optNorm}, expected yes/no`);
+ };
+ return new ConfigValue(secNorm, optNorm, val, convert);
+ }
+
+ getNumber(section: string, option: string): ConfigValue<number> {
+ const secNorm = section.toUpperCase();
+ const optNorm = option.toUpperCase();
+ const val = (this.sectionMap[secNorm] ?? {})[optNorm];
+ const convert = (x: string): number => {
+ try {
+ return Number.parseInt(x, 10);
+ } catch (e) {
+ throw Error(`invalid config value for [${secNorm}]/${optNorm}, expected number`);
+ }
+ };
+ return new ConfigValue(secNorm, optNorm, val, convert);
+ }
+
lookupVariable(x: string, depth: number = 0): string | undefined {
// We loop up options in PATHS in upper case, as option names
// are case insensitive