@fileverse-dev/formulajs 4.4.12-mod-8 → 4.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.cjs CHANGED
@@ -18565,17 +18565,18 @@ function flattenObject(obj, parentKey = '', res = {}) {
18565
18565
  }
18566
18566
 
18567
18567
  const SUPPORTED_TOKEN_NAMES = {
18568
- "eth": 1, // Ethereum Mainnet
18569
- "base": 8453, // Base
18570
- "polygon": 137, // Polygon
18571
- "arbitrum": 42161, // Arbitrum One
18572
- "optimism": 10, // Optimism
18573
- "gnosis": 100, // Gnosis Chain (xDai)
18574
- "bsc": 56, // Binance Smart Chain
18575
- "avalanche": 43114, // Avalanche C-Chain
18576
- "fantom": 250, // Fantom Opera
18577
- "scroll": 534352, // Scroll
18578
- "linea": 59144 // Linea
18568
+ "eth": 1,
18569
+ "base": 8453,
18570
+ "polygon": 137,
18571
+ "arbitrum": 42161,
18572
+ "optimism": 10,
18573
+ "gnosis": 100,
18574
+ "bsc": 56,
18575
+ "avalanche": 43114,
18576
+ "fantom": 250,
18577
+ "scroll": 534352,
18578
+ "linea": 59144,
18579
+ "ethereum": 1
18579
18580
  };
18580
18581
 
18581
18582
 
@@ -18594,6 +18595,23 @@ function formatNumber(raw, decimals) {
18594
18595
  }).format(normalized);
18595
18596
  }
18596
18597
 
18598
+ let cachedChains = null;
18599
+ async function getChainName(chainId){
18600
+ try {
18601
+ if (!cachedChains) {
18602
+ const res = await fetch("https://chainid.network/chains_mini.json");
18603
+ if (!res.ok) throw new Error("Failed to fetch chains.json");
18604
+ cachedChains = await res.json();
18605
+ }
18606
+
18607
+ const chain = cachedChains.find(c => c.chainId === chainId);
18608
+ return chain ? chain.name : chainId;
18609
+ } catch (error) {
18610
+ console.log(error);
18611
+ return chainId
18612
+ }
18613
+ }
18614
+
18597
18615
 
18598
18616
 
18599
18617
  async function DUNESIM() {
@@ -18653,7 +18671,13 @@ async function DUNESIM() {
18653
18671
  type === "token-holders" ? json?.holders ?? json ?? [] :
18654
18672
  type === "price" ? json?.tokens ?? json ?? [] :
18655
18673
  json ?? [];
18656
- const result = (Array.isArray(data) ? data : [data]).map((item) => {
18674
+ const result = (Array.isArray(data) ? data : [data]);
18675
+
18676
+ const final = [];
18677
+
18678
+ let globalDecimals;
18679
+
18680
+ for(let item of result){
18657
18681
  if(item?.decimals){
18658
18682
  if(item?.total_supply){
18659
18683
  item.total_supply = formatNumber(item?.total_supply, item.decimals);
@@ -18676,29 +18700,45 @@ async function DUNESIM() {
18676
18700
  item[key] = price;
18677
18701
  });
18678
18702
  }
18679
- return flattenObject(item)
18680
- });
18681
- return result
18703
+
18704
+ if(type === 'price'){
18705
+ delete item["chain_id"];
18706
+ delete item["decimals"];
18707
+ delete item["logo"];
18708
+ }
18709
+ if(type === 'activity'){
18710
+ item.chain_id = await getChainName(item.chain_id);
18711
+ }
18712
+ if(type === 'token-holders'){
18713
+ if(item.balance){
18714
+ if(!globalDecimals){
18715
+ try {
18716
+ const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
18717
+ const url = `https://api.sim.dune.com/v1/evm/token-info/${input1}?chain_ids=${chain}`;
18718
+ const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
18719
+ url, serviceName: "DuneSim",
18720
+ headers: { "X-Sim-Api-Key": apiKey },
18721
+ });
18722
+ const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
18723
+ const resData = await res.json();
18724
+ const decimals = resData.tokens[0]?.decimals;
18725
+ globalDecimals = decimals;
18726
+ } catch (error) {
18727
+ console.log(error);
18728
+ }
18729
+ }
18730
+ item.balance = formatNumber(item.balance, globalDecimals);
18731
+ }
18732
+ }
18733
+ final.push(flattenObject(item));
18734
+
18735
+ }
18736
+ return final
18682
18737
  } catch (err) {
18683
18738
  return errorMessageHandler(err, "DUNESIM");
18684
18739
  }
18685
18740
  }
18686
18741
 
18687
-
18688
- (async () => {
18689
- // Example: activity
18690
- // const res1 = await DUNESIM('activity', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', "eth", 5);
18691
- // console.log('Activity result:', res1, res1.length);
18692
-
18693
- // Example: price (token-info)
18694
- // const res2 = await DUNESIM('price', 'eth', '1,6,24', "", 5);
18695
- // console.log('Price result:', res2);
18696
-
18697
- // // Example: token holders
18698
- // const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base", 5);
18699
- // console.log('Holders result:', res3, res3.length);
18700
- })();
18701
-
18702
18742
  // export {GNOSISPAY} from './gnosispay/gnosispay.js'
18703
18743
 
18704
18744
 
package/lib/esm/index.mjs CHANGED
@@ -18563,17 +18563,18 @@ function flattenObject(obj, parentKey = '', res = {}) {
18563
18563
  }
