@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 2.93 kB
JavaScript
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
import i from"./../define-nonenumerable-read-only-property.js";import r from"./../../assert/is-function.js";import e from"./../../assert/is-collection.js";import t from"./../../constants/math/float64-pinf.js";import n from"./../../assert/is-plain-object.js";import o from"./../../assert/has-own-property.js";import s from"./../../assert/is-boolean.js";import l from"./../../assert/is-positive-integer.js";import u from"./../index-of.js";import a from"./../../vendor/debug.js";var m=n,p=o,f=s.isPrimitive,c=l.isPrimitive,g=u,h=["values","indices","*"];function d(i,r){return m(r)?(p(r,"thisArg")&&(i.thisArg=r.thisArg),p(r,"series")&&(i.series=r.series,!f(i.series))?new TypeError("invalid option. `series` option must be a boolean primitive. Option: `"+i.series+"`."):p(r,"limit")&&(i.limit=r.limit,!c(i.limit))?new TypeError("invalid option. `limit` option must be a positive integer. Option: `"+i.limit+"`."):p(r,"returns")&&(i.returns=r.returns,-1===g(h,i.returns))?new TypeError('invalid option. `returns` option must be one of the following: "'+h.join('", "')+'". Option: `'+i.returns+"`."):null):new TypeError("invalid argument. Options must be an object. Value: `"+r+"`.")}var v=a,b=v("bifurcate-by-async:limit");function y(i,r,e,t){var n,o,s,l,u,a,m,p;if(u=i.length,b("Collection length: %d",u),m=[],0===u)return b("Finished processing a collection."),t(null,m);for(m.push([],[]),l=u<r.limit?u:r.limit,b("Concurrency limit: %d",l),b("Number of arguments: %d",e.length),n=u-1,o=0,a=-1,p=0;p<l;p++)a<n&&f();function f(){var t,n;function o(i,e){if(!s){if(i)return s=!0,c(i);b("Collection element %d group: %s.",n,e?"0":"1"),"indices"===r.returns?e?m[0].push(n):m[1].push(n):"*"===r.returns?e?m[0].push([n,t]):m[1].push([n,t]):e?m[0].push(t):m[1].push(t),c()}}t=i[n=a+=1],b("Collection element %d: %s.",n,JSON.stringify(t)),2===e.length?e.call(r.thisArg,t,o):3===e.length?e.call(r.thisArg,t,n,o):e.call(r.thisArg,t,n,i,o)}function c(i){return i?(b("Encountered an error: %s",i.message),t(i)):(b("Processed %d of %d collection elements.",o+=1,u),a<n?f():o===u?(b("Finished processing a collection."),t(null,m)):void 0)}}var j=r,w=e,E=t,T=d,A=y;function O(i,r){var e,t,n;if(e={},arguments.length>1){if(t=T(e,i))throw t;n=r}else n=i;if(!j(n))throw new TypeError("invalid argument. Last argument must be a function. Value: `"+n+"`.");return e.series?e.limit=1:e.limit||(e.limit=E),o;function o(i,r){if(!w(i))throw new TypeError("invalid argument. First argument must be a collection. Value: `"+i+".`");if(!j(r))throw new TypeError("invalid argument. Last argument must be a function. Value: `"+r+"`.");return A(i,e,n,(function(i,e){if(i)return r(i);r(null,e)}))}}var C=O;function V(i,r,e,t){if(arguments.length<4)return C(r)(i,e);C(r,e)(i,t)}var F=i,P=V,x=O;F(P,"factory",x);export default P;
//# sourceMappingURL=bifurcate-by.js.map