diff options
Diffstat (limited to 'src/helpers.ts')
-rw-r--r-- | src/helpers.ts | 17 |
1 files changed, 17 insertions, 0 deletions
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; +} |