@fileverse-dev/formulajs 4.4.11-mod-8 → 4.4.11-mod-10

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
@@ -12950,74 +12950,68 @@ function SWITCH() {
12950
12950
  }
12951
12951
 
12952
12952
  const SERVICE_API_KEY = {
12953
- Etherscan: "ETHERSCAN_API_KEY",
12954
- Coingecko: "COINGECKO_API_KEY"
12953
+ Etherscan: "ETHERSCAN_API_KEY",
12954
+ Coingecko: "COINGECKO_API_KEY"
12955
12955
  };
12956
12956
 
12957
12957
  async function GETTXLIST(address, page, offset) {
12958
- const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Etherscan);
12959
- console.log("FORMULA JS API KEY ETHERSCAN NOT FOUND", API_KEY);
12960
- const url = `https://api.etherscan.io/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=${page}&offset=${offset}&sort=asc&apikey=${API_KEY}`;
12961
-
12962
- try {
12963
- const response = await fetch(url);
12964
- if (!response.ok) {
12965
- throw new Error(`HTTP error! Status: ${response.status}`)
12966
- }
12958
+ const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Etherscan);
12959
+ const url = `https://api.etherscan.io/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=${page}&offset=${offset}&sort=asc&apikey=${API_KEY}`;
12960
+
12961
+ try {
12962
+ const response = await fetch(url);
12963
+ if (!response.ok) {
12964
+ throw new Error(`HTTP error! Status: ${response.status}`)
12965
+ }
12966
+ const json = await response.json();
12967
+ if (json.result.includes("Invalid API Key")) {
12968
+ return `${SERVICE_API_KEY.Etherscan}_MISSING`
12969
+ }
12970
+ /*
12971
+ [{blockNumber: '0x1d3d1', timeStamp: '0x5f7e4f', hash: '0x3c3c3c3c', nonce: '0x1',}]
12972
+ */
12973
+ return json.result;
12974
+ } catch (error) {
12975
+ return "ERROR IN FETCHING"
12976
+ }
12977
+ }
12978
+
12979
+ async function GETPRICE(token, vs_currencies) {
12980
+ const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Coingecko);
12981
+ const url = `https://api.coingecko.com/api/v3/simple/price?vs_currencies=${vs_currencies}&ids=${token}`;
12982
+
12983
+ const options = {
12984
+ method: 'GET',
12985
+ headers: { accept: 'application/json', 'x-cg-demo-api-key': `${API_KEY}` },
12986
+ };
12987
+
12988
+ try {
12989
+ const response = await fetch(url, options);
12990
+ if (!response.ok) {
12967
12991
  const json = await response.json();
12968
- console.log(json.result);
12969
- if(json.result.includes("Invalid API Key")){
12970
- return `${SERVICE_API_KEY.Etherscan}_MISSING`
12992
+ if (json.status.error_message.includes("API Key Missing")) {
12993
+ return `${SERVICE_API_KEY.Coingecko}_MISSING`
12971
12994
  }
12972
- return json.result;
12973
- } catch (error) {
12974
- console.error('API call failed:', error);
12975
- return "ERROR IN FETCHING"
12976
- }
12977
- }
12978
-
12979
- async function GETPRICE(token, vs_currencies, offset) {
12980
- const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Coingecko);
12981
- console.log("FORMULA JS API KEY ETHERSCAN NOT FOUND", API_KEY);
12982
- // const url = 'https://api.coingecko.com/api/v3/simple/price?vs_currencies=usd&ids=bitcoin';
12983
- const url = `https://api.coingecko.com/api/v3/simple/price?vs_currencies=${vs_currencies}&ids=${token}`;
12984
-
12985
- try {
12986
- const response = await fetch(url);
12987
- if (!response.ok) {
12988
- throw new Error(`HTTP error! Status: ${response.status}`)
12989
- }
12990
- const jsonResponse = await response.json();
12991
- //JSON RESPONSE EXAMPLE
12992
- // {
12993
- // "bitcoin": {
12994
- // "usd": 103457,
12995
- // "inr": 8854165
12996
- // },
12997
- // "solana": {
12998
- // "usd": 167.56,
12999
- // "inr": 14340.55
13000
- // }
13001
- // }
13002
- console.log(jsonResponse);
13003
- // if(jsonResponse.result.includes("Invalid API Key")){
13004
- // return `${SERVICE_API_KEY.Coingecko}_MISSING`
13005
- // }
13006
- const output = {};
13007
-
13008
- for (const [coin, prices] of Object.entries(jsonResponse)) {
13009
- for (const [currency, value] of Object.entries(prices)) {
13010
- const key = `${coin.charAt(0).toUpperCase() + coin.slice(1)}_${currency.toUpperCase()}`;
13011
- output[key] = value;
13012
- }
12995
+ }
12996
+ const jsonResponse = await response.json();
12997
+
12998
+ // Free Coingecko API does not require API key, not need to handle API key error
12999
+
13000
+ const output = {};
13001
+ for (const [coin, prices] of Object.entries(jsonResponse)) {
13002
+ for (const [currency, value] of Object.entries(prices)) {
13003
+ const key = `${coin.charAt(0).toUpperCase() + coin.slice(1)}_${currency.toUpperCase()}`;
13004
+ output[key] = value;
13013
13005
  }
13014
- console.log([output]);
13015
- return [output];
13016
- } catch (error) {
13017
- console.error('API call failed:', error);
13018
- return "ERROR IN FETCHING"
13019
13006
  }
13007
+ /*
13008
+ [{Bitcon_usd: 1, Bitcoin_eur: 1},{Ethereum_usd: 1, Ethereum_eur: 1}}]
13009
+ */
13010
+ return [output];
13011
+ } catch (error) {
13012
+ return "ERROR IN FETCHING"
13020
13013
  }
13014
+ }
13021
13015
 
