@fileverse-dev/formulajs 4.4.12-mod-7 → 4.4.12-mod-9

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
@@ -18594,6 +18594,23 @@ function formatNumber(raw, decimals) {
18594
18594
  }).format(normalized);
18595
18595
  }
18596
18596
 
18597
+ let cachedChains = null;
18598
+ async function getChainName(chainId){
18599
+ try {
18600
+ if (!cachedChains) {
18601
+ const res = await fetch("https://chainid.network/chains_mini.json");
18602
+ if (!res.ok) throw new Error("Failed to fetch chains.json");
18603
+ cachedChains = await res.json();
18604
+ }
18605
+
18606
+ const chain = cachedChains.find(c => c.chainId === chainId);
18607
+ return chain ? chain.name : chainId;
18608
+ } catch (error) {
18609
+ console.log(error);
18610
+ return chainId
18611
+ }
18612
+ }
18613
+
18597
18614
 
18598
18615
 
18599
18616
  async function DUNESIM() {
@@ -18653,7 +18670,13 @@ async function DUNESIM() {
18653
18670
  type === "token-holders" ? json?.holders ?? json ?? [] :
18654
18671
  type === "price" ? json?.tokens ?? json ?? [] :
18655
18672
  json ?? [];
18656
- const result = (Array.isArray(data) ? data : [data]).map((item) => {
18673
+ const result = (Array.isArray(data) ? data : [data]);
18674
+
18675
+ const final = [];
18676
+
18677
+ let globalDecimals;
18678
+
18679
+ for(let item of result){
18657
18680
  if(item?.decimals){
18658
18681
  if(item?.total_supply){
18659
18682
  item.total_supply = formatNumber(item?.total_supply, item.decimals);
@@ -18668,9 +18691,48 @@ async function DUNESIM() {
18668
18691
  minute: "2-digit"
18669
18692
  }).format(new Date(item.first_acquired));
18670
18693
  }
18671
- return flattenObject(item)
18672
- });
18673
- return result
18694
+ if(item.historical_prices){
18695
+ const prices = item.historical_prices;
18696
+ prices.forEach((priceData) => {
18697
+ const key = "price_" + priceData.offset_hours +"h";
18698
+ const price = priceData.price_usd;
18699
+ item[key] = price;
18700
+ });
18701
+ }
18702
+
18703
+ if(type === 'price'){
18704
+ delete item["chain_id"];
18705
+ delete item["decimals"];
18706
+ delete item["logo"];
18707
+ }
18708
+ if(type === 'activity'){
18709
+ item.chain_id = await getChainName(item.chain_id);
18710
+ }
18711
+ if(type === 'token-holders'){
18712
+ if(item.balance){
18713
+ if(!globalDecimals){
18714
+ try {
18715
+ const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
18716
+ const url = `https://api.sim.dune.com/v1/evm/token-info/${input1}?chain_ids=${chain}`;
18717
+ const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
18718
+ url, serviceName: "DuneSim",
18719
+ headers: { "X-Sim-Api-Key": apiKey },
18720
+ });
18721
+ const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
18722
+ const resData = await res.json();
18723
+ const decimals = resData.tokens[0]?.decimals;
18724
+ globalDecimals = decimals;
18725
+ } catch (error) {
18726
+ console.log(error);
18727
+ }
18728
+ }
18729
+ item.balance = formatNumber(item.balance, globalDecimals);
18730
+ }
18731
+ }
18732
+ final.push(flattenObject(item));
18733
+
18734
+ }
18735
+ return final
18674
18736
  } catch (err) {
18675
18737
  return errorMessageHandler(err, "DUNESIM");
18676
18738
  }
@@ -18683,11 +18745,11 @@ async function DUNESIM() {
18683
18745
  // console.log('Activity result:', res1, res1.length);
18684
18746
 
18685
18747
  // Example: price (token-info)
18686
- // const res2 = await DUNESIM('price', 'base', '1,6,24', "0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca", 5);
18748
+ // const res2 = await DUNESIM('price', 'eth', '1,6,24', "", 5);
18687
18749
  // console.log('Price result:', res2);
18688
18750
 
18689
18751
  // // Example: token holders
18690
- // const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base", 5);
18752
+ // const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base", 1);
18691
18753
  // console.log('Holders result:', res3, res3.length);
18692
18754
  })();
18693
18755
 
package/lib/esm/index.mjs CHANGED
@@ -18592,6 +18592,23 @@ function formatNumber(raw, decimals) {
18592
18592
  }).format(normalized);
