-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.js
More file actions
4 lines (4 loc) · 6.13 KB
/
mod.js
File metadata and controls
4 lines (4 loc) · 6.13 KB
1
2
3
4
// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
/// <reference types="./mod.d.ts" />
var e="function"==typeof Object.defineProperty?Object.defineProperty:null;var r=Object.defineProperty;function i(e){return"number"==typeof e}function t(e){var r,i="";for(r=0;r<e;r++)i+="0";return i}function a(e,r,i){var a=!1,n=r-e.length;return n<0||(function(e){return"-"===e[0]}(e)&&(a=!0,e=e.substr(1)),e=i?e+t(n):t(n)+e,a&&(e="-"+e)),e}var n=String.prototype.toLowerCase,o=String.prototype.toUpperCase;function s(e){var r,t,s;switch(e.specifier){case"b":r=2;break;case"o":r=8;break;case"x":case"X":r=16;break;default:r=10}if(t=e.arg,s=parseInt(t,10),!isFinite(s)){if(!i(t))throw new Error("invalid integer. Value: "+t);s=0}return s<0&&("u"===e.specifier||10!==r)&&(s=4294967295+s+1),s<0?(t=(-s).toString(r),e.precision&&(t=a(t,e.precision,e.padRight)),t="-"+t):(t=s.toString(r),s||e.precision?e.precision&&(t=a(t,e.precision,e.padRight)):t="",e.sign&&(t=e.sign+t)),16===r&&(e.alternate&&(t="0x"+t),t=e.specifier===o.call(e.specifier)?o.call(t):n.call(t)),8===r&&e.alternate&&"0"!==t.charAt(0)&&(t="0"+t),t}var c=Math.abs,p=String.prototype.toLowerCase,l=String.prototype.toUpperCase,u=String.prototype.replace,f=/e\+(\d)$/,g=/e-(\d)$/,d=/^(\d+)$/,h=/^(\d+)e/,w=/\.0$/,b=/\.0*e/,v=/(\..*[^0])0*e/;function y(e,r){var i,t;switch(r.specifier){case"e":case"E":t=e.toExponential(r.precision);break;case"f":case"F":t=e.toFixed(r.precision);break;case"g":case"G":c(e)<1e-4?((i=r.precision)>0&&(i-=1),t=e.toExponential(i)):t=e.toPrecision(r.precision),r.alternate||(t=u.call(t,v,"$1e"),t=u.call(t,b,"e"),t=u.call(t,w,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return t=u.call(t,f,"e+0$1"),t=u.call(t,g,"e-0$1"),r.alternate&&(t=u.call(t,d,"$1."),t=u.call(t,h,"$1.e")),e>=0&&r.sign&&(t=r.sign+t),t=r.specifier===l.call(r.specifier)?l.call(t):p.call(t)}function m(e){var r,i="";for(r=0;r<e;r++)i+=" ";return i}var _=String.fromCharCode,k=Array.isArray;function x(e){return e!=e}function E(e){var r={};return r.specifier=e.specifier,r.precision=void 0===e.precision?1:e.precision,r.width=e.width,r.flags=e.flags||"",r.mapping=e.mapping,r}function S(e){var r,t,n,o,c,p,l,u,f,g,d,h,w,b;if(!k(e))throw new TypeError("invalid argument. First argument must be an array. Value: `"+e+"`.");for(p="",l=1,f=0;f<e.length;f++)if(n=e[f],"string"==typeof n)p+=n;else{if(r=void 0!==n.precision,!(n=E(n)).specifier)throw new TypeError("invalid argument. Token is missing `specifier` property. Index: `"+f+"`. Value: `"+n+"`.");for(n.mapping&&(l=n.mapping),t=n.flags,g=0;g<t.length;g++)switch(o=t.charAt(g)){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[l],10),l+=1,x(n.width))throw new TypeError("the argument for * width at position "+l+" is not a number. Value: `"+n.width+"`.");n.width<0&&(n.padRight=!0,n.width=-n.width)}if(r&&"*"===n.precision){if(n.precision=parseInt(arguments[l],10),l+=1,x(n.precision))throw new TypeError("the argument for * precision at position "+l+" is not a number. Value: `"+n.precision+"`.");n.precision<0&&(n.precision=1,r=!1)}switch(n.arg=arguments[l],n.specifier){case"b":case"o":case"x":case"X":case"d":case"i":case"u":r&&(n.padZeros=!1),n.arg=s(n);break;case"s":n.maxWidth=r?n.precision:-1,n.arg=String(n.arg);break;case"c":if(!x(n.arg)){if((c=parseInt(n.arg,10))<0||c>127)throw new Error("invalid character code. Value: "+n.arg);n.arg=x(c)?String(n.arg):_(c)}break;case"e":case"E":case"f":case"F":case"g":case"G":if(r||(n.precision=6),u=parseFloat(n.arg),!isFinite(u)){if(!i(n.arg))throw new Error("invalid floating-point number. Value: "+p);u=n.arg,n.padZeros=!1}n.arg=y(u,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=a(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=(d=n.arg,h=n.width,w=n.padRight,b=void 0,(b=h-d.length)<0?d:d=w?d+m(b):m(b)+d)),p+=n.arg||"",l+=1}return p}var V=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function j(e){var r={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(r.precision="1"),r}function $(e){var r,i,t,a;for(i=[],a=0,t=V.exec(e);t;)(r=e.slice(a,V.lastIndex-t[0].length)).length&&i.push(r),"%"===t[6]?i.push("%"):i.push(j(t)),a=V.lastIndex,t=V.exec(e);return(r=e.slice(a)).length&&i.push(r),i}function F(e){var r,i;if("string"!=typeof e)throw new TypeError(F("invalid argument. First argument must be a string. Value: `%s`.",e));for(r=[$(e)],i=1;i<arguments.length;i++)r.push(arguments[i]);return S.apply(null,r)}var I,T=Object.prototype,A=T.toString,C=T.__defineGetter__,R=T.__defineSetter__,Z=T.__lookupGetter__,O=T.__lookupSetter__;function P(e,r,i){var t,a,n,o,s;for(t=e.length,a=i,n=i,s=0;s<t;s++){if(0===e[s])return[i,i];(o=r[s])>0?n+=o*(e[s]-1):o<0&&(a+=o*(e[s]-1))}return[a,n]}function G(e,r,i,t){var a=P(r,i,t);return a[0]>=0&&a[1]<e}I=function(){try{return e({},"x",{}),!0}catch(e){return!1}}()?r:function(e,r,i){var t,a,n,o;if("object"!=typeof e||null===e||"[object Array]"===A.call(e))throw new TypeError(F("invalid argument. First argument must be an object. Value: `%s`.",e));if("object"!=typeof i||null===i||"[object Array]"===A.call(i))throw new TypeError(F("invalid argument. Property descriptor must be an object. Value: `%s`.",i));if((a="value"in i)&&(Z.call(e,r)||O.call(e,r)?(t=e.__proto__,e.__proto__=T,delete e[r],e[r]=i.value,e.__proto__=t):e[r]=i.value),n="get"in i,o="set"in i,a&&(n||o))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return n&&C&&C.call(e,r,i.get),o&&R&&R.call(e,r,i.set),e},I(P,"assign",{configurable:!1,enumerable:!1,writable:!1,value:function(e,r,i,t){var a,n,o,s,c;for(a=e.length,n=i,o=i,c=0;c<a;c++){if(0===e[c])return t[0]=i,t[1]=i,t;(s=r[c])>0?o+=s*(e[c]-1):s<0&&(n+=s*(e[c]-1))}return t[0]=n,t[1]=o,t}});export{G as default};
//# sourceMappingURL=mod.js.map