From a6e81543183e4842d1d2fb9707b09e620d0f6008 Mon Sep 17 00:00:00 2001 From: Stephen Mathieson Date: Thu, 26 Mar 2015 12:36:51 -0400 Subject: [PATCH] browser: expose `storage` This patch allows overriding the default `storage` mechanism. Closes #188. --- browser.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/browser.js b/browser.js index 55f4cf92..7c764522 100644 --- a/browser.js +++ b/browser.js @@ -11,17 +11,10 @@ exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; - -/** - * Use chrome.storage.local if we are in an app - */ - -var storage; - -if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined') - storage = chrome.storage.local; -else - storage = localstorage(); +exports.storage = 'undefined' != typeof chrome + && 'undefined' != typeof chrome.storage + ? chrome.storage.local + : localstorage(); /** * Colors. @@ -129,9 +122,9 @@ function log() { function save(namespaces) { try { if (null == namespaces) { - storage.removeItem('debug'); + exports.storage.removeItem('debug'); } else { - storage.debug = namespaces; + exports.storage.debug = namespaces; } } catch(e) {} } @@ -146,7 +139,7 @@ function save(namespaces) { function load() { var r; try { - r = storage.debug; + r = exports.storage.debug; } catch(e) {} return r; }