UNPKG

es-promise-ext

Version:

Native promise extensions for javascript and typescript.

26 lines (25 loc) 1.03 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = promiseAllWith; const allWithMap_1 = __importDefault(require("./allWithMap")); const allWithObject_1 = __importDefault(require("./allWithObject")); function promiseAllWith(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 if (typeof values === 'object') return (0, allWithObject_1.default)(values); throw new TypeError('Promise.allWith must be called with either array, map or object'); } function isIterable(object) { if (typeof object !== 'object' || object === null || object === undefined) { return false; } return typeof object[Symbol.iterator] === 'function'; }