From 1cd84f57c3e5b6b841dd301b672870c1b82f62a0 Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Thu, 7 May 2020 08:17:43 -0400 Subject: [PATCH] Removing truthy condition from `get()` such that the output is consistent in shape (breaking change for invalid key & tuple result), updating "invalid" read tests --- lib/haro.js | 6 +++--- package-lock.json | 2 +- package.json | 2 +- src/haro.js | 2 +- test/offline.js | 7 +++++-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/haro.js b/lib/haro.js index ab10997..6b1c7ab 100644 --- a/lib/haro.js +++ b/lib/haro.js @@ -4,7 +4,7 @@ * @author Jason Mulligan * @copyright 2020 * @license BSD-3-Clause - * @version 7.0.2 + * @version 8.0.0 */ "use strict"; @@ -249,7 +249,7 @@ get (key, raw = false) { const result = clone(this.data.get(key) || null); - return result && !raw ? this.list(key, result) : result; + return raw ? result : this.list(key, result); } has (key, map = this.data) { @@ -472,7 +472,7 @@ return obj; } - factory.version = "7.0.2"; + factory.version = "8.0.0"; // Node, AMD & window supported if (typeof exports !== "undefined") { diff --git a/package-lock.json b/package-lock.json index cf0bfc5..3773fc5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "haro", - "version": "7.0.2", + "version": "8.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2db088f..d4ff3e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "haro", - "version": "7.0.2", + "version": "8.0.0", "description": "Harō is a modern immutable DataStore", "main": "lib/haro.js", "scripts": { diff --git a/src/haro.js b/src/haro.js index 2567821..dd73a57 100644 --- a/src/haro.js +++ b/src/haro.js @@ -141,7 +141,7 @@ get (key, raw = false) { const result = clone(this.data.get(key) || null); - return result && !raw ? this.list(key, result) : result; + return raw ? result : this.list(key, result); } has (key, map = this.data) { diff --git a/test/offline.js b/test/offline.js index eaef47e..b8c13f6 100644 --- a/test/offline.js +++ b/test/offline.js @@ -153,11 +153,14 @@ exports["read (invalid)"] = { test: function (test) { const self = this; - test.expect(3); + test.expect(6); this.store.set(null, data[0]).then(function () { test.equal(self.store.size, 1, "Should be '1'"); test.equal(self.store.data.size, 1, "Should be '1'"); - test.equal(self.store.get("abc"), undefined, "Should be 'undefined'"); + test.equal(self.store.get("abc") instanceof Array, true, "Should be 'true'"); + test.equal(self.store.get("abc")[0], "abc", "Should be 'abc'"); + test.equal(self.store.get("abc")[1], null, "Should be 'null'"); + test.equal(self.store.get("abc", true), null, "Should be 'null'"); test.done(); }, function () { test.done();