13022
13016
  const utils = { errors, symbols, date };
13023
13017
 
package/lib/esm/index.mjs CHANGED
@@ -12948,74 +12948,68 @@ function SWITCH() {
12948
12948
  }
12949
12949
 
12950
12950
  const SERVICE_API_KEY = {
12951
- Etherscan: "ETHERSCAN_API_KEY",
12952
- Coingecko: "COINGECKO_API_KEY"
12951
+ Etherscan: "ETHERSCAN_API_KEY",
12952
+ Coingecko: "COINGECKO_API_KEY"
12953
12953
  };
12954
12954
 
12955
12955
  async function GETTXLIST(address, page, offset) {
12956
- const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Etherscan);
12957
- console.log("FORMULA JS API KEY ETHERSCAN NOT FOUND", API_KEY);
12958
- const url = `https://api.etherscan.io/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=${page}&offset=${offset}&sort=asc&apikey=${API_KEY}`;
12959
-
12960
- try {
12961
- const response = await fetch(url);
12962
- if (!response.ok) {
12963
- throw new Error(`HTTP error! Status: ${response.status}`)
12964
- }
12956
+ const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Etherscan);
12957
+ const url = `https://api.etherscan.io/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=${page}&offset=${offset}&sort=asc&apikey=${API_KEY}`;
12958
+
12959
+ try {
12960
+ const response = await fetch(url);
12961
+ if (!response.ok) {
12962
+ throw new Error(`HTTP error! Status: ${response.status}`)
12963
+ }
12964
+ const json = await response.json();
12965
+ if (json.result.includes("Invalid API Key")) {
12966
+ return `${SERVICE_API_KEY.Etherscan}_MISSING`
12967
+ }
12968
+ /*
12969
+ [{blockNumber: '0x1d3d1', timeStamp: '0x5f7e4f', hash: '0x3c3c3c3c', nonce: '0x1',}]
12970
+ */
12971
+ return json.result;
12972
+ } catch (error) {
12973
+ return "ERROR IN FETCHING"
12974
+ }
12975
+ }
12976
+
12977
+ async function GETPRICE(token, vs_currencies) {
12978
+ const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Coingecko);
12979
+ const url = `https://api.coingecko.com/api/v3/simple/price?vs_currencies=${vs_currencies}&ids=${token}`;
12980
+
12981
+ const options = {
12982
+ method: 'GET',
12983
+ headers: { accept: 'application/json', 'x-cg-demo-api-key': `${API_KEY}` },
12984
+ };
12985
+
12986
+ try {
12987
+ const response = await fetch(url, options);
12988
+ if (!response.ok) {
12965
12989
  const json = await response.json();
12966
- console.log(json.result);
12967
- if(json.result.includes("Invalid API Key")){
12968
- return `${SERVICE_API_KEY.Etherscan}_MISSING`
12990
+ if (json.status.error_message.includes("API Key Missing")) {
12991
+ return `${SERVICE_API_KEY.Coingecko}_MISSING`
12969
12992
  }
12970
- return json.result;
12971
- } catch (error) {
12972
- console.error('API call failed:', error);
12973
- return "ERROR IN FETCHING"
12974
- }
12975
- }
12976
-
12977
- async function GETPRICE(token, vs_currencies, offset) {
12978
- const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Coingecko);
12979
- console.log("FORMULA JS API KEY ETHERSCAN NOT FOUND", API_KEY);
12980
- // const url = 'https://api.coingecko.com/api/v3/simple/price?vs_currencies=usd&ids=bitcoin';
12981
- const url = `https://api.coingecko.com/api/v3/simple/price?vs_currencies=${vs_currencies}&ids=${token}`;
12982
-
12983
- try {
12984
- const response = await fetch(url);
12985
- if (!response.ok) {
12986
- throw new Error(`HTTP error! Status: ${response.status}`)
12987
- }
12988
- const jsonResponse = await response.json();
12989
- //JSON RESPONSE EXAMPLE
12990
- // {
12991
- // "bitcoin": {
12992
- // "usd": 103457,
12993
- // "inr": 8854165
12994
- // },
12995
- // "solana": {
12996
- // "usd": 167.56,
12997
- // "inr": 14340.55
12998
- // }
12999
- // }
13000
- console.log(jsonResponse);
13001
- // if(jsonResponse.result.includes("Invalid API Key")){
13002
- // return `${SERVICE_API_KEY.Coingecko}_MISSING`
13003
- // }
13004
- const output = {};
13005
-
13006
- for (const [coin, prices] of Object.entries(jsonResponse)) {
13007
- for (const [currency, value] of Object.entries(prices)) {
13008
- const key = `${coin.charAt(0).toUpperCase() + coin.slice(1)}_${currency.toUpperCase()}`;
13009
- output[key] = value;
13010
- }
12993
+ }
12994
+ const jsonResponse = await response.json();
12995
+
12996
+ // Free Coingecko API does not require API key, not need to handle API key error
12997
+
12998
+ const output = {};
12999
+ for (const [coin, prices] of Object.entries(jsonResponse)) {
13000
+ for (const [currency, value] of Object.entries(prices)) {
13001
+ const key = `${coin.charAt(0).toUpperCase() + coin.slice(1)}_${currency.toUpperCase()}`;
13002
+ output[key] = value;
13011
13003
  }
13012
- console.log([output]);
13013
- return [output];
13014
- } catch (error) {
13015
- console.error('API call failed:', error);
13016
- return "ERROR IN FETCHING"
13017
13004
  }
13005
+ /*
13006
+ [{Bitcon_usd: 1, Bitcoin_eur: 1},{Ethereum_usd: 1, Ethereum_eur: 1}}]
13007
+ */
13008
+ return [output];
13009
+ } catch (error) {
13010
+ return "ERROR IN FETCHING"
13018
13011
  }
13012
+ }
13019
13013
 
