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

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
@@ -18524,7 +18524,7 @@ const activity = objectType({
18524
18524
  });
18525
18525
 
18526
18526
  const tokenHolders = objectType({
18527
- type: literalType("token_holders"),
18527
+ type: literalType("token-holders"),
18528
18528
  input1: stringType().nonempty(), // expects token address
18529
18529
  input2: stringType().nonempty(), // chain id / name
18530
18530
  input3: numberType().int().min(1).max(500).optional() // limit
@@ -18551,16 +18551,12 @@ function flattenObject(obj, parentKey = '', res = {}) {
18551
18551
  if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
18552
18552
  const newKey = parentKey ? `${parentKey}_${key}` : key;
18553
18553
 
18554
- if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
18555
- flattenObject(obj[key], newKey, res);
18556
- } else if (Array.isArray(obj[key])) {
18557
- obj[key].forEach((val, i) => {
18558
- if (typeof val === 'object' && val !== null) {
18559
- flattenObject(val, `${newKey}_${i}`, res);
18560
- } else {
18561
- res[`${newKey}_${i}`] = val;
18562
- }
18563
- });
18554
+ if (typeof obj[key] === 'object' && obj[key] !== null) {
18555
+ if (Array.isArray(obj[key])) {
18556
+ continue;
18557
+ } else {
18558
+ flattenObject(obj[key], newKey, res);
18559
+ }
18564
18560
  } else {
18565
18561
  res[newKey] = obj[key];
18566
18562
  }
@@ -18584,6 +18580,22 @@ const SUPPORTED_TOKEN_NAMES = {
18584
18580
 
18585
18581
 
18586
18582
 
18583
+ function formatNumber(raw, decimals) {
18584
+ if(!decimals){
18585
+ return raw
18586
+ }
18587
+ const quorum = BigInt(raw);
18588
+ const divisor = 10 ** decimals;
18589
+ const normalized = Number(quorum) / divisor;
18590
+
18591
+ return new Intl.NumberFormat("en-US", {
18592
+ notation: "compact",
18593
+ maximumFractionDigits: 2,
18594
+ }).format(normalized);
18595
+ }
18596
+
18597
+
18598
+
18587
18599
  async function DUNESIM() {
18588
18600
  try {
18589
18601
  const [type, input1, input2, input3, input4] = argsToArray(arguments);
@@ -18602,7 +18614,7 @@ async function DUNESIM() {
18602
18614
  };
18603
18615
 
18604
18616
  if (type === 'activity') {
18605
- const address = fromEnsNameToAddress$1.validateAndGetAddress(input1);
18617
+ const address = await fromEnsNameToAddress$1.validateAndGetAddress(input1);
18606
18618
  const qs = buildQuery([['chain_ids', SUPPORTED_TOKEN_NAMES[input2] || input2], ['limit', input3]]);
18607
18619
  route = `activity/${address}${qs}`;
18608
18620
  }
@@ -18618,7 +18630,7 @@ async function DUNESIM() {
18618
18630
  route = `token-info/${tokenAddress}${qs}`;
18619
18631
  }
18620
18632
 
18621
- if (type === 'token_holders') {
18633
+ if (type === 'token-holders') {
18622
18634
  const qs = buildQuery([['limit', input3]]);
18623
18635
  const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
18624
18636
  route = `token-holders/${chain}/${input1}${qs}`;
@@ -18627,8 +18639,6 @@ async function DUNESIM() {
18627
18639
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.DuneSim);
18628
18640
  const url = `https://api.sim.dune.com/v1/evm/${route}`;
18629
18641
 
18630
- console.log({route});
18631
-
18632
18642
  const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
18633
18643
  url, serviceName: "DuneSim",
18634
18644
  headers: { "X-Sim-Api-Key": apiKey },
@@ -18640,11 +18650,34 @@ async function DUNESIM() {
18640
18650
  const json = await res.json();
18641
18651
  const data =
18642
18652
  type === "activity" ? json?.activity ?? json ?? [] :
18643
- type === "token_holders" ? json?.holders ?? json ?? [] :
18653
+ type === "token-holders" ? json?.holders ?? json ?? [] :
18644
18654
  type === "price" ? json?.tokens ?? json ?? [] :
18645
18655
  json ?? [];
18646
- const result = data.map((item) => flattenObject(item));
18647
- console.log({result});
18656
+ const result = (Array.isArray(data) ? data : [data]).map((item) => {
18657
+ if(item?.decimals){
18658
+ if(item?.total_supply){
18659
+ item.total_supply = formatNumber(item?.total_supply, item.decimals);
18660
+ }
18661
+ }
18662
+ if(item?.first_acquired){
18663
+ item.first_acquired = new Intl.DateTimeFormat("en-US", {
18664
+ year: "numeric",
18665
+ month: "long",
18666
+ day: "numeric",
18667
+ hour: "numeric",
18668
+ minute: "2-digit"
18669
+ }).format(new Date(item.first_acquired));
18670
+ }
18671
+ if(item.historical_prices){
18672
+ const prices = item.historical_prices;
18673
+ prices.forEach((priceData) => {
18674
+ const key = "price_" + priceData.offset_hours +"h";
18675
+ const price = priceData.price_usd;
18676
+ item[key] = price;
18677
+ });
18678
+ }
18679
+ return flattenObject(item)
18680
+ });
18648
18681
  return result
18649
18682
  } catch (err) {
18650
18683
  return errorMessageHandler(err, "DUNESIM");
@@ -18652,19 +18685,19 @@ async function DUNESIM() {
18652
18685
  }
18653
18686
 
18654
18687
 
18655
- // (async () => {
18688
+ (async () => {
18656
18689
  // Example: activity
18657
18690
  // const res1 = await DUNESIM('activity', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', "eth", 5);
18658
18691
  // console.log('Activity result:', res1, res1.length);
18659
18692
 
18660
- // // Example: price (token-info)
18661
- // const res2 = await DUNESIM('price', 'base', '1,6,24', "0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca", 5);
18693
+ // Example: price (token-info)
18694
+ // const res2 = await DUNESIM('price', 'eth', '1,6,24', "", 5);
18662
18695
  // console.log('Price result:', res2);
18663
18696
 
18664
18697
  // // Example: token holders
18665
- // const res3 = await DUNESIM('token_holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "8453", 5);
18698
+ // const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base", 5);
18666
18699
  // console.log('Holders result:', res3, res3.length);
18667
- // })();
18700
+ })();
18668
18701
 
18669
18702
  // export {GNOSISPAY} from './gnosispay/gnosispay.js'
18670
18703
 
@@ -895,21 +895,21 @@ var DUNESIM_metadata = {
895
895
  },
896
896
  {
897
897
  name: "input1",
898
- detail: 'When type is "price": the chain ID or name to query token prices. When "activity": wallet address or ENS. When "token_holders": token address.',
899
- example: "base",
898
+ detail: 'When type is "price": the chain ID or name to query token prices. When "activity": wallet address or ENS. When "token-holders": token address.',
899
+ example: `"base"`,
900
900
  require: "m",
901
901
  type: "string"
902
902
  },
903
903
  {
904
904
  name: "input2",
905
- detail: 'When "price": optional historical price offsets. When "activity": optional chain ID or name ( e.g eth ). When "token_holders": chain ID or name ( e.g eth ).',
905
+ detail: 'When "price": optional historical price offsets. When "activity": optional chain ID or name ( e.g eth ). When "token-holders": chain ID or name ( e.g eth ).',
906
906
  example: `"1,6,24"`,
907
907
  require: "o",
908
908
  type: "string"
909
909
  },
910
910
  {
911
911
  name: "input3",
912
- detail: 'When "price": optional token contract address, when "activity": limit (1\u2013100), when "token_holders": limit (1\u2013500).',
912
+ detail: 'When "price": optional token contract address, when "activity": limit (1\u2013100), when "token-holders": limit (1\u2013500).',
913
913
  example: `"0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca"`,
914
914
  require: "o",
915
915
  type: "number"
package/lib/esm/index.mjs CHANGED
@@ -18522,7 +18522,7 @@ const activity = objectType({
18522
18522
  });
18523
18523
 
18524
18524
  const tokenHolders = objectType({
18525
- type: literalType("token_holders"),
18525
+ type: literalType("token-holders"),
18526
18526
  input1: stringType().nonempty(), // expects token address
18527
18527
  input2: stringType().nonempty(), // chain id / name
18528
18528
  input3: numberType().int().min(1).max(500).optional() // limit
@@ -18549,16 +18549,12 @@ function flattenObject(obj, parentKey = '', res = {}) {
18549
18549
  if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
18550
18550
  const newKey = parentKey ? `${parentKey}_${key}` : key;
18551
18551
 
18552
- if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
18553
- flattenObject(obj[key], newKey, res);
18554
- } else if (Array.isArray(obj[key])) {
18555
- obj[key].forEach((val, i) => {
18556
- if (typeof val === 'object' && val !== null) {
18557
- flattenObject(val, `${newKey}_${i}`, res);
18558
- } else {
18559
- res[`${newKey}_${i}`] = val;
18560
- }
18561
- });
18552
+ if (typeof obj[key] === 'object' && obj[key] !== null) {
18553
+ if (Array.isArray(obj[key])) {
18554
+ continue;
18555
+ } else {
18556
+ flattenObject(obj[key], newKey, res);
18557
+ }
18562
18558
  } else {
18563
18559
  res[newKey] = obj[key];
18564
18560
  }
@@ -18582,6 +18578,22 @@ const SUPPORTED_TOKEN_NAMES = {
18582
18578
 
18583
18579
 
18584
18580
 
18581
+ function formatNumber(raw, decimals) {
18582
+ if(!decimals){
18583
+ return raw
18584
+ }
18585
+ const quorum = BigInt(raw);
18586
+ const divisor = 10 ** decimals;
18587
+ const normalized = Number(quorum) / divisor;
18588
+
18589
+ return new Intl.NumberFormat("en-US", {
18590
+ notation: "compact",
18591
+ maximumFractionDigits: 2,
18592
+ }).format(normalized);
18593
+ }
18594
+
18595
+
18596
+
18585
18597
  async function DUNESIM() {
18586
18598
  try {
18587
18599
  const [type, input1, input2, input3, input4] = argsToArray(arguments);
@@ -18600,7 +18612,7 @@ async function DUNESIM() {
18600
18612
  };
18601
18613
 
18602
18614
  if (type === 'activity') {
18603
- const address = fromEnsNameToAddress$1.validateAndGetAddress(input1);
18615
+ const address = await fromEnsNameToAddress$1.validateAndGetAddress(input1);
18604
18616
  const qs = buildQuery([['chain_ids', SUPPORTED_TOKEN_NAMES[input2] || input2], ['limit', input3]]);
18605
18617
  route = `activity/${address}${qs}`;
18606
18618
  }
@@ -18616,7 +18628,7 @@ async function DUNESIM() {
18616
18628
  route = `token-info/${tokenAddress}${qs}`;
18617
18629
  }
18618
18630
 
18619
- if (type === 'token_holders') {
18631
+ if (type === 'token-holders') {
18620
18632
  const qs = buildQuery([['limit', input3]]);
18621
18633
  const chain = SUPPORTED_TOKEN_NAMES[input2] || input2;
18622
18634
  route = `token-holders/${chain}/${input1}${qs}`;
@@ -18625,8 +18637,6 @@ async function DUNESIM() {
18625
18637
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.DuneSim);
18626
18638
  const url = `https://api.sim.dune.com/v1/evm/${route}`;
18627
18639
 
18628
- console.log({route});
18629
-
18630
18640
  const { URL: finalUrl, HEADERS } = getUrlAndHeaders({
18631
18641
  url, serviceName: "DuneSim",
18632
18642
  headers: { "X-Sim-Api-Key": apiKey },
@@ -18638,11 +18648,34 @@ async function DUNESIM() {
18638
18648
  const json = await res.json();
18639
18649
  const data =
18640
18650
  type === "activity" ? json?.activity ?? json ?? [] :
18641
- type === "token_holders" ? json?.holders ?? json ?? [] :
18651
+ type === "token-holders" ? json?.holders ?? json ?? [] :
18642
18652
  type === "price" ? json?.tokens ?? json ?? [] :
18643
18653
  json ?? [];
18644
- const result = data.map((item) => flattenObject(item));
18645
- console.log({result});
18654
+ const result = (Array.isArray(data) ? data : [data]).map((item) => {
18655
+ if(item?.decimals){
18656
+ if(item?.total_supply){
18657
+ item.total_supply = formatNumber(item?.total_supply, item.decimals);
18658
+ }
18659
+ }
18660
+ if(item?.first_acquired){
18661
+ item.first_acquired = new Intl.DateTimeFormat("en-US", {
18662
+ year: "numeric",
18663
+ month: "long",
18664
+ day: "numeric",
18665
+ hour: "numeric",
18666
+ minute: "2-digit"
18667
+ }).format(new Date(item.first_acquired));
18668
+ }
18669
+ if(item.historical_prices){
18670
+ const prices = item.historical_prices;
18671
+ prices.forEach((priceData) => {
18672
+ const key = "price_" + priceData.offset_hours +"h";
18673
+ const price = priceData.price_usd;
18674
+ item[key] = price;
18675
+ });
18676
+ }
18677
+ return flattenObject(item)
18678
+ });
18646
18679
  return result
18647
18680
  } catch (err) {
18648
18681
  return errorMessageHandler(err, "DUNESIM");
@@ -18650,19 +18683,19 @@ async function DUNESIM() {
18650
18683
  }
18651
18684
 
18652
18685
 
18653
- // (async () => {
18686
+ (async () => {
18654
18687
  // Example: activity
18655
18688
  // const res1 = await DUNESIM('activity', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', "eth", 5);
18656
18689
  // console.log('Activity result:', res1, res1.length);
18657
18690
 
18658
- // // Example: price (token-info)
18659
- // const res2 = await DUNESIM('price', 'base', '1,6,24', "0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca", 5);
18691
+ // Example: price (token-info)
18692
+ // const res2 = await DUNESIM('price', 'eth', '1,6,24', "", 5);
18660
18693
  // console.log('Price result:', res2);
18661
18694
 
18662
18695
  // // Example: token holders
18663
- // const res3 = await DUNESIM('token_holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "8453", 5);
18696
+ // const res3 = await DUNESIM('token-holders', '0x63706e401c06ac8513145b7687A14804d17f814b', "base", 5);
18664
18697
  // console.log('Holders result:', res3, res3.length);
18665
- // })();
18698
+ })();
18666
18699
 
18667
18700
  // export {GNOSISPAY} from './gnosispay/gnosispay.js'
18668
18701
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/formulajs",
3
- "version": "4.4.12-mod-6",
3
+ "version": "4.4.12-mod-8",
4
4
  "description": "JavaScript implementation of most Microsoft Excel formula functions",
5
5
  "author": "Formulajs",
6
6
  "publishConfig": {
@@ -1292,7 +1292,25 @@ export function DSTDEVP(database: any, field: any, criteria: any): number | Erro
1292
1292
  * @returns
1293
1293
  */
1294
1294
  export function DSUM(database: any, field: any, criteria: any): number | Error;
1295
- export function DUNESIM(...args: any[]): Promise<any>;
1295
+ export function DUNESIM(...args: any[]): Promise<{
1296
+ message: string;
1297
+ functionName: any;
1298
+ type: string;
1299
+ apiKeyName?: undefined;
1300
+ reason?: undefined;
1301
+ } | {
1302
+ message: string;
1303
+ functionName: any;
1304
+ type: string;
1305
+ apiKeyName: any;
1306
+ reason?: undefined;
1307
+ } | {
1308
+ message: string;
1309
+ functionName: any;
1310
+ type: string;
1311
+ reason: any;
1312
+ apiKeyName?: undefined;
1313
+ } | {}[]>;
1296
1314
  /**
1297
1315
  * Estimates variance based on a sample from selected database entries.
1298
1316
  *
@@ -1292,7 +1292,25 @@ export function DSTDEVP(database: any, field: any, criteria: any): number | Erro
1292
1292
  * @returns
1293
1293
  */
1294
1294
  export function DSUM(database: any, field: any, criteria: any): number | Error;
1295
- export function DUNESIM(...args: any[]): Promise<any>;
1295
+ export function DUNESIM(...args: any[]): Promise<{
1296
+ message: string;
1297
+ functionName: any;
1298
+ type: string;
1299
+ apiKeyName?: undefined;
1300
+ reason?: undefined;
1301
+ } | {
1302
+ message: string;
1303
+ functionName: any;
1304
+ type: string;
1305
+ apiKeyName: any;
1306
+ reason?: undefined;
1307
+ } | {
1308
+ message: string;
1309
+ functionName: any;
1310
+ type: string;
1311
+ reason: any;
1312
+ apiKeyName?: undefined;
1313
+ } | {}[]>;
1296
1314
  /**
1297
1315
  * Estimates variance based on a sample from selected database entries.
1298
1316
  *