UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 3.48 kB
import O from"bn.js";import u from"big.js";import w from"bn.js";import S from"decimal.js-light";import{get as f,set as B}from"lodash";var g=class{constructor(r){this.logLevel=r.logLevel!==void 0?r.logLevel:0,this.name=r.name}set level(r){this.logLevel=r}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(r){return r<=this.logLevel}error(...r){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...r),this):this}logWithError(...r){let i=r.map(o=>typeof o=="object"?JSON.stringify(o):o).join(", ");throw new Error(i)}warning(...r){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...r),this):this}info(...r){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...r),this):this}debug(...r){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...r),this):this}},b={},N={};function p(e){let r=f(b,e);if(!r){let i=f(N,e);r=new g({name:e,logLevel:i}),B(b,e,r)}return r}import n from"bn.js";var h=9007199254740991;function t(e){let r=p("Sega_parseBigNumberish");if(e instanceof n)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new n(e);r.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&r.logWithError(`BigNumberish number underflow: ${e}`),(e>=h||e<=-h)&&r.logWithError(`BigNumberish number overflow: ${e}`),new n(String(e))):typeof e=="bigint"?new n(e.toString()):(r.error(`invalid BigNumberish value: ${e}`),new n(0))}import L from"toformat";var F=L,c=F;var s=p("module/fraction"),d=c(u),a=c(S),y={0:a.ROUND_DOWN,1:a.ROUND_HALF_UP,2:a.ROUND_UP},U={0:u.roundDown,1:u.roundHalfUp,2:u.roundUp},m=class e{constructor(r,i=new w(1)){this.numerator=t(r),this.denominator=t(i)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new e(this.denominator,this.numerator)}add(r){let i=r instanceof e?r:new e(t(r));return this.denominator.eq(i.denominator)?new e(this.numerator.add(i.numerator),this.denominator):new e(this.numerator.mul(i.denominator).add(i.numerator.mul(this.denominator)),this.denominator.mul(i.denominator))}sub(r){let i=r instanceof e?r:new e(t(r));return this.denominator.eq(i.denominator)?new e(this.numerator.sub(i.numerator),this.denominator):new e(this.numerator.mul(i.denominator).sub(i.numerator.mul(this.denominator)),this.denominator.mul(i.denominator))}mul(r){let i=r instanceof e?r:new e(t(r));return new e(this.numerator.mul(i.numerator),this.denominator.mul(i.denominator))}div(r){let i=r instanceof e?r:new e(t(r));return new e(this.numerator.mul(i.denominator),this.denominator.mul(i.numerator))}toSignificant(r,i={groupSeparator:""},o=1){Number.isInteger(r)||s.logWithError(`${r} is not an integer.`),r<=0&&s.logWithError(`${r} is not positive.`),a.set({precision:r+1,rounding:y[o]});let l=new a(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(r);return l.toFormat(l.decimalPlaces(),i)}toFixed(r,i={groupSeparator:""},o=1){return Number.isInteger(r)||s.logWithError(`${r} is not an integer.`),r<0&&s.logWithError(`${r} is negative.`),d.DP=r,d.RM=U[o]||1,new d(this.numerator.toString()).div(this.denominator.toString()).toFormat(r,i)}isZero(){return this.numerator.isZero()}};var W=new m(new O(100)),D=class extends m{toSignificant(r=5,i,o){return this.mul(W).toSignificant(r,i,o)}toFixed(r=2,i,o){return this.mul(W).toFixed(r,i,o)}};export{D as Percent,W as _100_PERCENT}; //# sourceMappingURL=percent.mjs.map