aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/taler-util/src/amounts.ts7
-rw-r--r--packages/taler-util/src/talerconfig.ts20
2 files changed, 24 insertions, 3 deletions
diff --git a/packages/taler-util/src/amounts.ts b/packages/taler-util/src/amounts.ts
index e472de503..931bc1dda 100644
--- a/packages/taler-util/src/amounts.ts
+++ b/packages/taler-util/src/amounts.ts
@@ -331,6 +331,13 @@ export class Amounts {
};
}
+ /**
+ * Convert a Taler amount to a float
+ */
+ static toFloat(amount: AmountJson): number {
+ return amount.value + (amount.fraction / amountFractionalBase)
+ }
+
static min(a: AmountLike, b: AmountLike): AmountJson {
const cr = Amounts.cmp(a, b);
if (cr >= 0) {
diff --git a/packages/taler-util/src/talerconfig.ts b/packages/taler-util/src/talerconfig.ts
index e060afb71..f3c1220e2 100644
--- a/packages/taler-util/src/talerconfig.ts
+++ b/packages/taler-util/src/talerconfig.ts
@@ -25,7 +25,21 @@
*/
import { AmountJson } from "./amounts.js";
import { Amounts } from "./amounts.js";
-import fs from "fs";
+
+const nodejs_fs = (function () {
+ let fs: typeof import("fs");
+ return function() {
+ if (!fs) {
+ /**
+ * need to use an expression when doing a require if we want
+ * webpack not to find out about the requirement
+ */
+ const _r = "require"
+ fs = module[_r]("fs")
+ }
+ return fs
+ }
+})()
export class ConfigError extends Error {
constructor(message: string) {
@@ -293,7 +307,7 @@ export class Configuration {
}
static load(filename: string): Configuration {
- const s = fs.readFileSync(filename, "utf-8");
+ const s = nodejs_fs().readFileSync(filename, "utf-8");
const cfg = new Configuration();
cfg.loadFromString(s);
return cfg;
@@ -313,6 +327,6 @@ export class Configuration {
}
s += "\n";
}
- fs.writeFileSync(filename, s);
+ nodejs_fs().writeFileSync(filename, s);
}
}