18564
18564
 
18565
18565
  const SUPPORTED_TOKEN_NAMES = {
18566
- "eth": 1, // Ethereum Mainnet
18567
- "base": 8453, // Base
18568
- "polygon": 137, // Polygon
18569
- "arbitrum": 42161, // Arbitrum One
18570
- "optimism": 10, // Optimism
18571
- "gnosis": 100, // Gnosis Chain (xDai)
18572
- "bsc": 56, // Binance Smart Chain
18573
- "avalanche": 43114, // Avalanche C-Chain
18574
- "fantom": 250, // Fantom Opera
18575
- "scroll": 534352, // Scroll
18576
- "linea": 59144 // Linea
18566
+ "eth": 1,
18567
+ "base": 8453,
18568
+ "polygon": 137,
18569
+ "arbitrum": 42161,
18570
+ "optimism": 10,
18571
+ "gnosis": 100,
18572
+ "bsc": 56,
18573
+ "avalanche": 43114,
18574
+ "fantom": 250,
18575
+ "scroll": 534352,
18576
+ "linea": 59144,
18577
+ "ethereum": 1
18577
18578
  };
18578
18579
 
18579
18580
 
@@ -18592,6 +18593,23 @@ function formatNumber(raw, decimals) {
18592
18593
  }).format(normalized);
18593
18594
  }
18594
18595
 
18596
+ let cachedChains = null;
18597
+ async function getChainName(chainId){
18598
+ try {
18599
+ if (!cachedChains) {
18600
+ const res = await fetch("https://chainid.network/chains_mini.json");
18601
+ if (!res.ok) throw new Error("Failed to fetch chains.json");
18602
+ cachedChains = await res.json();
18603
+ }
18604
+
18605
+ const chain = cachedChains.find(c => c.chainId === chainId);
18606
+ return chain ? chain.name : chainId;
18607
+ } catch (error) {
18608
+ console.log(error);
18609
+ return chainId
18610
+ }
18611
+ }
18612
+
18595
18613
 
18596
18614
 
18597
18615
  async function DUNESIM() {
@@ -18651,7 +18669,13 @@ async function DUNESIM() {
18651
18669
  type === "token-holders" ? json?.holders ?? json ?? [] :
18652
18670
  type === "price" ? json?.tokens ?? json ?? [] :
18653
18671
  json ?? [];
18654
- const result = (Array.isArray(data) ? data : [data]).map((item) => {
18672
+ const result = (Array.isArray(data) ? data : [data]);
18673
+
18674
+ const final = [];
18675
+
18676
+ let globalDecimals;
18677
+
18678
+ for(let item of result){
18655
18679
  if(item?.decimals){
18656
18680
  if(item?.total_supply){
18657
18681
  item.total_supply = formatNumber(item?.total_supply, item.decimals);
@@ -18674,29 +18698,45 @@ async function DUNESIM() {
18674
18698
  item[key] = price;
18675
18699
  });
18676
18700
  }
18677
- return flattenObject(item)
18678
- });
18679
- return result
18701
+
18702
+ if(type === 'price'){
18703
+ delete item["chain_id"];
18704
+ delete item["decimals"];
18705
+ delete item["logo"];
18706
+ }
18707
+ if(type === 'activity'){
18708
+ item.chain_id = await getChainName(item.chain_id);
18709
+ }
18710
+ if(type === 'token-holders'){
18711
+ if(item.balance){
18712
+ if(!globalDecimals){
18713
+ try {
18714
+ const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
18715
+ const url = `https://api.sim.dune.com/v1/evm/token-info/${input1}?chain_ids=${chain}`;
18716
+ const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
18717
+ url, serviceName: "DuneSim",
18718
+ headers: { "X-Sim-Api-Key": apiKey },
18719
+ });
18720
+ const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
18721
+ const resData = await res.json();
18722
+ const decimals = resData.tokens[0]?.decimals;
18723
+ globalDecimals = decimals;
18724
+ } catch (error) {
18725
+ console.log(error);
18726
+ }
18727
+ }
18728
+ item.balance = formatNumber(item.balance, globalDecimals);
18729
+ }
18730
+ }
18731
+ final.push(flattenObject(item));
18732
+
18733
+ }
18734
+ return final
18680
18735
  } catch (err) {
18681
18736
  return errorMessageHandler(err, "DUNESIM");
18682
18737
  }
18683
18738
  }
18684
18739
 
18685
-
18686
- (async () => {
18687
- // Example: activity
18688
- // const res1 = await DUNESIM('activity', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', "eth", 5);
18689
- // console.log('Activity result:', res1, res1.length);
18690
-
18691
- // Example: price (token-info)
18692
- // const res2 = await DUNESIM('price', 'eth', '1,6,24', "", 5);
18693
- // console.log('Price result:', res2);
18694
-
18695
- // // Example: token holders
18696
- // const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base", 5);
18697
- // console.log('Holders result:', res3, res3.length);
18698
- })();
18699
-
18700
18740
  // export {GNOSISPAY} from './gnosispay/gnosispay.js'
18701
18741
 
18702
18742
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/formulajs",
3
- "version": "4.4.12-mod-8",
3
+ "version": "4.4.13",
4
4
  "description": "JavaScript implementation of most Microsoft Excel formula functions",
5
5
  "author": "Formulajs",
6
6
  "publishConfig": {