summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNick Van Doorn <vandoorn.nick@gmail.com>2019-01-20 15:21:34 -0800
committerNick Van Doorn <vandoorn.nick@gmail.com>2019-01-20 15:21:34 -0800
commit2e94d8dce0fb509afd8cdb795067d97ecc4c364f (patch)
tree00279cae424154d8f47254ec8ab2e924384efee7 /lib
parentfd3317e2bf2f65050583d9c072ee34eea3287d76 (diff)
MONOREPO
Diffstat (limited to 'lib')
-rw-r--r--lib/error.model.ts22
-rw-r--r--lib/util.ts10
2 files changed, 32 insertions, 0 deletions
diff --git a/lib/error.model.ts b/lib/error.model.ts
new file mode 100644
index 0000000..5cf9916
--- /dev/null
+++ b/lib/error.model.ts
@@ -0,0 +1,22 @@
+export enum NaiveErrorCode {
+ UNCAUGHT = 0,
+ OUT_OF_SPACE
+}
+
+const e = NaiveErrorCode;
+
+export const lookupMsg = (c: NaiveErrorCode) => {
+ switch (c) {
+ case e.OUT_OF_SPACE:
+ return `Out of storage space (too big for in memory buffer)`;
+ case e.UNCAUGHT:
+ default:
+ return `Uncaught error. Please add message/code in src/error.model.ts`;
+ }
+};
+
+export class NaiveError extends Error {
+ constructor(public code: NaiveErrorCode) {
+ super(lookupMsg(code));
+ }
+}
diff --git a/lib/util.ts b/lib/util.ts
new file mode 100644
index 0000000..7e7b965
--- /dev/null
+++ b/lib/util.ts
@@ -0,0 +1,10 @@
+/**
+ * Get the last item in t
+ */
+export const last = <T>(t: T[]): T => t[t.length - 1];
+
+/**
+ * Generate a random key with a seed
+ */
+export const getKey = (seed: string) =>
+ seed + Date.now() + Math.floor(Math.random() * 1000);