UNPKG

@stdlib/esm

Version:

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

3 lines 2.12 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import e from"./../utils/define-nonenumerable-read-only-property.js";import r from"./../assert/has-own-property.js";import t from"./../assert/is-function.js";import n from"./../assert/is-array-like-object.js";import i from"./../assert/is-plain-object.js";import o from"./../assert/is-nonnegative-integer.js";import a from"./../symbol/iterator.js";var l=e,u=r,s=t,d=n,m=i,f=o.isPrimitive,p=a;function g(e){var r,t,n,i,o,a,h,c;if(!d(e))throw new TypeError("invalid argument. First argument must be an array-like object. Value: `"+e+"`.");if(i={iter:1e308,dir:1},arguments.length>1)if(m(arguments[1])){if(t=arguments[1],arguments.length>2){if(!s(h=arguments[2]))throw new TypeError("invalid argument. Callback argument must be a function. Value: `"+h+"`.");r=arguments[3]}if(u(t,"iter")&&(i.iter=t.iter,!f(t.iter)))throw new TypeError("invalid option. `iter` option must be a nonnegative integer. Option: `"+t.iter+"`.");if(u(t,"dir")&&(i.dir=t.dir,1!==t.dir&&-1!==t.dir))throw new TypeError("invalid option. `dir` option must be either `1` or `-1`. Option: `"+t.dir+"`.")}else{if(!s(h=arguments[1]))throw new TypeError("invalid argument. Second argument must be either a function or an options object. Value: `"+h+"`.");r=arguments[2]}return n=0,o={},h?1===i.dir?(c=-1,l(o,"next",v)):(c=e.length,l(o,"next",b)):1===i.dir?(c=-1,l(o,"next",j)):(c=e.length,l(o,"next",w)),l(o,"return",y),p&&l(o,p,x),o;function v(){return c=(c+1)%e.length,n+=1,a||n>i.iter||0===e.length?{done:!0}:{value:h.call(r,e[c],c,n,e),done:!1}}function b(){return(c-=1)<0&&(c+=e.length),n+=1,a||n>i.iter||0===e.length?{done:!0}:{value:h.call(r,e[c],c,n,e),done:!1}}function j(){return c=(c+1)%e.length,n+=1,a||n>i.iter||0===e.length?{done:!0}:{value:e[c],done:!1}}function w(){return(c-=1)<0&&(c+=e.length),n+=1,a||n>i.iter||0===e.length?{done:!0}:{value:e[c],done:!1}}function y(e){return a=!0,arguments.length?{value:e,done:!0}:{done:!0}}function x(){return h?g(e,i,h,r):g(e,i)}}var h=g;export default h; //# sourceMappingURL=to-circular-iterator.js.map