UNPKG

taro-hooks

Version:
65 lines 1.83 kB
import { logError } from '@taro-hooks/shared'; import { INIT } from './spaceInfo.type'; function _await(value, then, direct) { if (direct) { return then ? then(value) : value; } if (!value || !value.then) { value = Promise.resolve(value); } return then ? value.then(then) : value; } var getStorageSpaceInfo = function getStorageSpaceInfo() { var _exit = false; return _await(_catch(function () { return _invoke(function () { if (navigator && 'storage' in navigator && 'estimate' in navigator.storage) { return _catch(function () { return _await(navigator.storage.estimate(), function (_ref) { var _ref$usage = _ref.usage, usage = _ref$usage === void 0 ? 0 : _ref$usage, _ref$quota = _ref.quota, quota = _ref$quota === void 0 ? 0 : _ref$quota; var _currentSize$limitSiz = { currentSize: usage, limitSize: quota }; _exit = true; return _currentSize$limitSiz; }); }, function (e) { logError('estimate failed', e); var _currentSize$limitSiz2 = { currentSize: Storage.length, limitSize: 0 }; _exit = true; return _currentSize$limitSiz2; }); } }, function (_result) { return _exit ? _result : INIT; }); }, function () { return INIT; })); }; function _catch(body, recover) { try { var result = body(); } catch (e) { return recover(e); } if (result && result.then) { return result.then(void 0, recover); } return result; } function _invoke(body, then) { var result = body(); if (result && result.then) { return result.then(then); } return then(result); } export default getStorageSpaceInfo;