From 202d51c6a2aea6c24af00605dd76b4fc37e42630 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 4 Jan 2018 11:35:04 +0100 Subject: refactor / put some types where they belong --- src/helpers.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/helpers.ts') diff --git a/src/helpers.ts b/src/helpers.ts index 42863c65b..3b7cd36f5 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -138,6 +138,9 @@ export function getTalerStampDate(stamp: string): Date | null { return new Date(sec * 1000); } +/** + * Compute the hash function of a JSON object. + */ export function hash(val: any): number { const str = canonicalJson(val); // https://github.com/darkskyapp/string-hash @@ -152,3 +155,17 @@ export function hash(val: any): number { * signed int to an unsigned by doing an unsigned bitshift. */ return h >>> 0; } + + +/** + * Lexically compare two strings. + */ +export function strcmp(s1: string, s2: string): number { + if (s1 < s2) { + return -1; + } + if (s1 > s2) { + return 1; + } + return 0; +} -- cgit v1.2.3