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

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
@@ -17447,7 +17447,9 @@ function getUrlAndHeaders({ url, serviceName, headers = {} }) {
17447
17447
  HEADERS: {
17448
17448
  'target-url': cleanedUrl,
17449
17449
  method: 'GET',
17450
- 'Content-Type': 'application/json'
17450
+ 'Content-Type': 'application/json',
17451
+ "Cache-Control": "no-store",
17452
+ Pragma: "no-cache",
17451
17453
  }
17452
17454
  };
17453
17455
  }
@@ -17455,6 +17457,8 @@ function getUrlAndHeaders({ url, serviceName, headers = {} }) {
17455
17457
  return {
17456
17458
  URL: url,
17457
17459
  HEADERS: {
17460
+ "Cache-Control": "no-store",
17461
+ Pragma: "no-cache",
17458
17462
  ...headers,
17459
17463
  }
17460
17464
  };
@@ -18565,17 +18569,18 @@ function flattenObject(obj, parentKey = '', res = {}) {
18565
18569
  }
18566
18570
 
18567
18571
  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
18572
+ "eth": 1,
18573
+ "base": 8453,
18574
+ "polygon": 137,
18575
+ "arbitrum": 42161,
18576
+ "optimism": 10,
18577
+ "gnosis": 100,
18578
+ "bsc": 56,
18579
+ "avalanche": 43114,
18580
+ "fantom": 250,
18581
+ "scroll": 534352,
18582
+ "linea": 59144,
18583
+ "ethereum": 1
18579
18584
  };
18580
18585
 
18581
18586
 
@@ -18594,6 +18599,23 @@ function formatNumber(raw, decimals) {
18594
18599
  }).format(normalized);
18595
18600
  }
18596
18601
 
18602
+ let cachedChains = null;
18603
+ async function getChainName(chainId){
18604
+ try {
18605
+ if (!cachedChains) {
18606
+ const res = await fetch("https://chainid.network/chains_mini.json");
18607
+ if (!res.ok) throw new Error("Failed to fetch chains.json");
18608
+ cachedChains = await res.json();
18609
+ }
18610
+
18611
+ const chain = cachedChains.find(c => c.chainId === chainId);
18612
+ return chain ? chain.name : chainId;
18613
+ } catch (error) {
18614
+ console.log(error);
18615
+ return chainId
18616
+ }
18617
+ }
18618
+
18597
18619
 
18598
18620
 
18599
18621
  async function DUNESIM() {
@@ -18653,7 +18675,13 @@ async function DUNESIM() {
18653
18675
  type === "token-holders" ? json?.holders ?? json ?? [] :
18654
18676
  type === "price" ? json?.tokens ?? json ?? [] :
18655
18677
  json ?? [];
18656
- const result = (Array.isArray(data) ? data : [data]).map((item) => {
18678
+ const result = (Array.isArray(data) ? data : [data]);
18679
+
18680
+ const final = [];
18681
+
18682
+ let globalDecimals;
18683
+
18684
+ for(let item of result){
18657
18685
  if(item?.decimals){
18658
18686
  if(item?.total_supply){
18659
18687
  item.total_supply = formatNumber(item?.total_supply, item.decimals);
@@ -18676,29 +18704,45 @@ async function DUNESIM() {
18676
18704
  item[key] = price;
18677
18705
  });
18678
18706
  }
18679
- return flattenObject(item)
18680
- });
18681
- return result
18707
+
18708
+ if(type === 'price'){
18709
+ delete item["chain_id"];
18710
+ delete item["decimals"];
18711
+ delete item["logo"];
18712
+ }
18713
+ if(type === 'activity'){
18714
+ item.chain_id = await getChainName(item.chain_id);
18715
+ }
18716
+ if(type === 'token-holders'){
18717
+ if(item.balance){
18718
+ if(!globalDecimals){
18719
+ try {
18720
+ const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
18721
+ const url = `https://api.sim.dune.com/v1/evm/token-info/${input1}?chain_ids=${chain}`;
18722
+ const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
18723
+ url, serviceName: "DuneSim",
18724
+ headers: { "X-Sim-Api-Key": apiKey },
18725
+ });
18726
+ const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
18727
+ const resData = await res.json();
18728
+ const decimals = resData.tokens[0]?.decimals;
18729
+ globalDecimals = decimals;
18730
+ } catch (error) {
18731
+ console.log(error);
18732
+ }
18733
+ }
18734
+ item.balance = formatNumber(item.balance, globalDecimals);
18735
+ }
18736
+ }
18737
+ final.push(flattenObject(item));
18738
+
18739
+ }
18740
+ return final
18682
18741
  } catch (err) {
18683
18742
  return errorMessageHandler(err, "DUNESIM");
18684
18743
  }
18685
18744
  }
18686
18745
 
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
18746
  // export {GNOSISPAY} from './gnosispay/gnosispay.js'
18703
18747
 
18704
18748
 
