diff options
author | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-01-19 22:01:11 -0800 |
---|---|---|
committer | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-01-19 22:01:11 -0800 |
commit | d6111be9eed62024bde0f588850bb1f40538114b (patch) | |
tree | 0adf06612fc34483263fcae2d33d7b41d41082ee | |
parent | bd69a7dafdeff0b1742887e466cf9a711e7c14cb (diff) |
Factor out root node handling
-rw-r--r-- | src/database.ts | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/database.ts b/src/database.ts index 9ac31ea..35ffc0f 100644 --- a/src/database.ts +++ b/src/database.ts @@ -8,6 +8,7 @@ import { NaiveError, NaiveErrorCode as e } from "./error.model"; import { last } from "./util"; const splitPath = (path: string): string[] => path.split("/").filter(k => k); +const isRootNode = (path: string): boolean => path === "/" || path === ""; const write = promisify(writeFile); const read = promisify(readFile); @@ -47,13 +48,13 @@ export class Database implements DatabaseInterface { // (which obviously becomes a bad idea at some point) async read(path: string): Promise<Object> { // root node case - if (path === "/") return this.buff; + if (isRootNode(path)) return this.buff; const pathParts = splitPath(path); return this.resolve(pathParts); } async write(path: string, toWrite: any): Promise<void> { - if (path === "/") { + if (isRootNode(path)) { this.buff = toWrite; } else { const pathParts = splitPath(path); |