diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-01-04 11:35:04 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-01-04 11:35:04 +0100 |
commit | 202d51c6a2aea6c24af00605dd76b4fc37e42630 (patch) | |
tree | 2ce699ebb99c127b560392cbd1ab42c034f4433e /src/helpers.ts | |
parent | 02b4a2ad6208c3b70a4a194b4c763a4e4334cdc1 (diff) | |
download | wallet-core-202d51c6a2aea6c24af00605dd76b4fc37e42630.tar.xz |
refactor / put some types where they belong
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; +} |