UNPKG

@stdlib/esm

Version:

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

3 lines 2.04 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import e from"./../assert/is-nonnegative-integer-array.js";import r from"./../assert/is-integer.js";import o from"./base/shape2strides.js";import t from"./base/ind2sub.js";import i from"./../assert/is-plain-object.js";import n from"./../assert/has-own-property.js";import a from"./base/assert/is-order.js";import s from"./base/assert/is-index-mode.js";var m="throw",d="row-major",p={mode:m,order:d},u=i,l=n,f=a,g=s;function b(e,r){return u(r)?l(r,"mode")&&(e.mode=r.mode,!g(e.mode))?new TypeError("invalid option. `mode` option must be a supported/recognized mode. Option: `"+e.mode+"`."):l(r,"order")&&(e.order=r.order,!f(e.order))?new TypeError("invalid option. `order` option must be a supported/recognized order. Option: `"+e.order+"`."):null:new TypeError("invalid argument. Options must be an object. Value: `"+r+"`.")}var y=e.primitives,v=r.isPrimitive,w=o,j=t,h=p,c=b;function E(){var e,r,o,t,i,n;if((o={}).mode=h.mode,o.order=h.order,2===arguments.length)r=arguments[0],t=arguments[1];else if(3===arguments.length)if(v(arguments[1])){if(r=arguments[0],t=arguments[1],n=c(o,arguments[2]))throw n}else{if("object"!=typeof(i=arguments[0])||null===i)throw new TypeError("invalid argument. Output argument must be either an array, typed array, or object. Value: `"+i+"`.");r=arguments[1],t=arguments[2]}else{if("object"!=typeof(i=arguments[0])||null===i)throw new TypeError("invalid argument. Output argument must be either an array, typed array, or object. Value: `"+i+"`.");if(r=arguments[1],t=arguments[2],n=c(o,arguments[3]))throw n}if(!y(r))throw new TypeError("invalid argument. Shape argument must be an array-like object containing nonnegative integers. Value: `"+r+"`.");if(!v(t))throw new TypeError("invalid argument. Linear index argument must be integer valued. Value: `"+t+"`.");return void 0===i&&(i=new Array(r.length)),e=w(r,o.order),j(i,r,e,0,o.order,t,o.mode)}var T=E;export default T; //# sourceMappingURL=ind2sub.js.map