@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 12.9 kB
JavaScript
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
import r from"./../assert/is-string-array.js";import e from"./../assert/is-string.js";import t from"./../assert/is-arraybuffer.js";import n from"./../assert/is-function.js";import i from"./../assert/is-integer.js";import o from"./../assert/is-object.js";import a from"./../assert/is-collection.js";import u from"./../assert/has-own-property.js";import s from"./../assert/has-iterator-symbol-support.js";import l from"./properties-in.js";import f from"./../array/typed.js";import h from"./../array/int8.js";import m from"./../array/dtype.js";import p from"./define-property.js";import v from"./define-nonenumerable-property.js";import c from"./define-nonenumerable-read-only-accessor.js";import d from"./define-nonenumerable-read-write-accessor.js";import w from"./../math/base/special/floor.js";import g from"./../symbol/iterator.js";import y from"./../assert/is-plain-object.js";import b from"./../array/typed-dtypes.js";function E(r,e){var t;for(t=0;t<r.length;t++)if(r[t]===e)return!0;return!1}var T=u;function j(r){var e,t;for(e={},t=0;t<r.length;t++){if(T(e,r[t]))return!1;e[r[t]]=!0}return!0}var V=y,F=u,S=e.isPrimitive,O=b,N=E,x=O();function k(r,e){if(!V(e))return new TypeError("invalid argument. Options must be an object. Value: `"+e+"`.");if(F(e,"dtype")){if(r.dtype=e.dtype,!S(r.dtype))return new TypeError("invalid option. `dtype` option must be a string. Option: `"+r.dtype+"`.");if(!N(x,r.dtype))return new Error("invalid option. `dtype` option must be a recognized data type. Option: `"+r.dtype+"`.")}return F(e,"name")&&(r.name=e.name,!S(r.name))?new TypeError("invalid option. `name` option must be a string. Option: `"+r.name+"`."):null}function P(r,e){return r-e}function R(r){var e,t;for(e=[];void 0!==(t=r.next()).value&&e.push(t.value),!t.done;);return e}function M(r,e,t,n){var i,o,a;for(i=[],a=-1;a+=1,void 0!==(o=e.next()).value&&i.push(t.call(n,o.value,a,r[a])),!o.done;);return i}var _=r.primitives,z=e.isPrimitive,A=t,B=n,I=i.isPrimitive,J=o,L=a,Y=u,q=s,C=l,D=f,G=h,H=m,K=p,Q=v,U=c,W=d,X=w,Z=g,$=E,rr=j,er=k,tr=P,nr=R,ir=M,or=C(new G(0)),ar=q();function ur(r,e){var t,n,i,o,a;if(!_(r))throw new TypeError("invalid argument. Must provide an array of strings. Value: `"+r+"`.");if(!rr(r))throw new TypeError("invalid argument. Field names must be distinct. Value: `"+r+"`.");for(n=r.slice(),t=n.length,a=0;a<t;a++)if($(or,n[a]))throw new Error("invalid argument. Provided field name is reserved. Name: `"+n[a]+"`.");if(i={dtype:"float64",name:"tuple"},arguments.length>1&&(o=er(i,e)))throw o;function u(){var r,e,o,a,s;if((a=(o=arguments.length)<=0?D(t,i.dtype):1===o?z(arguments[0])?D(t,arguments[0]):A(arguments[0])?D(arguments[0],0,t,i.dtype):D(arguments[0],i.dtype):2===o?A(arguments[0])?z(arguments[1])?D(arguments[0],0,t,arguments[1]):D(arguments[0],arguments[1],t,i.dtype):D(arguments[0],arguments[1]):D(arguments[0],arguments[1],t,arguments[2])).length!==t)throw new RangeError("invalid arguments. Arguments are incompatible with number of tuple fields. Number of fields: `"+t+"`. Number of data elements: `"+a.length+"`.");for(e=H(a),r=[],s=0;s<t;s++)r.push(s),W(a,n[s],l(s),f(s));return Q(a,"name",i.name),U(a,"fields",h),U(a,"orderedFields",m),Q(a,"entries",p),Q(a,"every",v),Q(a,"fieldOf",c),Q(a,"filter",d),Q(a,"find",w),Q(a,"findIndex",y),Q(a,"findField",g),Q(a,"forEach",b),Q(a,"ind2key",E),Q(a,"key2ind",T),Q(a,"keys",j),Q(a,"lastFieldOf",V),Q(a,"map",F),Q(a,"reduce",S),Q(a,"reduceRight",O),Q(a,"reverse",N),Q(a,"slice",x),Q(a,"some",k),Q(a,"sort",P),Q(a,"subtuple",R),Q(a,"toJSON",M),Q(a,"toString",_),a;function l(e){return function(){return a[r[e]]}}function f(e){return function(t){a[r[e]]=t}}function h(){return n.slice()}function m(){var e,i;for(e=n.slice(),i=0;i<t;i++)e[i]=n[r[i]];return e}function p(){var e,i,o,u;if((e=this)!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");return u=-1,K(i={},"next",{configurable:!1,enumerable:!1,writable:!1,value:function(){if(u+=1,o||u>=t)return{done:!0};return{value:[u,n[r[u]],a[u]],done:!1}}}),K(i,"return",{configurable:!1,enumerable:!1,writable:!1,value:function(r){if(o=!0,arguments.length)return{value:r,done:!0};return{done:!0}}}),ar&&K(i,Z,{configurable:!1,enumerable:!1,writable:!1,value:function(){return e.entries()}}),i}function v(e,i){var o;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!B(e))throw new TypeError("invalid argument. First argument must be a function. Value: `"+e+"`.");for(o=0;o<t;o++)if(!e.call(i,a[o],o,n[r[o]],a))return!1;return!0}function c(e){var i;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(arguments.length>1){if(!I(i=arguments[0]))throw new TypeError("invalid argument. Second argument must be an integer. Value: `"+i+"`.");if(i>=t)return;i<0&&(i=t+i)<0&&(i=0)}else i=0;for(;i<t;i++)if(a[i]===e)return n[r[i]]}function d(o,s){var l,f,h;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!B(o))throw new TypeError("invalid argument. First argument must be a function. Value: `"+o+"`.");for(l=[],f=[],h=0;h<t;h++)o.call(s,a[h],h,n[r[h]],a)&&(f.push(n[r[h]]),l.push(a[h]));return f.length===t?u(l,e):f.length?ur(f,i)(l):null}function w(e,i){var o;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!B(e))throw new TypeError("invalid argument. First argument must be a function. Value: `"+e+"`.");for(o=0;o<t;o++)if(e.call(i,a[o],o,n[r[o]],a))return a[o]}function g(e,i){var o,u;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!B(e))throw new TypeError("invalid argument. First argument must be a function. Value: `"+e+"`.");for(u=0;u<t;u++)if(o=n[r[u]],e.call(i,a[u],u,o,a))return o}function y(e,i){var o;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!B(e))throw new TypeError("invalid argument. First argument must be a function. Value: `"+e+"`.");for(o=0;o<t;o++)if(e.call(i,a[o],o,n[r[o]],a))return o;return-1}function b(e,i){var o;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!B(e))throw new TypeError("invalid argument. First argument must be a function. Value: `"+e+"`.");for(o=0;o<t;o++)e.call(i,a[o],o,n[r[o]],a)}function E(e){if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!I(e))throw new TypeError("invalid argument. Must provide an integer. Value: `"+e+"`.");if(e<0&&(e=t-e),!(e<0||e>=t))return n[r[e]]}function T(e){var i;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!z(e))throw new TypeError("invalid argument. First argument must be a string. Value: `"+e+"`.");for(i=0;i<t;i++)if(n[r[i]]===e)return i;return-1}function j(){var e,i,o,u;if((e=this)!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");return u=-1,K(i={},"next",{configurable:!1,enumerable:!1,writable:!1,value:function(){if(u+=1,o||u>=t)return{done:!0};return{value:[u,n[r[u]]],done:!1}}}),K(i,"return",{configurable:!1,enumerable:!1,writable:!1,value:function(r){if(o=!0,arguments.length)return{value:r,done:!0};return{done:!0}}}),ar&&K(i,Z,{configurable:!1,enumerable:!1,writable:!1,value:function(){return e.keys()}}),i}function V(e){var i;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(arguments.length>1){if(!I(i=arguments[0]))throw new TypeError("invalid argument. Second argument must be an integer. Value: `"+i+"`.");if(i>=t)i=t-1;else if(i<0&&(i=t+i)<0)return}else i=t-1;for(;i>=0;i--)if(a[i]===e)return n[r[i]]}function F(i,o){var s,l;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!B(i))throw new TypeError("invalid argument. First argument must be a function. Value: `"+i+"`.");for(s=u(e),l=0;l<t;l++)s[l]=i.call(o,a[l],l,n[r[l]],a);return s}function S(e){var i,o;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!B(e))throw new TypeError("invalid argument. First argument must be a function. Value: `"+e+"`.");for(arguments.length>1?(i=arguments[1],o=0):(i=a[0],o=1);o<t;o++)i=e(i,a[o],o,n[r[o]],a);return i}function O(e){var i,o;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!B(e))throw new TypeError("invalid argument. First argument must be a function. Value: `"+e+"`.");for(arguments.length>1?(i=arguments[1],o=t-1):(i=a[t-1],o=t-2);o>=0;o--)i=e(i,a[o],o,n[r[o]],a);return i}function N(){var e,n,i;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");for(n=0;n<X(t/2);n++)i=t-n-1,e=a[n],a[n]=a[i],a[i]=e;for(n=0;n<t;n++)r[n]=t-r[n]-1;return a}function x(o,s){var l,f,h,m;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(0===arguments.length)return u(a,e);if(!I(h=o))throw new TypeError("invalid argument. First argument must be an integer. Value: `"+o+"`.");if(h<0&&(h=t+h)<0&&(h=0),1===arguments.length)m=t;else{if(!I(m=s))throw new TypeError("invalid argument. Second argument must be an integer. Value: `"+s+"`.");m<0?(m=t+m)<0&&(m=0):m>t&&(m=t)}if(h>=m)return null;for(f=[],l=[];h<m;h++)f.push(n[r[h]]),l.push(a[h]);return ur(f,i)(l,e)}function k(e,i){var o;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(!B(e))throw new TypeError("invalid argument. First argument must be a function. Value: `"+e+"`.");for(o=0;o<t;o++)if(e.call(i,a[o],o,n[r[o]],a))return!0;return!1}function P(e){var n,i,o,u,s,l;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(arguments.length){if(!B(e))throw new TypeError("invalid argument. First argument must be a function. Value: `"+e+"`.");n=e}else n=tr;for(r.sort(f),i=r.slice(),o=0;o<t;o++)if(i[o]!==o){for(l=a[o],s=i[u=o];s!==o;)a[u]=a[s],i[u]=u,s=i[u=s];a[u]=l,i[u]=u}return a;function f(e,t){var i=a[r[e]],o=a[r[t]];return n(i,o)}}function R(o,s){var l,f,h,m;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");if(0===arguments.length)return u(a.buffer,a.byteOffset,e);if(!I(f=o))throw new TypeError("invalid argument. First argument must be an integer. Value: `"+o+"`.");if(f<0&&(f=t+f)<0&&(f=0),1===arguments.length)h=t;else{if(!I(h=s))throw new TypeError("invalid argument. Second argument must be an integer. Value: `"+s+"`.");h<0?(h=t+h)<0&&(h=0):h>t&&(h=t)}if(f>=h)return null;for(l=[],m=f;m<h;m++)l.push(n[r[m]]);return ur(l,i)(a.buffer,a.byteOffset+f*a.BYTES_PER_ELEMENT,e)}function M(){var e,i;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");for(e={},i=0;i<t;i++)e[n[i]]=a[r[i]];return e}function _(){var e,o;if(this!==a)throw new TypeError("invalid invocation. `this` is not host tuple.");for(e=i.name+"(",o=0;o<t;o++)e+=n[o],e+="=",e+=a[r[o]],o<t-1&&(e+=", ");return e+=")"}}return K(u,"from",{configurable:!1,enumerable:!1,writable:!1,value:function(r){var e,o,a,s,l,f;if(this!==u)throw new TypeError("invalid invocation. `this` is not the host tuple factory.");if((o=arguments.length)>1){if(!B(s=arguments[1]))throw new TypeError("invalid argument. Second argument must be a function. Value: `"+s+"`.");o>2&&(e=arguments[2])}if(L(r)){if(r.length!==t)throw new RangeError("invalid argument. Source is incompatible with number of tuple fields. Number of fields: `"+t+"`. Source length: `"+r.length+"`.");if(a=u(t,i.dtype),s)for(f=0;f<t;f++)a[f]=s.call(e,r[f],f,n[f]);else for(f=0;f<t;f++)a[f]=r[f]}else{if(!(J(r)&&ar&&B(r[Z])))throw new TypeError("invalid argument. First argument must be an array-like object or an iterable. Value: `"+r+"`.");if(l=r[Z](),!B(l.next))throw new TypeError("invalid argument. First argument must be an array-like object or an iterable.");a=u(s?ir(n,l,s,e):nr(l),i.dtype)}return a}}),K(u,"fromObject",{configurable:!1,enumerable:!1,writable:!1,value:function(r){var e,o,a,s,l,f;if(this!==u)throw new TypeError("invalid invocation. `this` is not the host tuple factory.");if(null===r||"object"!=typeof r)throw new TypeError("invalid argument. First argument must be an object. Value: `"+r+"`.");if((o=arguments.length)>1){if(!B(s=arguments[1]))throw new TypeError("invalid argument. Second argument must be a function. Value: `"+s+"`.");o>2&&(e=arguments[2])}if(a=u(t,i.dtype),s)for(f=0;f<t;f++)l=n[f],Y(r,l)&&(a[f]=s.call(e,r[l],l));else for(f=0;f<t;f++)l=n[f],Y(r,l)&&(a[f]=r[l]);return a}}),K(u,"of",{configurable:!1,enumerable:!1,writable:!1,value:function(){var r,e;if(this!==u)throw new TypeError("invalid invocation. `this` is not the host tuple factory.");if(arguments.length!==t)throw new RangeError("invalid invocation. Number of arguments incompatible with number of tuple fields. Number of fields: `"+t+"`. Number of arguments: `"+arguments.length+"`.");for(r=[],e=0;e<arguments.length;e++)r.push(arguments[e]);return u(r)}}),u}var sr=ur;export default sr;
//# sourceMappingURL=named-typed-tuple.js.map