UNPKG

@plq/use-persisted-state

Version:
29 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = isAsyncStorage; 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); return Boolean(storage) && hasGet && hasSet && hasRemove && hasGetPromise && hasSetPromise && hasRemovePromise; } //# sourceMappingURL=is-async-storage.js.map