Skip to content

Commit a6e8154

Browse files
author
Stephen Mathieson
committed
browser: expose storage
This patch allows overriding the default `storage` mechanism. Closes #188.
1 parent 0a8e4b7 commit a6e8154

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

browser.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@ exports.formatArgs = formatArgs;
1111
exports.save = save;
1212
exports.load = load;
1313
exports.useColors = useColors;
14-
15-
/**
16-
* Use chrome.storage.local if we are in an app
17-
*/
18-
19-
var storage;
20-
21-
if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined')
22-
storage = chrome.storage.local;
23-
else
24-
storage = localstorage();
14+
exports.storage = 'undefined' != typeof chrome
15+
&& 'undefined' != typeof chrome.storage
16+
? chrome.storage.local
17+
: localstorage();
2518

2619
/**
2720
* Colors.
@@ -129,9 +122,9 @@ function log() {
129122
function save(namespaces) {
130123
try {
131124
if (null == namespaces) {
132-
storage.removeItem('debug');
125+
exports.storage.removeItem('debug');
133126
} else {
134-
storage.debug = namespaces;
127+
exports.storage.debug = namespaces;
135128
}
136129
} catch(e) {}
137130
}
@@ -146,7 +139,7 @@ function save(namespaces) {
146139
function load() {
147140
var r;
148141
try {
149-
r = storage.debug;
142+
r = exports.storage.debug;
150143
} catch(e) {}
151144
return r;
152145
}

0 commit comments

Comments
 (0)