package/lib/esm/index.mjs CHANGED
@@ -17445,7 +17445,9 @@ function getUrlAndHeaders({ url, serviceName, headers = {} }) {
17445
17445
  HEADERS: {
17446
17446
  'target-url': cleanedUrl,
17447
17447
  method: 'GET',
17448
- 'Content-Type': 'application/json'
17448
+ 'Content-Type': 'application/json',
17449
+ "Cache-Control": "no-store",
17450
+ Pragma: "no-cache",
17449
17451
  }
17450
17452
  };
17451
17453
  }
@@ -17453,6 +17455,8 @@ function getUrlAndHeaders({ url, serviceName, headers = {} }) {
17453
17455
  return {
17454
17456
  URL: url,
17455
17457
  HEADERS: {
17458
+ "Cache-Control": "no-store",
17459
+ Pragma: "no-cache",
17456
17460
  ...headers,
17457
17461
  }
17458
17462
  };
@@ -18563,17 +18567,18 @@ function flattenObject(obj, parentKey = '', res = {}) {
18563
18567
  }
18564
18568
 
18565
18569
  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
18570
+ "eth": 1,
18571
+ "base": 8453,
18572
+ "polygon": 137,
18573
+ "arbitrum": 42161,
18574
+ "optimism": 10,
18575
+ "gnosis": 100,
18576
+ "bsc": 56,
18577
+ "avalanche": 43114,
18578
+ "fantom": 250,
18579
+ "scroll": 534352,
18580
+ "linea": 59144,
18581
+ "ethereum": 1
18577
18582
  };
18578
18583
 
18579
18584
 
@@ -18592,6 +18597,23 @@ function formatNumber(raw, decimals) {
18592
18597
  }).format(normalized);
18593
18598
  }
18594
18599
 
18600
+ let cachedChains = null;
18601
+ async function getChainName(chainId){
18602
+ try {
18603
+ if (!cachedChains) {
18604
+ const res = await fetch("https://chainid.network/chains_mini.json");
18605
+ if (!res.ok) throw new Error("Failed to fetch chains.json");
18606
+ cachedChains = await res.json();
18607
+ }
18608
+
18609
+ const chain = cachedChains.find(c => c.chainId === chainId);
18610
+ return chain ? chain.name : chainId;
18611
+ } catch (error) {
18612
+ console.log(error);
18613
+ return chainId
18614
+ }
18615
+ }
18616
+
18595
18617
 
18596
18618
 
18597
18619
  async function DUNESIM() {
@@ -18651,7 +18673,13 @@ async function DUNESIM() {
18651
18673
  type === "token-holders" ? json?.holders ?? json ?? [] :
18652
18674
  type === "price" ? json?.tokens ?? json ?? [] :
18653
18675
  json ?? [];
18654
- const result = (Array.isArray(data) ? data : [data]).map((item) => {
18676
+ const result = (Array.isArray(data) ? data : [data]);
18677
+
18678
+ const final = [];
18679
+
18680
+ let globalDecimals;
18681
+
18682
+ for(let item of result){
18655
18683
  if(item?.decimals){
18656
18684
  if(item?.total_supply){
18657
18685
  item.total_supply = formatNumber(item?.total_supply, item.decimals);
@@ -18674,29 +18702,45 @@ async function DUNESIM() {
18674
18702
  item[key] = price;
18675
18703
  });
18676
18704
  }
18677
- return flattenObject(item)
18678
- });
18679
- return result
18705
+
18706
+ if(type === 'price'){
18707
+ delete item["chain_id"];
18708
+ delete item["decimals"];
18709
+ delete item["logo"];
18710
+ }
18711
+ if(type === 'activity'){
18712
+ item.chain_id = await getChainName(item.chain_id);
18713
+ }
18714
+ if(type === 'token-holders'){
18715
+ if(item.balance){
18716
+ if(!globalDecimals){
18717
+ try {
18718
+ const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
18719
+ const url = `https://api.sim.dune.com/v1/evm/token-info/${input1}?chain_ids=${chain}`;
18720
+ const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
18721
+ url, serviceName: "DuneSim",
18722
+ headers: { "X-Sim-Api-Key": apiKey },
18723
+ });
18724
+ const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
18725
+ const resData = await res.json();
18726
+ const decimals = resData.tokens[0]?.decimals;
18727
+ globalDecimals = decimals;
18728
+ } catch (error) {
18729
+ console.log(error);
18730
+ }
18731
+ }
18732
+ item.balance = formatNumber(item.balance, globalDecimals);
18733
+ }
18734
+ }
18735
+ final.push(flattenObject(item));
18736
+
18737
+ }
18738
+ return final
18680
18739
  } catch (err) {
18681
18740
  return errorMessageHandler(err, "DUNESIM");
18682
18741
  }
18683
18742
  }
18684
18743
 
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
18744
  // export {GNOSISPAY} from './gnosispay/gnosispay.js'
18701
18745
 
18702
18746
 
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-patch-1",
4
4
  "description": "JavaScript implementation of most Microsoft Excel formula functions",
5
5
  "author": "Formulajs",
6
6
  "publishConfig": {