UNPKG

taro-hooks

Version:
48 lines 1.15 kB
import { getStorageInfo } from '@tarojs/taro'; import { INIT } from './spaceInfo.type'; function _call(body, then, direct) { if (direct) { return then ? then(body()) : body(); } try { var result = Promise.resolve(body()); return then ? result.then(then) : result; } catch (e) { return Promise.reject(e); } } var getStorageSpaceInfo = function getStorageSpaceInfo() { return _await(_catch(function () { return _call(getStorageInfo, function (_ref) { var currentSize = _ref.currentSize, limitSize = _ref.limitSize; return { currentSize: currentSize, limitSize: limitSize }; }); }, 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 _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; } export default getStorageSpaceInfo;