From 1c8206f8c0c8921643aa1b070fbe6648411300fe Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 24 May 2017 16:14:23 +0200 Subject: remove dead code and add comments --- src/helpers.ts | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'src/helpers.ts') 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(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) { -- cgit v1.2.3