Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@avalabs/core-utils-sdk

Package Overview
Dependencies
Maintainers
0
Versions
152
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@avalabs/core-utils-sdk - npm Package Compare versions

Comparing version 3.0.1-canary.ac7b1ff.0 to 3.0.1-canary.cd0239c.0

13

dist/index.d.ts

@@ -243,15 +243,4 @@ import * as BN from 'bn.js';

eq(value: TokenUnit | AcceptedTypes): boolean;
/**
* Tries to display token unit in most meaningful way.
* Precision of displaying token units makes sense only to up to
* *maxDecimals* decimal points, just as you would display US dollars up to 2 decimals.
* However, there's no point in showing all *maxDecimals* decimals if total
* value is huge, e.g. instead of displaying 1,000,000.000,000,001 we want to
* display 1,000,000. So in that effort this function will display maximum of
* **[maxDecimals - wholeDigits]** decimals, where *wholeDigits* is the number of digits
* of only whole portion of value.
*
* @param fixedDp See {@link Big.toFixed}
*/
toDisplay(fixedDp?: number): string;
private toLocaleString;
isZero(): boolean;

@@ -258,0 +247,0 @@ /**

2

dist/index.js

@@ -1,1 +0,1 @@

"use strict";var t=require("big.js"),e=require("@avalabs/avalanchejs"),n=require("bn.js"),r=require("@hpke/core"),o=require("is-ipfs");function i(e,n=0){const r=t(10).pow(n);return new t(e.toString()).div(r)}function s(t,e=9){const n=t.toFixed(e).split("."),r=parseInt(n[0]).toLocaleString("en-US");if(1===n.length)return r;{let t=n[1],o=t.charAt(t.length-1);for(;"0"===o;)t=t.substring(0,t.length-1),o=t.charAt(t.length-1);const i=t.substring(0,e);return i?`${r}.${i}`:r}}const a=new t(10),c=new t(0);function u(t){const e=new n(10).pow(new n(9));return t.mul(e)}function l(t,e=9){return s(i(t,e),e)}function p(t){return l(t,9)}function h(t){return i(t,9)}const f=new r.CipherSuite({kem:new r.DhkemP521HkdfSha512,kdf:new r.HkdfSha512,aead:new r.Aes256Gcm});const x=(t,e,n)=>{const r=(o=n,Object.fromEntries(Object.entries(o).filter((([t,e])=>void 0!==e))));var o;const i=new URLSearchParams(r).toString();return`${t}${e=i?`${e}?${i}`:e}`},d="unsupported ipfs URL pattern",g=t=>{if("string"!=typeof t)throw new Error("url is not string");const e=t.split(/\/|\?/);for(const t of e){if(o.cid(t))return{containsCid:!0,cid:t};const e=t.split(".")[0];if(o.cid(e))return{containsCid:!0,cid:e}}return{containsCid:!1,cid:null}},w=(t,e)=>new Array(e+1).join(t),m=(t,e,n=" ")=>w(n,e-t.toString().length)+t,b=t=>`${m(t.getHours(),2,"0")}:${m(t.getMinutes(),2,"0")}:${m(t.getSeconds(),2,"0")}.${m(t.getMilliseconds(),3,"0")}`,T=()=>b(new Date);function v(e,r){const o=t("string"==typeof e?e.replace(/,/gi,""):e),i=t(10).pow(r);return new n(o.times(i).toFixed(0))}function B(t){return v(t,9)}const y=new t("1e+18");const $=new t("1e+9");const S=t();S.PE=99,S.NE=-18;class E{value;symbol;maxDecimals;constructor(t,e,n){this.value=E.toBig(t).div(S(10).pow(e)),this.maxDecimals=e,this.symbol=n}getSymbol(){return this.symbol}getMaxDecimals(){return this.maxDecimals}add(t){return this.cloneWithValue(this.value.add(E.toBig(t)))}sub(t){return this.cloneWithValue(this.value.sub(E.toBig(t)))}mul(t){return this.cloneWithValue(this.value.mul(E.toBig(t)))}div(t){return this.cloneWithValue(this.value.div(E.toBig(t)))}gt(t){return this.value.gt(E.toBig(t))}lt(t){return this.value.lt(E.toBig(t))}eq(t){return this.value.eq(E.toBig(t))}toDisplay(e){const n=this.value.toFixed(0,t.roundDown).length,r=n>6?this.maxDecimals-n+1:this.maxDecimals;return this.value.round(r,t.roundHalfUp).toFixed(e,t.roundHalfUp)}isZero(){return this.value.eq(0)}toSubUnit(t){const e=t?this.value.round(this.maxDecimals):this.value;return BigInt(e.mul(new S(10).pow(this.maxDecimals)).toFixed(0))}static toBig(e){switch(typeof e){case"bigint":return S(BigInt(e).toString());case"string":case"number":return S(e);case"object":if(n.isBN(e))return S(e.toString());if(e instanceof t)return e}return e.value}cloneWithValue(t){return new E(t.mul(S(10).pow(this.maxDecimals)),this.maxDecimals,this.symbol)}}exports.BIG_TEN=a,exports.BIG_ZERO=c,exports.HttpClient=class{constructor(t,e={}){this.baseURL=t;const{headers:n,...r}=e;this.headerOptions=n,this.nonHeaderOptions=r}TIMEOUT=1e4;headerOptions;nonHeaderOptions;get(t,e={},n={}){const r=x(this.baseURL,t,e),{headers:o,...i}=n,s={method:"GET",headers:{"Content-Type":"application/json",...this.headerOptions,...o},...this.nonHeaderOptions,...i};return this.handleResponse(this.fetchWithTimeout(r,s))}post(t,e,n={},r={}){const o=x(this.baseURL,t,r),{headers:i,...s}=n,a={method:"POST",headers:{"Content-Type":"application/json",...this.headerOptions,...i},...this.nonHeaderOptions,...s,body:"string"==typeof e?e:JSON.stringify(e)};return this.handleResponse(this.fetchWithTimeout(o,a))}async handleResponse(t){const e=await t;if(e.ok)return await e.json();{const t=await e.text();return Promise.reject(new Error(t))}}async fetchWithTimeout(t,e={}){const{timeout:n=this.TIMEOUT}=e,r=new AbortController,o=setTimeout((()=>r.abort()),n),i=await fetch(t,{...e,signal:r.signal});return clearTimeout(o),i}},exports.TokenUnit=E,exports.UNSUPPORTED_URL_ERROR=d,exports.avaxCtoX=function(t){const e=new n(10).pow(new n(9));return t.div(e)},exports.avaxPtoC=function(t){return u(t)},exports.avaxXtoC=u,exports.balanceToDisplayValue=function(t,e){const n=i(t,e);return n.gte(1e3)?s(n,2):n.gte(1e-4)?s(n,4):s(n,e-t.toString().length+1)},exports.bech32ToHex=function(t){const[n,r,o]=e.utils.parse(t);return e.utils.strip0x(e.utils.bufferToHex(o))},exports.bigIntToString=function(t,e){e=Math.floor(e);const n=t.toString(),r=Math.max(n.length-e,0),o=n.slice(r).padStart(e,"0"),i=n.slice(0,r),s=BigInt(i).toLocaleString();return o.length?`${s}.${o}`:s},exports.bigToBN=function(e,r){const o=Math.floor(r);if(o<0)throw new Error("Denomination can not be less that 0.");const i=e.mul(t(10).pow(o)).toFixed(0,0);return new n(i)},exports.bigToBigInt=function(e,n){const r=Math.floor(n);if(r<0)throw new Error("Denomination can not be less that 0.");const o=e.mul(t(10).pow(r)).toFixed(0,0);return BigInt(o)},exports.bigToLocaleString=s,exports.bigintToBig=function(t,e){return i(new n.BN(t.toString()),e)},exports.bnToAvaxC=function(t){return l(t,18)},exports.bnToAvaxP=function(t){return p(t)},exports.bnToAvaxX=p,exports.bnToBig=i,exports.bnToBigAvaxC=function(t){return i(t,18)},exports.bnToBigAvaxP=function(t){return h(t)},exports.bnToBigAvaxX=h,exports.bnToLocaleString=l,exports.encryptAnalyticsData=async function(t,e,n){if(!t||!e)throw new Error("Encryption setting missing");const r=await f.kem.deserializePublicKey(Buffer.from(e,"base64")),o=await f.createSenderContext({recipientPublicKey:r}),i=(new TextEncoder).encode(t),s=(new TextEncoder).encode(n),a=await o.seal(s,i);return{data:Buffer.from(a).toString("base64"),enc:Buffer.from(o.enc).toString("base64"),keyID:t}},exports.formatAndLog=function(t,e,n){console.groupCollapsed("%c%s %s",((t,e=!0)=>`color:${t};font-weight:${e?"600":"300"};font-size:11px`)(n?.color??"#cccccc"),T(),t),console.log(e),console.groupEnd()},exports.formatTime=b,exports.hexToBN=function(t){return t.match("0x")?new n.BN(BigInt(t)):new n.BN(t,"hex")},exports.hexToBytes=function(t){return t?(t.length-2)/2:null},exports.ipfsResolver=(t,e)=>{const n=g(t);if(!n.cid||!0!==n.containsCid)throw new Error("url does not contain CID");const r=t.split(n.cid);if(t.includes(`ipfs://${n.cid}`))return`${e}/ipfs/${n.cid}${r[1]}`;if(t.includes(`/ipfs/${n.cid}`))return`${e}/ipfs/${n.cid}${r[1]}`;if(t.includes(`/ipns/${n.cid}`))return`${e}/ipns/${n.cid}${r[1]}`;if(t.includes(`${n.cid}.ipfs`)){const r=new URL(t).pathname;return`${e}/ipfs/${n.cid}${r}`}throw new Error(d)},exports.noop=()=>{},exports.now=T,exports.numberToBN=v,exports.numberToBNAvaxC=function(t){return v(t,18)},exports.numberToBNAvaxP=function(t){return B(t)},exports.numberToBNAvaxX=B,exports.padStart=m,exports.promiseResolveWithBackoff=async function t(e,n,r=0,o=10){try{const i=await function(t,e=0){return new Promise(((n,r)=>{setTimeout((()=>{t().then((t=>n(t))).catch((t=>r(t)))}),500*e)}))}(e,r);return o===r+1?i:n(i)?t(e,n,r+1,o):i}catch(i){if(o===r+1)throw"string"==typeof i?new Error(i):i;if(n(i))return t(e,n,r+1,o);throw"string"==typeof i?new Error(i):i}},exports.repeat=w,exports.resolve=async function(t){try{return[await t,null]}catch(t){return[null,t]}},exports.stringToBN=function(e,r){const o=t(e.replace(/,/gi,"")),i=t(10).pow(r),s=o.times(i).toFixed(0,0);return new n(s)},exports.strip0x=function(t){return"0x"===t.substring(0,2)?t.substring(2):t},exports.truncateAddress=(t,e=6)=>`${t.substring(0,e)}…${t.slice(-e/2)}`,exports.urlContainsCID=g,exports.wait=function(t){return new Promise((e=>setTimeout(e,t)))},exports.weiToAvax=function(t){return t.div(y)},exports.weiToNAvax=function(t){return t.div($)};
"use strict";var t=require("big.js"),e=require("@avalabs/avalanchejs"),n=require("bn.js"),r=require("@hpke/core"),o=require("is-ipfs");function i(e,n=0){const r=t(10).pow(n);return new t(e.toString()).div(r)}function s(t,e=9){const n=t.toFixed(e).split("."),r=parseInt(n[0]).toLocaleString("en-US");if(1===n.length)return r;{let t=n[1],o=t.charAt(t.length-1);for(;"0"===o;)t=t.substring(0,t.length-1),o=t.charAt(t.length-1);const i=t.substring(0,e);return i?`${r}.${i}`:r}}const a=new t(10),c=new t(0);function u(t){const e=new n(10).pow(new n(9));return t.mul(e)}function l(t,e=9){return s(i(t,e),e)}function p(t){return l(t,9)}function h(t){return i(t,9)}const f=new r.CipherSuite({kem:new r.DhkemP521HkdfSha512,kdf:new r.HkdfSha512,aead:new r.Aes256Gcm});const g=(t,e,n)=>{const r=(o=n,Object.fromEntries(Object.entries(o).filter((([t,e])=>void 0!==e))));var o;const i=new URLSearchParams(r).toString();return`${t}${e=i?`${e}?${i}`:e}`},x="unsupported ipfs URL pattern",d=t=>{if("string"!=typeof t)throw new Error("url is not string");const e=t.split(/\/|\?/);for(const t of e){if(o.cid(t))return{containsCid:!0,cid:t};const e=t.split(".")[0];if(o.cid(e))return{containsCid:!0,cid:e}}return{containsCid:!1,cid:null}},w=(t,e)=>new Array(e+1).join(t),m=(t,e,n=" ")=>w(n,e-t.toString().length)+t,b=t=>`${m(t.getHours(),2,"0")}:${m(t.getMinutes(),2,"0")}:${m(t.getSeconds(),2,"0")}.${m(t.getMilliseconds(),3,"0")}`,v=()=>b(new Date);function T(e,r){const o=t("string"==typeof e?e.replace(/,/gi,""):e),i=t(10).pow(r);return new n(o.times(i).toFixed(0))}function B(t){return T(t,9)}const S=new t("1e+18");const $=new t("1e+9");const y=t();y.PE=99,y.NE=-18;class E{value;symbol;maxDecimals;constructor(t,e,n){this.value=E.toBig(t).div(y(10).pow(e)),this.maxDecimals=e,this.symbol=n}getSymbol(){return this.symbol}getMaxDecimals(){return this.maxDecimals}add(t){return this.cloneWithValue(this.value.add(E.toBig(t)))}sub(t){return this.cloneWithValue(this.value.sub(E.toBig(t)))}mul(t){return this.cloneWithValue(this.value.mul(E.toBig(t)))}div(t){return this.cloneWithValue(this.value.div(E.toBig(t)))}gt(t){return this.value.gt(E.toBig(t))}lt(t){return this.value.lt(E.toBig(t))}eq(t){return this.value.eq(E.toBig(t))}toDisplay(e){if(this.value.gte(1e3))return this.toLocaleString(this.value.round(2,t.roundHalfUp).toFixed(e));if(this.value.gte(1e-4))return this.toLocaleString(this.value.round(4,t.roundHalfUp).toFixed(e));const n=this.value.round(this.maxDecimals,t.roundHalfUp);return this.toLocaleString(n.toFixed(e))}toLocaleString(t){const e=t.split("."),n=e[0];return 1===e.length?n:`${Number(n).toLocaleString("en-US")}.${e[1]}`}isZero(){return this.value.eq(0)}toSubUnit(t){const e=t?this.value.round(this.maxDecimals):this.value;return BigInt(e.mul(new y(10).pow(this.maxDecimals)).toFixed(0))}static toBig(e){switch(typeof e){case"bigint":return y(BigInt(e).toString());case"string":case"number":return y(e);case"object":if(n.isBN(e))return y(e.toString());if(e instanceof t)return e}return e.value}cloneWithValue(t){return new E(t.mul(y(10).pow(this.maxDecimals)),this.maxDecimals,this.symbol)}}exports.BIG_TEN=a,exports.BIG_ZERO=c,exports.HttpClient=class{constructor(t,e={}){this.baseURL=t;const{headers:n,...r}=e;this.headerOptions=n,this.nonHeaderOptions=r}TIMEOUT=1e4;headerOptions;nonHeaderOptions;get(t,e={},n={}){const r=g(this.baseURL,t,e),{headers:o,...i}=n,s={method:"GET",headers:{"Content-Type":"application/json",...this.headerOptions,...o},...this.nonHeaderOptions,...i};return this.handleResponse(this.fetchWithTimeout(r,s))}post(t,e,n={},r={}){const o=g(this.baseURL,t,r),{headers:i,...s}=n,a={method:"POST",headers:{"Content-Type":"application/json",...this.headerOptions,...i},...this.nonHeaderOptions,...s,body:"string"==typeof e?e:JSON.stringify(e)};return this.handleResponse(this.fetchWithTimeout(o,a))}async handleResponse(t){const e=await t;if(e.ok)return await e.json();{const t=await e.text();return Promise.reject(new Error(t))}}async fetchWithTimeout(t,e={}){const{timeout:n=this.TIMEOUT}=e,r=new AbortController,o=setTimeout((()=>r.abort()),n),i=await fetch(t,{...e,signal:r.signal});return clearTimeout(o),i}},exports.TokenUnit=E,exports.UNSUPPORTED_URL_ERROR=x,exports.avaxCtoX=function(t){const e=new n(10).pow(new n(9));return t.div(e)},exports.avaxPtoC=function(t){return u(t)},exports.avaxXtoC=u,exports.balanceToDisplayValue=function(t,e){const n=i(t,e);return n.gte(1e3)?s(n,2):n.gte(1e-4)?s(n,4):s(n,e-t.toString().length+1)},exports.bech32ToHex=function(t){const[n,r,o]=e.utils.parse(t);return e.utils.strip0x(e.utils.bufferToHex(o))},exports.bigIntToString=function(t,e){e=Math.floor(e);const n=t.toString(),r=Math.max(n.length-e,0),o=n.slice(r).padStart(e,"0"),i=n.slice(0,r),s=BigInt(i).toLocaleString();return o.length?`${s}.${o}`:s},exports.bigToBN=function(e,r){const o=Math.floor(r);if(o<0)throw new Error("Denomination can not be less that 0.");const i=e.mul(t(10).pow(o)).toFixed(0,0);return new n(i)},exports.bigToBigInt=function(e,n){const r=Math.floor(n);if(r<0)throw new Error("Denomination can not be less that 0.");const o=e.mul(t(10).pow(r)).toFixed(0,0);return BigInt(o)},exports.bigToLocaleString=s,exports.bigintToBig=function(t,e){return i(new n.BN(t.toString()),e)},exports.bnToAvaxC=function(t){return l(t,18)},exports.bnToAvaxP=function(t){return p(t)},exports.bnToAvaxX=p,exports.bnToBig=i,exports.bnToBigAvaxC=function(t){return i(t,18)},exports.bnToBigAvaxP=function(t){return h(t)},exports.bnToBigAvaxX=h,exports.bnToLocaleString=l,exports.encryptAnalyticsData=async function(t,e,n){if(!t||!e)throw new Error("Encryption setting missing");const r=await f.kem.deserializePublicKey(Buffer.from(e,"base64")),o=await f.createSenderContext({recipientPublicKey:r}),i=(new TextEncoder).encode(t),s=(new TextEncoder).encode(n),a=await o.seal(s,i);return{data:Buffer.from(a).toString("base64"),enc:Buffer.from(o.enc).toString("base64"),keyID:t}},exports.formatAndLog=function(t,e,n){console.groupCollapsed("%c%s %s",((t,e=!0)=>`color:${t};font-weight:${e?"600":"300"};font-size:11px`)(n?.color??"#cccccc"),v(),t),console.log(e),console.groupEnd()},exports.formatTime=b,exports.hexToBN=function(t){return t.match("0x")?new n.BN(BigInt(t)):new n.BN(t,"hex")},exports.hexToBytes=function(t){return t?(t.length-2)/2:null},exports.ipfsResolver=(t,e)=>{const n=d(t);if(!n.cid||!0!==n.containsCid)throw new Error("url does not contain CID");const r=t.split(n.cid);if(t.includes(`ipfs://${n.cid}`))return`${e}/ipfs/${n.cid}${r[1]}`;if(t.includes(`/ipfs/${n.cid}`))return`${e}/ipfs/${n.cid}${r[1]}`;if(t.includes(`/ipns/${n.cid}`))return`${e}/ipns/${n.cid}${r[1]}`;if(t.includes(`${n.cid}.ipfs`)){const r=new URL(t).pathname;return`${e}/ipfs/${n.cid}${r}`}throw new Error(x)},exports.noop=()=>{},exports.now=v,exports.numberToBN=T,exports.numberToBNAvaxC=function(t){return T(t,18)},exports.numberToBNAvaxP=function(t){return B(t)},exports.numberToBNAvaxX=B,exports.padStart=m,exports.promiseResolveWithBackoff=async function t(e,n,r=0,o=10){try{const i=await function(t,e=0){return new Promise(((n,r)=>{setTimeout((()=>{t().then((t=>n(t))).catch((t=>r(t)))}),500*e)}))}(e,r);return o===r+1?i:n(i)?t(e,n,r+1,o):i}catch(i){if(o===r+1)throw"string"==typeof i?new Error(i):i;if(n(i))return t(e,n,r+1,o);throw"string"==typeof i?new Error(i):i}},exports.repeat=w,exports.resolve=async function(t){try{return[await t,null]}catch(t){return[null,t]}},exports.stringToBN=function(e,r){const o=t(e.replace(/,/gi,"")),i=t(10).pow(r),s=o.times(i).toFixed(0,0);return new n(s)},exports.strip0x=function(t){return"0x"===t.substring(0,2)?t.substring(2):t},exports.truncateAddress=(t,e=6)=>`${t.substring(0,e)}…${t.slice(-e/2)}`,exports.urlContainsCID=d,exports.wait=function(t){return new Promise((e=>setTimeout(e,t)))},exports.weiToAvax=function(t){return t.div(S)},exports.weiToNAvax=function(t){return t.div($)};

@@ -31,15 +31,4 @@ import BN__default from 'bn.js';

eq(value: TokenUnit | AcceptedTypes): boolean;
/**
* Tries to display token unit in most meaningful way.
* Precision of displaying token units makes sense only to up to
* *maxDecimals* decimal points, just as you would display US dollars up to 2 decimals.
* However, there's no point in showing all *maxDecimals* decimals if total
* value is huge, e.g. instead of displaying 1,000,000.000,000,001 we want to
* display 1,000,000. So in that effort this function will display maximum of
* **[maxDecimals - wholeDigits]** decimals, where *wholeDigits* is the number of digits
* of only whole portion of value.
*
* @param fixedDp See {@link Big.toFixed}
*/
toDisplay(fixedDp?: number): string;
private toLocaleString;
isZero(): boolean;

