aboutsummaryrefslogtreecommitdiff
path: root/src/helpers.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-24 16:14:23 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-24 16:14:23 +0200
commit1c8206f8c0c8921643aa1b070fbe6648411300fe (patch)
tree1ee523e701fa369d0290d14e50a6f0b3cb5fb50f /src/helpers.ts
parentfc53a08bb0ffaf2bd49408f50701f17cdd603fb9 (diff)
downloadwallet-core-1c8206f8c0c8921643aa1b070fbe6648411300fe.tar.xz
remove dead code and add comments
Diffstat (limited to 'src/helpers.ts')
-rw-r--r--src/helpers.ts39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/helpers.ts b/src/helpers.ts
index 7b9470271..8b2b265cc 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -17,20 +17,19 @@
/**
* Smaller helper functions that do not depend
* on the emscripten machinery.
- *
- * @author Florian Dold
*/
+/**
+ * Imports.
+ */
import {AmountJson, Amounts} from "./types";
import URI = require("urijs");
-export function substituteFulfillmentUrl(url: string, vars: any) {
- url = url.replace("${H_contract}", vars.H_contract);
- url = url.replace("${$}", "$");
- return url;
-}
-
-
+/**
+ * Show an amount in a form suitable for the user.
+ * FIXME: In the future, this should consider currency-specific
+ * settings such as significant digits or currency symbols.
+ */
export function amountToPretty(amount: AmountJson): string {
let x = amount.value + amount.fraction / Amounts.fractionalBase;
return `${x} ${amount.currency}`;
@@ -54,20 +53,6 @@ export function canonicalizeBaseUrl(url: string) {
}
-export function parsePrettyAmount(pretty: string): AmountJson|undefined {
- const res = /([0-9]+)(.[0-9]+)?\s*(\w+)/.exec(pretty);
- if (!res) {
- return undefined;
- }
- return {
- value: parseInt(res[1], 10),
- fraction: res[2] ? (parseFloat(`0.${res[2]}`) / Amounts.fractionalBase) : 0,
- currency: res[3]
- }
-}
-
-
-
/**
* Convert object to JSON with canonical ordering of keys
* and whitespace omitted.
@@ -119,6 +104,10 @@ export function flatMap<T, U>(xs: T[], f: (x: T) => U[]): U[] {
}
+/**
+ * Extract a numeric timstamp (in seconds) from the Taler date format
+ * ("/Date([n])/"). Returns null if input is not in the right format.
+ */
export function getTalerStampSec(stamp: string): number | null {
const m = stamp.match(/\/?Date\(([0-9]*)\)\/?/);
if (!m) {
@@ -128,6 +117,10 @@ export function getTalerStampSec(stamp: string): number | null {
}
+/**
+ * Get a JavaScript Date object from a Taler date string.
+ * Returns null if input is not in the right format.
+ */
export function getTalerStampDate(stamp: string): Date | null {
let sec = getTalerStampSec(stamp);
if (sec == null) {