18593
18593
  }
18594
18594
 
18595
+ let cachedChains = null;
18596
+ async function getChainName(chainId){
18597
+ try {
18598
+ if (!cachedChains) {
18599
+ const res = await fetch("https://chainid.network/chains_mini.json");
18600
+ if (!res.ok) throw new Error("Failed to fetch chains.json");
18601
+ cachedChains = await res.json();
18602
+ }
18603
+
18604
+ const chain = cachedChains.find(c => c.chainId === chainId);
18605
+ return chain ? chain.name : chainId;
18606
+ } catch (error) {
18607
+ console.log(error);
18608
+ return chainId
18609
+ }
18610
+ }
18611
+
18595
18612
 
18596
18613
 
18597
18614
  async function DUNESIM() {
@@ -18651,7 +18668,13 @@ async function DUNESIM() {
18651
18668
  type === "token-holders" ? json?.holders ?? json ?? [] :
18652
18669
  type === "price" ? json?.tokens ?? json ?? [] :
18653
18670
  json ?? [];
18654
- const result = (Array.isArray(data) ? data : [data]).map((item) => {
18671
+ const result = (Array.isArray(data) ? data : [data]);
18672
+
18673
+ const final = [];
18674
+
18675
+ let globalDecimals;
18676
+
18677
+ for(let item of result){
18655
18678
  if(item?.decimals){
18656
18679
  if(item?.total_supply){
18657
18680
  item.total_supply = formatNumber(item?.total_supply, item.decimals);
@@ -18666,9 +18689,48 @@ async function DUNESIM() {
18666
18689
  minute: "2-digit"
18667
18690
  }).format(new Date(item.first_acquired));
18668
18691
  }
18669
- return flattenObject(item)
18670
- });
18671
- return result
18692
+ if(item.historical_prices){
18693
+ const prices = item.historical_prices;
18694
+ prices.forEach((priceData) => {
18695
+ const key = "price_" + priceData.offset_hours +"h";
18696
+ const price = priceData.price_usd;
18697
+ item[key] = price;
18698
+ });
18699
+ }
18700
+
18701
+ if(type === 'price'){
18702
+ delete item["chain_id"];
18703
+ delete item["decimals"];
18704
+ delete item["logo"];
18705
+ }
18706
+ if(type === 'activity'){
18707
+ item.chain_id = await getChainName(item.chain_id);
18708
+ }
18709
+ if(type === 'token-holders'){
18710
+ if(item.balance){
18711
+ if(!globalDecimals){
18712
+ try {
18713
+ const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
18714
+ const url = `https://api.sim.dune.com/v1/evm/token-info/${input1}?chain_ids=${chain}`;
18715
+ const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
18716
+ url, serviceName: "DuneSim",
18717
+ headers: { "X-Sim-Api-Key": apiKey },
18718
+ });
18719
+ const res = await fetch(finalUrl, { method: "GET", headers: HEADERS });
18720
+ const resData = await res.json();
18721
+ const decimals = resData.tokens[0]?.decimals;
18722
+ globalDecimals = decimals;
18723
+ } catch (error) {
18724
+ console.log(error);
18725
+ }
18726
+ }
18727
+ item.balance = formatNumber(item.balance, globalDecimals);
18728
+ }
18729
+ }
18730
+ final.push(flattenObject(item));
18731
+
18732
+ }
18733
+ return final
18672
18734
  } catch (err) {
18673
18735
  return errorMessageHandler(err, "DUNESIM");
18674
18736
  }
@@ -18681,11 +18743,11 @@ async function DUNESIM() {
18681
18743
  // console.log('Activity result:', res1, res1.length);
18682
18744
 
18683
18745
  // Example: price (token-info)
18684
- // const res2 = await DUNESIM('price', 'base', '1,6,24', "0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca", 5);
18746
+ // const res2 = await DUNESIM('price', 'eth', '1,6,24', "", 5);
18685
18747
  // console.log('Price result:', res2);
18686
18748
 
18687
18749
  // // Example: token holders
18688
- // const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base", 5);
18750
+ // const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base", 1);
18689
18751
  // console.log('Holders result:', res3, res3.length);
18690
18752
  })();
18691
18753
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/formulajs",
3
- "version": "4.4.12-mod-7",
3
+ "version": "4.4.12-mod-9",
4
4
  "description": "JavaScript implementation of most Microsoft Excel formula functions",
5
5
  "author": "Formulajs",
6
6
  "publishConfig": {