@@ -46,0 +35,0 @@ /**

@@ -1,1 +0,1 @@

import t from"bn.js";import i from"big.js";const e=i();e.PE=99,e.NE=-18;class s{value;symbol;maxDecimals;constructor(t,i,r){this.value=s.toBig(t).div(e(10).pow(i)),this.maxDecimals=i,this.symbol=r}getSymbol(){return this.symbol}getMaxDecimals(){return this.maxDecimals}add(t){return this.cloneWithValue(this.value.add(s.toBig(t)))}sub(t){return this.cloneWithValue(this.value.sub(s.toBig(t)))}mul(t){return this.cloneWithValue(this.value.mul(s.toBig(t)))}div(t){return this.cloneWithValue(this.value.div(s.toBig(t)))}gt(t){return this.value.gt(s.toBig(t))}lt(t){return this.value.lt(s.toBig(t))}eq(t){return this.value.eq(s.toBig(t))}toDisplay(t){const e=this.value.toFixed(0,i.roundDown).length,s=e>6?this.maxDecimals-e+1:this.maxDecimals;return this.value.round(s,i.roundHalfUp).toFixed(t,i.roundHalfUp)}isZero(){return this.value.eq(0)}toSubUnit(t){const i=t?this.value.round(this.maxDecimals):this.value;return BigInt(i.mul(new e(10).pow(this.maxDecimals)).toFixed(0))}static toBig(s){switch(typeof s){case"bigint":return e(BigInt(s).toString());case"string":case"number":return e(s);case"object":if(t.isBN(s))return e(s.toString());if(s instanceof i)return s}return s.value}cloneWithValue(t){return new s(t.mul(e(10).pow(this.maxDecimals)),this.maxDecimals,this.symbol)}}export{s as TokenUnit};
import t from"bn.js";import e from"big.js";const i=e();i.PE=99,i.NE=-18;class s{value;symbol;maxDecimals;constructor(t,e,r){this.value=s.toBig(t).div(i(10).pow(e)),this.maxDecimals=e,this.symbol=r}getSymbol(){return this.symbol}getMaxDecimals(){return this.maxDecimals}add(t){return this.cloneWithValue(this.value.add(s.toBig(t)))}sub(t){return this.cloneWithValue(this.value.sub(s.toBig(t)))}mul(t){return this.cloneWithValue(this.value.mul(s.toBig(t)))}div(t){return this.cloneWithValue(this.value.div(s.toBig(t)))}gt(t){return this.value.gt(s.toBig(t))}lt(t){return this.value.lt(s.toBig(t))}eq(t){return this.value.eq(s.toBig(t))}toDisplay(t){if(this.value.gte(1e3))return this.toLocaleString(this.value.round(2,e.roundHalfUp).toFixed(t));if(this.value.gte(1e-4))return this.toLocaleString(this.value.round(4,e.roundHalfUp).toFixed(t));const i=this.value.round(this.maxDecimals,e.roundHalfUp);return this.toLocaleString(i.toFixed(t))}toLocaleString(t){const e=t.split("."),i=e[0];return 1===e.length?i:`${Number(i).toLocaleString("en-US")}.${e[1]}`}isZero(){return this.value.eq(0)}toSubUnit(t){const e=t?this.value.round(this.maxDecimals):this.value;return BigInt(e.mul(new i(10).pow(this.maxDecimals)).toFixed(0))}static toBig(s){switch(typeof s){case"bigint":return i(BigInt(s).toString());case"string":case"number":return i(s);case"object":if(t.isBN(s))return i(s.toString());if(s instanceof e)return s}return s.value}cloneWithValue(t){return new s(t.mul(i(10).pow(this.maxDecimals)),this.maxDecimals,this.symbol)}}export{s as TokenUnit};
{
"name": "@avalabs/core-utils-sdk",
"version": "3.0.1-canary.ac7b1ff.0+ac7b1ff",
"version": "3.0.1-canary.cd0239c.0+cd0239c",
"license": "Limited Ecosystem License",

@@ -39,3 +39,3 @@ "private": false,

},
"gitHead": "ac7b1ffb8780b20632a160157961db4243de288c"
"gitHead": "cd0239c0ec9ca6d20c62c0a91ab6a8f2c27bfd51"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc