UNPKG

es-promise-ext

Version:

Native promise extensions for javascript and typescript.

26 lines (25 loc) 926 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = all; exports.isIterable = isIterable; const allWithMap_1 = __importDefault(require("./allWithMap")); const allWithObject_1 = __importDefault(require("./allWithObject")); function all(values) { if (values instanceof Map) return (0, allWithMap_1.default)(values); else if (values instanceof Array) return () => Promise.all(values); else if (isIterable(values)) return () => Promise.all(values); else return (0, allWithObject_1.default)(values); } function isIterable(object) { if (typeof object !== 'object' || object === null || object === undefined) { return false; } return typeof object[Symbol.iterator] === 'function'; }