aboutsummaryrefslogtreecommitdiff
path: root/src/helpers.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-01-04 11:35:04 +0100
committerFlorian Dold <florian.dold@gmail.com>2018-01-04 11:35:04 +0100
commit202d51c6a2aea6c24af00605dd76b4fc37e42630 (patch)
tree2ce699ebb99c127b560392cbd1ab42c034f4433e /src/helpers.ts
parent02b4a2ad6208c3b70a4a194b4c763a4e4334cdc1 (diff)
downloadwallet-core-202d51c6a2aea6c24af00605dd76b4fc37e42630.tar.xz
refactor / put some types where they belong
Diffstat (limited to 'src/helpers.ts')
-rw-r--r--src/helpers.ts17
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;
+}