1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.getStorage = getStorage;
- exports.usePromise = usePromise;
- /**
- * Need to invoke a function at runtime instead of import-time to make tests
- * pass with mocked browser and chrome objects
- */
- function getStorage() {
- return typeof browser !== 'undefined' && browser.storage || typeof chrome !== 'undefined' && chrome.storage;
- }
- /**
- * Need to invoke a function at runtime instead of import-time to make tests
- * pass with mocked browser and chrome objects
- */
- function usesPromises() {
- var storage = getStorage();
- try {
- return storage && storage.local.get && storage.local.get() && typeof storage.local.get().then === 'function';
- } catch (e) {
- return false;
- }
- }
- /**
- * Converts a callback-based API to a promise based API.
- * For now we assume that there is only one arg in addition to the callback
- */
- function usePromise(fn, arg) {
- if (usesPromises()) {
- return fn(arg);
- }
- return new Promise(function (resolve) {
- fn(arg, function () {
- resolve.apply(void 0, arguments);
- });
- });
- }
|