[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated: Amount.toFloat and hide files
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated: Amount.toFloat and hide filesystem requirement |
Date: |
Thu, 27 May 2021 16:16:03 +0200 |
This is an automated email from the git hooks/post-receive script.
sebasjm pushed a commit to branch master
in repository wallet-core.
The following commit(s) were added to refs/heads/master by this push:
new 3688f7e4 Amount.toFloat and hide filesystem requirement
3688f7e4 is described below
commit 3688f7e4d4d2ccd148edd25e0a8eaddbd677b317
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Thu May 27 11:15:55 2021 -0300
Amount.toFloat and hide filesystem requirement
---
packages/taler-util/src/amounts.ts | 7 +++++++
packages/taler-util/src/talerconfig.ts | 20 +++++++++++++++++---
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/packages/taler-util/src/amounts.ts
b/packages/taler-util/src/amounts.ts
index e472de50..931bc1dd 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 e060afb7..f3c1220e 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);
}
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-core] branch master updated: Amount.toFloat and hide filesystem requirement,
gnunet <=