-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.js
4 lines (4 loc) · 10.2 KB
/
mod.js
1
2
3
4
// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
/// <reference types="./mod.d.ts" />
var r="function"==typeof Object.defineProperty?Object.defineProperty:null;var e=Object.defineProperty;function t(r){return"number"==typeof r}function n(r){var e,t="";for(e=0;e<r;e++)t+="0";return t}function i(r,e,t){var i=!1,o=e-r.length;return o<0||(function(r){return"-"===r[0]}(r)&&(i=!0,r=r.substr(1)),r=t?r+n(o):n(o)+r,i&&(r="-"+r)),r}var o=String.prototype.toLowerCase,a=String.prototype.toUpperCase;function u(r){var e,n,u;switch(r.specifier){case"b":e=2;break;case"o":e=8;break;case"x":case"X":e=16;break;default:e=10}if(n=r.arg,u=parseInt(n,10),!isFinite(u)){if(!t(n))throw new Error("invalid integer. Value: "+n);u=0}return u<0&&("u"===r.specifier||10!==e)&&(u=4294967295+u+1),u<0?(n=(-u).toString(e),r.precision&&(n=i(n,r.precision,r.padRight)),n="-"+n):(n=u.toString(e),u||r.precision?r.precision&&(n=i(n,r.precision,r.padRight)):n="",r.sign&&(n=r.sign+n)),16===e&&(r.alternate&&(n="0x"+n),n=r.specifier===a.call(r.specifier)?a.call(n):o.call(n)),8===e&&r.alternate&&"0"!==n.charAt(0)&&(n="0"+n),n}var c=Math.abs,s=String.prototype.toLowerCase,l=String.prototype.toUpperCase,p=String.prototype.replace,f=/e\+(\d)$/,g=/e-(\d)$/,d=/^(\d+)$/,h=/^(\d+)e/,y=/\.0$/,v=/\.0*e/,b=/(\..*[^0])0*e/;function w(r){var e,n,i=parseFloat(r.arg);if(!isFinite(i)){if(!t(r.arg))throw new Error("invalid floating-point number. Value: "+n);i=r.arg}switch(r.specifier){case"e":case"E":n=i.toExponential(r.precision);break;case"f":case"F":n=i.toFixed(r.precision);break;case"g":case"G":c(i)<1e-4?((e=r.precision)>0&&(e-=1),n=i.toExponential(e)):n=i.toPrecision(r.precision),r.alternate||(n=p.call(n,b,"$1e"),n=p.call(n,v,"e"),n=p.call(n,y,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return n=p.call(n,f,"e+0$1"),n=p.call(n,g,"e-0$1"),r.alternate&&(n=p.call(n,d,"$1."),n=p.call(n,h,"$1.e")),i>=0&&r.sign&&(n=r.sign+n),n=r.specifier===l.call(r.specifier)?l.call(n):s.call(n)}function m(r){var e,t="";for(e=0;e<r;e++)t+=" ";return t}var _=String.fromCharCode,S=Array.isArray;function E(r){return r!=r}function j(r){var e={};return e.specifier=r.specifier,e.precision=void 0===r.precision?1:r.precision,e.width=r.width,e.flags=r.flags||"",e.mapping=r.mapping,e}function T(r){var e,t,n,o,a,c,s,l,p,f,g,d,h;if(!S(r))throw new TypeError("invalid argument. First argument must be an array. Value: `"+r+"`.");for(c="",s=1,l=0;l<r.length;l++)if(n=r[l],"string"==typeof n)c+=n;else{if(e=void 0!==n.precision,!(n=j(n)).specifier)throw new TypeError("invalid argument. Token is missing `specifier` property. Index: `"+l+"`. Value: `"+n+"`.");for(n.mapping&&(s=n.mapping),t=n.flags,p=0;p<t.length;p++)switch(o=t.charAt(p)){case" ":n.sign=" ";break;case"+":n.sign="+";break;case"-":n.padRight=!0,n.padZeros=!1;break;case"0":n.padZeros=t.indexOf("-")<0;break;case"#":n.alternate=!0;break;default:throw new Error("invalid flag: "+o)}if("*"===n.width){if(n.width=parseInt(arguments[s],10),s+=1,E(n.width))throw new TypeError("the argument for * width at position "+s+" is not a number. Value: `"+n.width+"`.");n.width<0&&(n.padRight=!0,n.width=-n.width)}if(e&&"*"===n.precision){if(n.precision=parseInt(arguments[s],10),s+=1,E(n.precision))throw new TypeError("the argument for * precision at position "+s+" is not a number. Value: `"+n.precision+"`.");n.precision<0&&(n.precision=1,e=!1)}switch(n.arg=arguments[s],n.specifier){case"b":case"o":case"x":case"X":case"d":case"i":case"u":e&&(n.padZeros=!1),n.arg=u(n);break;case"s":n.maxWidth=e?n.precision:-1,n.arg=String(n.arg);break;case"c":if(!E(n.arg)){if((a=parseInt(n.arg,10))<0||a>127)throw new Error("invalid character code. Value: "+n.arg);n.arg=E(a)?String(n.arg):_(a)}break;case"e":case"E":case"f":case"F":case"g":case"G":e||(n.precision=6),n.arg=w(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=i(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=(f=n.arg,g=n.width,d=n.padRight,h=void 0,(h=g-f.length)<0?f:f=d?f+m(h):m(h)+f)),c+=n.arg||"",s+=1}return c}var k=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function x(r){var e={mapping:r[1]?parseInt(r[1],10):void 0,flags:r[2],width:r[3],precision:r[5],specifier:r[6]};return"."===r[4]&&void 0===r[5]&&(e.precision="1"),e}function O(r){var e,t,n,i;for(t=[],i=0,n=k.exec(r);n;)(e=r.slice(i,k.lastIndex-n[0].length)).length&&t.push(e),t.push(x(n)),i=k.lastIndex,n=k.exec(r);return(e=r.slice(i)).length&&t.push(e),t}function I(r){var e,t;if("string"!=typeof r)throw new TypeError(I("invalid argument. First argument must be a string. Value: `%s`.",r));for(e=[O(r)],t=1;t<arguments.length;t++)e.push(arguments[t]);return T.apply(null,e)}var V=Object.prototype,A=V.toString,F=V.__defineGetter__,N=V.__defineSetter__,P=V.__lookupGetter__,$=V.__lookupSetter__;var R=function(){try{return r({},"x",{}),!0}catch(r){return!1}}()?e:function(r,e,t){var n,i,o,a;if("object"!=typeof r||null===r||"[object Array]"===A.call(r))throw new TypeError(I("invalid argument. First argument must be an object. Value: `%s`.",r));if("object"!=typeof t||null===t||"[object Array]"===A.call(t))throw new TypeError(I("invalid argument. Property descriptor must be an object. Value: `%s`.",t));if((i="value"in t)&&(P.call(r,e)||$.call(r,e)?(n=r.__proto__,r.__proto__=V,delete r[e],r[e]=t.value,r.__proto__=n):r[e]=t.value),o="get"in t,a="set"in t,i&&(o||a))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return o&&F&&F.call(r,e,t.get),a&&N&&N.call(r,e,t.set),r};function C(r,e,t){R(r,e,{configurable:!1,enumerable:!1,writable:!1,value:t})}function G(r,e,t){R(r,e,{configurable:!1,enumerable:!1,get:t})}function M(r){return"number"==typeof r}var Z="function"==typeof Symbol&&"symbol"==typeof Symbol("foo");function B(){return Z&&"symbol"==typeof Symbol.toStringTag}var J=Object.prototype.toString;var L=Object.prototype.hasOwnProperty;var W="function"==typeof Symbol?Symbol:void 0,U="function"==typeof W?W.toStringTag:"";var X=B()?function(r){var e,t,n,i,o;if(null==r)return J.call(r);t=r[U],o=U,e=null!=(i=r)&&L.call(i,o);try{r[U]=void 0}catch(e){return J.call(r)}return n=J.call(r),e?r[U]=t:delete r[U],n}:function(r){return J.call(r)},z=Number,Y=z.prototype.toString;var q=B();function D(r){return"object"==typeof r&&(r instanceof z||(q?function(r){try{return Y.call(r),!0}catch(r){return!1}}(r):"[object Number]"===X(r)))}function H(r){return M(r)||D(r)}C(H,"isPrimitive",M),C(H,"isObject",D);var K=Number.POSITIVE_INFINITY,Q=z.NEGATIVE_INFINITY,rr=Math.floor;function er(r){return r<K&&r>Q&&rr(e=r)===e;var e}function tr(r){return M(r)&&er(r)}function nr(r){return D(r)&&er(r.valueOf())}function ir(r){return tr(r)||nr(r)}function or(r){return null===r}function ar(r){return void 0===r}function ur(r){return tr(r)||or(r)||ar(r)}function cr(){var r,e,t,n;if(0===(r=arguments.length)?(e=null,t=null,n=null):1===r?(e=null,t=arguments[0],n=null):2===r?(e=arguments[0],t=arguments[1],n=null):(e=arguments[0],t=arguments[1],n=arguments[2]),!(this instanceof cr))return new cr(e,t,n);if(!ur(e))throw new TypeError(I("invalid argument. First argument must be an integer, null, or undefined. Value: `%s`.",e));if(!ur(t))throw new TypeError(I("invalid argument. Second argument must be an integer, null, or undefined. Value: `%s`.",t));if(!ur(n))throw new TypeError(I("invalid argument. Third argument must be an integer, null, or undefined. Value: `%s`.",n));if(0===n)throw new RangeError(I("invalid argument. Third argument cannot be zero. Value: `%s`.",n));return this._start=void 0===e?null:e,this._stop=void 0===t?null:t,this._step=void 0===n?null:n,this}function sr(){return/^\s*function\s*([^(]*)/i}C(ir,"isPrimitive",tr),C(ir,"isObject",nr),C(cr,"name","Slice"),G(cr.prototype,"start",(function(){return this._start})),G(cr.prototype,"stop",(function(){return this._stop})),G(cr.prototype,"step",(function(){return this._step})),C(cr.prototype,"toString",(function(){return"Slice("+this._start+","+this._stop+","+this.step+")"})),C(cr.prototype,"toJSON",(function(){return{type:"Slice",data:[this._start,this._stop,this._step]}}));var lr=/^\s*function\s*([^(]*)/i;C(sr,"REGEXP",lr);var pr=Array.isArray?Array.isArray:function(r){return"[object Array]"===X(r)};function fr(r){return null!==r&&"object"==typeof r}function gr(r){var e,t,n,i;if(("Object"===(t=X(r).slice(8,-1))||"Error"===t)&&r.constructor){if("string"==typeof(n=r.constructor).name)return n.name;if(e=lr.exec(n.toString()))return e[1]}return fr(i=r)&&(i._isBuffer||i.constructor&&"function"==typeof i.constructor.isBuffer&&i.constructor.isBuffer(i))?"Buffer":t}function dr(){var r,e=arguments,t="https://stdlib.io/e/"+e[0]+"?";for(r=1;r<e.length;r++)t+="&arg[]="+encodeURIComponent(e[r]);return t}function hr(r){return tr(r)||or(r)||ar(r)||function(r){return r instanceof cr||"Slice"===gr(r)}(r)}function yr(){var r,e,t,n,i;if(r=arguments.length,!(this instanceof yr)){if(1===r)return new yr(arguments[0]);if(2===r)return new yr(arguments[0],arguments[1]);if(3===r)return new yr(arguments[0],arguments[1],arguments[2]);if(4===r)return new yr(arguments[0],arguments[1],arguments[2],arguments[3]);if(5===r)return new yr(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4]);for(t=[],i=0;i<r;i++)t.push(arguments[i]);return e=Object.create(yr.prototype),yr.apply(e,t)}for(this._data=[],i=0;i<r;i++){if(!hr(n=arguments[i]))throw new TypeError(dr("1j1Em",i,String(n)));this._data.push(void 0===n?null:n)}return this}C(fr,"isObjectLikeArray",function(r){if("function"!=typeof r)throw new TypeError(I("invalid argument. Must provide a function. Value: `%s`.",r));return function(e){var t,n;if(!pr(e))return!1;if(0===(t=e.length))return!1;for(n=0;n<t;n++)if(!1===r(e[n]))return!1;return!0}}(fr)),C(yr,"name","MultiSlice"),G(yr.prototype,"ndims",(function(){return this._data.length})),G(yr.prototype,"data",(function(){return this._data.slice()})),C(yr.prototype,"toString",(function(){var r,e,t;for(r=this._data,e=[],t=0;t<r.length;t++)e.push(String(r[t]));return"MultiSlice("+e.join(",")+")"})),C(yr.prototype,"toJSON",(function(){var r,e,t,n;for(r=this._data,e={type:"MultiSlice",data:[]},n=0;n<r.length;n++)t=r[n],e.data.push(t&&"function"==typeof t.toJSON?t.toJSON():t);return e}));export{yr as default};
//# sourceMappingURL=mod.js.map