UNPKG

@sega-so/sega-sdk

Version:

An SDK for building applications on top of SEGA.

2 lines 4.26 kB
"use strict";var U=Object.create;var c=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var C=(e,r)=>{for(var i in r)c(e,i,{get:r[i],enumerable:!0})},B=(e,r,i,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of v(r))!R.call(e,t)&&t!==i&&c(e,t,{get:()=>r[t],enumerable:!(o=O(r,t))||o.enumerable});return e};var a=(e,r,i)=>(i=e!=null?U(x(e)):{},B(r||!e||!e.__esModule?c(i,"default",{value:e,enumerable:!0}):i,e)),E=e=>B(c({},"__esModule",{value:!0}),e);var $={};C($,{Percent:()=>D,_100_PERCENT:()=>W});module.exports=E($);var y=a(require("bn.js"));var s=a(require("big.js")),w=a(require("bn.js")),S=a(require("decimal.js-light"));var p=require("lodash");var f=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}},N={},P={};function d(e){let r=(0,p.get)(N,e);if(!r){let i=(0,p.get)(P,e);r=new f({name:e,logLevel:i}),(0,p.set)(N,e,r)}return r}var m=a(require("bn.js"));var L=9007199254740991;function n(e){let r=d("Sega_parseBigNumberish");if(e instanceof m.default)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new m.default(e);r.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&r.logWithError(`BigNumberish number underflow: ${e}`),(e>=L||e<=-L)&&r.logWithError(`BigNumberish number overflow: ${e}`),new m.default(String(e))):typeof e=="bigint"?new m.default(e.toString()):(r.error(`invalid BigNumberish value: ${e}`),new m.default(0))}var F=a(require("toformat")),k=F.default,b=k;var l=d("module/fraction"),h=b(s.default),u=b(S.default),_={0:u.ROUND_DOWN,1:u.ROUND_HALF_UP,2:u.ROUND_UP},A={0:s.default.roundDown,1:s.default.roundHalfUp,2:s.default.roundUp},g=class e{constructor(r,i=new w.default(1)){this.numerator=n(r),this.denominator=n(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(n(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(n(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(n(r));return new e(this.numerator.mul(i.numerator),this.denominator.mul(i.denominator))}div(r){let i=r instanceof e?r:new e(n(r));return new e(this.numerator.mul(i.denominator),this.denominator.mul(i.numerator))}toSignificant(r,i={groupSeparator:""},o=1){Number.isInteger(r)||l.logWithError(`${r} is not an integer.`),r<=0&&l.logWithError(`${r} is not positive.`),u.set({precision:r+1,rounding:_[o]});let t=new u(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(r);return t.toFormat(t.decimalPlaces(),i)}toFixed(r,i={groupSeparator:""},o=1){return Number.isInteger(r)||l.logWithError(`${r} is not an integer.`),r<0&&l.logWithError(`${r} is negative.`),h.DP=r,h.RM=A[o]||1,new h(this.numerator.toString()).div(this.denominator.toString()).toFormat(r,i)}isZero(){return this.numerator.isZero()}};var W=new g(new y.default(100)),D=class extends g{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)}};0&&(module.exports={Percent,_100_PERCENT}); //# sourceMappingURL=percent.js.map