13020
13014
  const utils = { errors, symbols, date };
13021
13015
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/formulajs",
3
- "version": "4.4.11-mod-8",
3
+ "version": "4.4.11-mod-10",
4
4
  "description": "JavaScript implementation of most Microsoft Excel formula functions",
5
5
  "author": "Formulajs",
6
6
  "publishConfig": {
@@ -1784,7 +1784,7 @@ export function GEOMEAN(...args: any[]): any;
1784
1784
  * @returns
1785
1785
  */
1786
1786
  export function GESTEP(number: any, step: any): any;
1787
- export function GETPRICE(token: any, vs_currencies: any, offset: any): Promise<"ERROR IN FETCHING" | {}[]>;
1787
+ export function GETPRICE(token: any, vs_currencies: any): Promise<string | {}[]>;
1788
1788
  export function GETTXLIST(address: any, page: any, offset: any): Promise<any>;
1789
1789
  /**
1790
1790
  * Returns values along an exponential trend.
@@ -1784,7 +1784,7 @@ export function GEOMEAN(...args: any[]): any;
1784
1784
  * @returns
1785
1785
  */
1786
1786
  export function GESTEP(number: any, step: any): any;
1787
- export function GETPRICE(token: any, vs_currencies: any, offset: any): Promise<"ERROR IN FETCHING" | {}[]>;
1787
+ export function GETPRICE(token: any, vs_currencies: any): Promise<string | {}[]>;
1788
1788
  export function GETTXLIST(address: any, page: any, offset: any): Promise<any>;
1789
1789
  /**
1790
1790
  * Returns values along an exponential trend.