UNPKG

@stdlib/esm

Version:

ES module distribution for Stdlib, a standard library for JavaScript and Node.js.

3 lines 2.69 kB
// 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 a from"./../../vendor/debug.js";import m from"./../index-of.js";var u=n,f=o,c=s.isPrimitive,p=l.isPrimitive;function g(i,r){return u(r)?(f(r,"thisArg")&&(i.thisArg=r.thisArg),f(r,"series")&&(i.series=r.series,!c(i.series))?new TypeError("invalid option. `series` option must be a boolean primitive. Option: `"+i.series+"`."):f(r,"limit")&&(i.limit=r.limit,!p(i.limit))?new TypeError("invalid option. `limit` option must be a positive integer. Option: `"+i.limit+"`."):null):new TypeError("invalid argument. Options must be an object. Value: `"+r+"`.")}var h=a,d=m,v=h("tabulate-by-async:limit");function b(i,r,e,t){var n,o,s,l,a,m,u,f,c;if(a=i.length,v("Collection length: %d",a),u=[],0===a)return v("Finished processing a collection."),t(null,u);for(f=[],l=a<r.limit?a:r.limit,v("Concurrency limit: %d",l),v("Number of arguments: %d",e.length),n=a-1,o=0,m=-1,c=0;c<l;c++)m<n&&p();function p(){var t,n;function o(i,r){var e;if(!s){if(i)return s=!0,g(i);v("Collection element %d group: %s.",n,r),-1===(e=d(f,r))?(f.push(r),u.push([r,1,0])):u[e][1]+=1,g()}}t=i[n=m+=1],v("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 g(i){var r;if(i)return v("Encountered an error: %s",i.message),t(i);if(v("Processed %d of %d collection elements.",o+=1,a),m<n)return p();if(o===a){for(r=0;r<u.length;r++)u[r][2]=u[r][1]/o;return v("Finished processing a collection."),t(null,u)}}}var y=r,j=e,w=t,E=g,A=b;function T(i,r){var e,t,n;if(e={},arguments.length>1){if(t=E(e,i))throw t;n=r}else n=i;if(!y(n))throw new TypeError("invalid argument. Last argument must be a function. Value: `"+n+"`.");return e.series?e.limit=1:e.limit||(e.limit=w),o;function o(i,r){if(!j(i))throw new TypeError("invalid argument. First argument must be a collection. Value: `"+i+".`");if(!y(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=T;function O(i,r,e,t){if(arguments.length<4)return C(r)(i,e);C(r,e)(i,t)}var V=i,F=O,P=T;V(F,"factory",P);export default F; //# sourceMappingURL=tabulate-by.js.map