import{e as _}from"./index.RuhrnD1v.js";const a={not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,decimal_number:/[diefgu]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(,|_)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/},h=Object.create(null);function m(o,i=","){let n="",s=o;(s.startsWith("-")||s.startsWith("+"))&&(n=s[0],s=s.slice(1));const p=s.indexOf(".");let c,l;p!==-1?(c=s.slice(0,p),l=s.slice(p)):c=s;const e=c.replace(/\B(?=(\d{3})+(?!\d))/g,i);return n+e+(l??"")}function k(o,i){let n=1;const s=o.length;let p="";for(let c=0;c<s;c++){const l=o[c];if(typeof l=="string"){p+=l;continue}const e=l;let r;if(e.keys){r=i[n];for(let d=0;d<e.keys.length;d++){if(_(r))throw new Error(`[sprintf] Cannot access property "${e.keys[d]}" of undefined value "${e.keys[d-1]}"`);r=r[e.keys[d]]}}else e.param_no?r=i[parseInt(e.param_no,10)]:r=i[n++];if(a.not_type.test(e.type)&&a.not_primitive.test(e.type)&&typeof r=="function"&&(r=r()),a.numeric_arg.test(e.type)&&typeof r!="number"&&isNaN(r))throw new TypeError(`[sprintf] expecting number but found ${Object.prototype.toString.call(r)}`);let g=!0;a.number.test(e.type)&&(g=r>=0);let t;switch(e.type){case"b":t=parseInt(String(r),10).toString(2);break;case"c":t=String.fromCharCode(parseInt(String(r),10));break;case"d":case"i":t=String(parseInt(String(r),10));break;case"j":t=JSON.stringify(r,null,e.width?parseInt(e.width):0);break;case"e":t=e.precision?parseFloat(String(r)).toExponential(parseInt(e.precision,10)):parseFloat(String(r)).toExponential();break;case"f":t=e.precision?parseFloat(String(r)).toFixed(parseInt(e.precision,10)):String(parseFloat(String(r)));break;case"g":t=e.precision?String(Number(r.toPrecision(parseInt(e.precision,10)))):String(parseFloat(String(r)));break;case"o":t=(parseInt(String(r),10)>>>0).toString(8);break;case"s":t=String(r),t=e.precision?t.substring(0,parseInt(e.precision,10)):t;break;case"t":t=String(!!r),t=e.precision?t.substring(0,parseInt(e.precision,10)):t;break;case"T":t=Object.prototype.toString.call(r).slice(8,-1).toLowerCase(),t=e.precision?t.substring(0,parseInt(e.precision,10)):t;break;case"u":t=String(parseInt(String(r),10)>>>0);break;case"v":t=String(r.valueOf()),t=e.precision?t.substring(0,parseInt(e.precision,10)):t;break;case"x":t=(parseInt(String(r),10)>>>0).toString(16);break;case"X":t=(parseInt(String(r),10)>>>0).toString(16).toUpperCase();break;default:t=String(r)}if(a.json.test(e.type))p+=t;else{let d="";if(a.number.test(e.type)&&(!g||e.sign)&&(d=g?"+":"-",t=t.replace(a.sign,"")),e.thousand_sep&&a.decimal_number.test(e.type)){let u;e.thousand_sep==="_"?u="_":e.pad_char?.startsWith("'")?u=e.pad_char.charAt(1):u=",",t=m(t,u)}const b=e.pad_char?e.pad_char==="0"?"0":e.pad_char.charAt(1):" ",y=e.width?parseInt(e.width,10):0,S=y-(d+t).length,f=y&&S>0?b.repeat(S):"";p+=e.align?d+t+f:b==="0"?d+f+t:f+d+t}}return p}function x(o){if(h[o])return h[o];let i=o,n;const s=[];let p=0;for(;i;){if((n=a.text.exec(i))!==null)s.push(n[0]);else if((n=a.modulo.exec(i))!==null)s.push("%");else if((n=a.placeholder.exec(i))!==null){if(n[2]){p|=1;const c=[];let l=n[2],e;if((e=a.key.exec(l))!==null)for(c.push(e[1]);(l=l.substring(e[0].length))!=="";)if((e=a.key_access.exec(l))!==null)c.push(e[1]);else if((e=a.index_access.exec(l))!==null)c.push(e[1]);else throw new SyntaxError("[sprintf] failed to parse named argument key");else throw new SyntaxError("[sprintf] failed to parse named argument key");n[2]=c.join(".")}else p|=2;if(p===3)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");s.push({placeholder:n[0],param_no:n[1],keys:n[2]?n[2].split("."):void 0,sign:n[3],pad_char:n[4],align:n[5],thousand_sep:n[6],width:n[7],precision:n[8],type:n[9]})}else throw new SyntaxError("[sprintf] unexpected placeholder");i=i.substring(n[0].length)}return h[o]=s,s}function I(o,...i){return k(x(o),[o,...i])}export{I as s};
