@plq/use-persisted-state
Version:
useState hook with persistence in storage
38 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const is_1 = require("@plq/is");
function isAsyncStorage(storage) {
const hasGet = Boolean(storage) && typeof storage?.get !== 'undefined';
const hasSet = Boolean(storage) && typeof storage?.set !== 'undefined';
const hasRemove = Boolean(storage) && typeof storage?.remove !== 'undefined';
if (!hasGet || !hasSet || !hasRemove) {
return false;
}
const hasGetPromise = (0, is_1.isPromise)(storage.get)
|| (0, is_1.isFunction)(storage.get) && (0, is_1.isPromise)(storage.get(''))
|| (0, is_1.isAsyncFunction)(storage.get);
const hasSetPromise = (0, is_1.isPromise)(storage.set)
|| (0, is_1.isFunction)(storage.set) && (0, is_1.isPromise)(storage.set({}))
|| (0, is_1.isAsyncFunction)(storage.set);
const hasRemovePromise = (0, is_1.isPromise)(storage.remove)
|| (0, is_1.isFunction)(storage.remove) && (0, is_1.isPromise)(storage.remove(''))
|| (0, is_1.isAsyncFunction)(storage.remove);
console.log('isAsyncStorage', {
storage,
hasGet,
hasSet,
hasRemove,
hasGetPromise,
hasSetPromise,
hasRemovePromise,
});
return Boolean(storage)
&& hasGet
&& hasSet
&& hasRemove
&& hasGetPromise
&& hasSetPromise
&& hasRemovePromise;
}
exports.default = isAsyncStorage;
//# sourceMappingURL=is-async-storage.js.map