@fileverse-dev/formulajs 4.4.11-mod-18-patch-20 → 4.4.11-mod-21-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
@@ -73,9 +73,17 @@ function dateToSerial(date) {
73
73
  return Math.ceil((date - d1900) / 86400000) + addOn
74
74
  }
75
75
 
76
+ function formatDate(date) {
77
+ const day = String(date.getDate()).padStart(2, '0');
78
+ const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed
79
+ const year = date.getFullYear();
80
+ return `${day}/${month}/${year}`
81
+ }
82
+
76
83
  var date = /*#__PURE__*/Object.freeze({
77
84
  __proto__: null,
78
85
  dateToSerial: dateToSerial,
86
+ formatDate: formatDate,
79
87
  get returnSerial () { return returnSerial; },
80
88
  serialToDate: serialToDate,
81
89
  useDate: useDate,
@@ -549,10 +557,46 @@ function parseDate(date) {
549
557
  }
550
558
 
551
559
  if (typeof date === 'string') {
552
- date = /(\d{4})-(\d\d?)-(\d\d?)$/.test(date) ? new Date(date + 'T00:00:00.000') : new Date(date);
560
+ // Check for YYYY-MM-DD (ISO format)
561
+ if (/^\d{4}-\d{1,2}-\d{1,2}$/.test(date)) {
562
+ return new Date(date + 'T00:00:00.000')
563
+ }
564
+
565
+ // Check for DD/MM/YYYY
566
+ const match = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.exec(date);
567
+ if (match) {
568
+ const [, day, month, year] = match.map(Number);
569
+ const d = new Date(year, month - 1, day);
570
+ if (!isNaN(d)) {
571
+ return d
572
+ }
573
+ }
553
574
 
554
- if (!isNaN(date)) {
555
- return date
575
+ // Handle time-only string (HH:MM[:SS])
576
+ if (/^\d{1,2}:\d{2}(:\d{2})?$/.test(date)) {
577
+ const [h, m, s = '0'] = date.split(':').map(Number);
578
+ const now = new Date();
579
+ now.setHours(h, m, s, 0);
580
+ return now
581
+ }
582
+
583
+ // Handle AM/PM time format (e.g., "2:15 PM")
584
+ const ampmMatch = /^(\d{1,2}):(\d{2})\s*(AM|PM)$/i.exec(date);
585
+ if (ampmMatch) {
586
+ let [, hour, minute, meridian] = ampmMatch;
587
+ hour = parseInt(hour);
588
+ minute = parseInt(minute);
589
+ if (meridian.toUpperCase() === 'PM' && hour !== 12) hour += 12;
590
+ if (meridian.toUpperCase() === 'AM' && hour === 12) hour = 0;
591
+ const now = new Date();
592
+ now.setHours(hour, minute, 0, 0);
593
+ return now
594
+ }
595
+
596
+ // Fallback for other date strings
597
+ const parsed = new Date(date);
598
+ if (!isNaN(parsed)) {
599
+ return parsed
556
600
  }
557
601
  }
558
602
 
@@ -5251,7 +5295,6 @@ function PNL() {
5251
5295
  }
5252
5296
 
5253
5297
 
5254
-
5255
5298
  /**
5256
5299
  * Returns the absolute value of a number.
5257
5300
  *
@@ -6946,8 +6989,6 @@ function SUBTOTAL(function_num, ref1) {
6946
6989
  function SUM() {
6947
6990
  let result = 0;
6948
6991
 
6949
- console.log("LLLLO", argsToArray(arguments), {arguments});
6950
-
6951
6992
  arrayEach(argsToArray(arguments), (value) => {
6952
6993
  if (result instanceof Error) {
6953
6994
  return false
@@ -7827,7 +7868,8 @@ function DAYS(end_date, start_date) {
7827
7868
  return start_date
7828
7869
  }
7829
7870
 
7830
- return dateToSerial(startOfDay(end_date)) - dateToSerial(startOfDay(start_date))
7871
+ const diffMs = startOfDay(end_date).getTime() - startOfDay(start_date).getTime();
7872
+ return diffMs / (1000 * 60 * 60 * 24);
7831
7873
  }
7832
7874
 
7833
7875
  /**
@@ -8142,6 +8184,8 @@ NETWORKDAYS.INTL = (start_date, end_date, weekend, holidays) => {
8142
8184
  return total
8143
8185
  };
8144
8186
 
8187
+ const NETWORKDAYS_INTL = NETWORKDAYS.INTL;
8188
+
8145
8189
  /**
8146
8190
  * Returns the serial number of the current date and time.
8147
8191
  *
@@ -8194,9 +8238,14 @@ function TIME(hour, minute, second) {
8194
8238
  return num
8195
8239
  }
8196
8240
 
8197
- return (3600 * hour + 60 * minute + second) / 86400
8241
+ const hh = String(hour).padStart(2, '0');
8242
+ const mm = String(minute).padStart(2, '0');
8243
+ const ss = String(second).padStart(2, '0');
8244
+
8245
+ return `${hh}:${mm}:${ss}`
8198
8246
  }
8199
8247
 
8248
+
8200
8249
  /**
8201
8250
  * Converts a time in the form of text to a serial number.
8202
8251
  *
@@ -8224,7 +8273,7 @@ function TIMEVALUE(time_text) {
8224
8273
  */
8225
8274
  function TODAY() {
8226
8275
  const today = startOfDay(new Date());
8227
- return returnSerial ? dateToSerial(today) : today
8276
+ return formatDate(today)
8228
8277
  }
8229
8278
 
8230
8279
  /**
@@ -8298,6 +8347,11 @@ function WORKDAY(start_date, days, holidays) {
8298
8347
  return WORKDAY.INTL(start_date, days, 1, holidays)
8299
8348
  }
8300
8349
 
8350
+ function ISDATE(value) {
8351
+ const parsed = parseDate(value);
8352
+ return !(parsed instanceof Error)
8353
+ }
8354
+
8301
8355
  /**
8302
8356
  * Returns the serial number of the date before or after a specified number of workdays using parameters to indicate which and how many days are weekend days.
8303
8357
  *
@@ -8382,9 +8436,11 @@ WORKDAY.INTL = (start_date, days, weekend, holidays) => {
8382
8436
  return value
8383
8437
  }
8384
8438
 
8385
- return start_date
8439
+ return formatDate(start_date)
8386
8440
  };
8387
8441
 
8442
+ const WORKDAY_INTL = WORKDAY.INTL;
8443
+
8388
8444
  /**
8389
8445
  * Converts a serial number to a year.
8390
8446
  *
@@ -13024,18 +13080,18 @@ function SWITCH() {
13024
13080
  const SERVICE_API_KEY = {
13025
13081
  Etherscan: "ETHERSCAN_API_KEY",
13026
13082
  Coingecko: "COINGECKO_API_KEY",
13027
- Safe: "SAFE_API_KEY",
13028
13083
  };
13029
13084
 
13030
13085
  const CHAIN_ID_MAP = {
13031
- ethereum: 1,
13032
- gnosis: 100,
13033
- base: 8453,
13034
- };
13086
+ ethereum: 1,
13087
+ gnosis: 100,
13088
+ base: 8453,
13089
+ };
13035
13090
 
13036
- const SAFE_CHAIN_MAP = {
13037
- ethereum: 'eth',
13038
- gnosis: 'gno',
13091
+ const ERROR_MESSAGES_FLAG = {
13092
+ INVALID_API_KEY: '_MISSING',
13093
+ RATE_LIMIT: '_RATE_LIMIT_REACHED',
13094
+ DEFAULT: 'FETCH_ERROR'
13039
13095
  };
13040
13096
 
13041
13097
  const fromTimeStampToBlock = async (timestamp, chain, apiKey) => {
@@ -13049,28 +13105,32 @@ if(!timestamp || !chain || !apiKey) return
13049
13105
  };
13050
13106
 
13051
13107
  async function ETHERSCAN(address, page, offset) {
13052
- const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Etherscan);
13053
- 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}`;
13054
-
13055
- try {
13056
- const response = await fetch(url);
13057
- if (!response.ok) {
13058
- throw new Error(`HTTP error! Status: ${response.status}`)
13059
- }
13060
- const json = await response.json();
13061
- if (json.result.includes("Invalid API Key")) {
13062
- return `${SERVICE_API_KEY.Etherscan}_MISSING`
13063
- }
13064
- /*
13065
- [{blockNumber: '0x1d3d1', timeStamp: '0x5f7e4f', hash: '0x3c3c3c3c', nonce: '0x1',}]
13066
- */
13067
- return json.result;
13068
- } catch (error) {
13069
- return "ERROR IN FETCHING"
13070
- }
13071
- }
13072
-
13073
- async function GETPRICE(token, vs_currencies) {
13108
+ return `${SERVICE_API_KEY.Etherscan}${ERROR_MESSAGES_FLAG.RATE_LIMIT}`
13109
+ // const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Etherscan);
13110
+ // const url = `https://api.etherscan.io/v2/api?chainid=1&module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=${page || 1}&offset=${offset || 10}&sort=asc&apikey=${API_KEY}`
13111
+
13112
+ // try {
13113
+ // const response = await fetch(url)
13114
+ // if (!response.ok) {
13115
+ // throw new Error(`HTTP error! Status: ${response.status}`)
13116
+ // }
13117
+ // const json = await response.json()
13118
+ // if (json.result.includes("Invalid API Key")) {
13119
+ // return `${SERVICE_API_KEY.Etherscan}${ERROR_MESSAGES_FLAG.INVALID_API_KEY}`
13120
+ // }
13121
+ // if(json.result.includes('Max rate limit reached')){
13122
+ // return `${SERVICE_API_KEY.Etherscan}${ERROR_MESSAGES_FLAG.RATE_LIMIT}`
13123
+ // }
13124
+ // /*
13125
+ // [{blockNumber: '0x1d3d1', timeStamp: '0x5f7e4f', hash: '0x3c3c3c3c', nonce: '0x1',}]
13126
+ // */
13127
+ // return json.result;
13128
+ // } catch (error) {
13129
+ // return ERROR_MESSAGES_FLAG.DEFAULT
13130
+ // }
13131
+ }
13132
+
13133
+ async function COINGECKO(token, vs_currencies) {
13074
13134
  const API_KEY = window.localStorage.getItem(SERVICE_API_KEY.Coingecko);
13075
13135
  const url = `https://api.coingecko.com/api/v3/simple/price?vs_currencies=${vs_currencies}&ids=${token}`;
13076
13136
 
@@ -13084,7 +13144,10 @@ async function GETPRICE(token, vs_currencies) {
13084
13144
  if (!response.ok) {
13085
13145
  const json = await response.json();
13086
13146
  if (json.status.error_message.includes("API Key Missing")) {
13087
- return `${SERVICE_API_KEY.Coingecko}_MISSING`
13147
+ return `${SERVICE_API_KEY.Coingecko}${ERROR_MESSAGES_FLAG.INVALID_API_KEY}`
13148
+ }
13149
+ if(response.status === 429){
13150
+ return `${SERVICE_API_KEY.Coingecko}${ERROR_MESSAGES_FLAG.RATE_LIMIT}`
13088
13151
  }
13089
13152
  }
13090
13153
  const jsonResponse = await response.json();
@@ -13103,11 +13166,11 @@ async function GETPRICE(token, vs_currencies) {
13103
13166
  */
13104
13167
  return [output];
13105
13168
  } catch (error) {
13106
- return "ERROR IN FETCHING"
13169
+ return ERROR_MESSAGES_FLAG.DEFAULT
13107
13170
  }
13108
13171
  }
13109
13172
 
13110
- async function OX(address, categories, chain, startTime, endTime) {
13173
+ async function EOA(address, categories, chain, startTime, endTime) {
13111
13174
  const API_KEYS = {
13112
13175
  ethereum: window.localStorage.getItem(SERVICE_API_KEY.Etherscan),
13113
13176
  gnosis: window.localStorage.getItem(SERVICE_API_KEY.Gnosisscan),
@@ -13119,12 +13182,12 @@ async function OX(address, categories, chain, startTime, endTime) {
13119
13182
 
13120
13183
  let action = '';
13121
13184
  if (categories === 'txns') action = 'account.txlist';
13122
- else { action = 'account.balance'; } let timeQuery = '';
13123
- if (!isNaN(startTime) && !isNaN(endTime)) {
13124
- const startBlock = await fromTimeStampToBlock(startTime, chain, apiKey);
13125
- const endBlock = await fromTimeStampToBlock(endTime, chain, apiKey);
13185
+ else {action = 'account.balance';} let timeQuery = '';
13186
+ if(!isNaN(startTime) && !isNaN(endTime)){
13187
+ const startBlock = await fromTimeStampToBlock(startTime, chain, apiKey);
13188
+ const endBlock = await fromTimeStampToBlock(endTime, chain, apiKey);
13126
13189
  timeQuery = `&startblock=${startBlock}&endblock=${endBlock}`;
13127
- } else if (categories === 'balance') {
13190
+ } else if(categories === 'balance') {
13128
13191
  timeQuery = `&tag=latest`;
13129
13192
  } else {
13130
13193
  throw new Error('Start and End Time is required for querying transaction list ')
@@ -13137,56 +13200,28 @@ async function OX(address, categories, chain, startTime, endTime) {
13137
13200
  if (json.result?.includes?.("Invalid API Key")) {
13138
13201
  return `${SERVICE_API_KEY[chain.charAt(0).toUpperCase() + chain.slice(1)]}_MISSING`;
13139
13202
  }
13203
+ if(json.result.includes('Max rate limit reached')){
13204
+ return `${SERVICE_API_KEY.Etherscan}${ERROR_MESSAGES_FLAG.RATE_LIMIT}`
13205
+ }
13140
13206
  return json.result;
13141
13207
  } catch (e) {
13142
13208
  console.log(e);
13143
- return "ERROR IN FETCHING";
13209
+ return ERROR_MESSAGES_FLAG.DEFAULT;
13144
13210
  }
13145
13211
  }
13146
13212
 
13147
13213
 
13214
+
13215
+
13216
+
13148
13217
  async function FLVURL(token, vs_currencies) {
13149
13218
  return new Promise((resolve) => {
13150
13219
  setTimeout(() => {
13151
- resolve([{ "Yoo": "gotcha" }]);
13220
+ resolve([{"Yoo": "gotcha"}]);
13152
13221
  }, 10000);
13153
13222
  });
13154
13223
  }
13155
13224
 
13156
- async function SAFE(address, utility, chain, limit, offset) {
13157
-
13158
- if (typeof limit !== 'number' || limit < 0) return 'INVALID_LIMIT';
13159
- if (typeof offset !== 'number' || offset < 0) return 'INVALID_OFFSET';
13160
- if (utility !== 'txns') return 'UTILITY IS NOT SUPPORTED';
13161
-
13162
- const apiKey = window.localStorage.getItem(SERVICE_API_KEY.Safe);
13163
- const chainIdentifier = SAFE_CHAIN_MAP[chain];
13164
-
13165
- if (!apiKey) return `${SERVICE_API_KEY.Safe}_MISSING`;
13166
- if (!chainIdentifier) return 'CHAIN IS NOT SUPPORTED';
13167
-
13168
- const url = `https://api.safe.global/tx-service/${chainIdentifier}/api/v2/safes/${address}/multisig-transactions?limit=${limit}&offset=${offset}`;
13169
- try {
13170
- const response = await fetch(url,
13171
- {
13172
- headers: {
13173
- 'Authorization': `Bearer ${apiKey}`,
13174
- },
13175
- }
13176
- );
13177
- if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
13178
- const json = await response.json();
13179
- if (!Array.isArray(json.results)) {
13180
- return "INVALID API RESPONSE";
13181
- }
13182
- // remove nested structure from the response
13183
- return json.results.map(({ confirmations, dataDecoded, ...rest }) => rest);
13184
- } catch (e) {
13185
- console.log(e);
13186
- return "ERROR IN FETCHING";
13187
- }
13188
- }
13189
-
13190
13225
  const utils = { errors, symbols, date };
13191
13226
 
13192
13227
  exports.ABS = ABS;
@@ -13239,6 +13274,7 @@ exports.CHITEST = CHITEST;
13239
13274
  exports.CHOOSE = CHOOSE;
13240
13275
  exports.CLEAN = CLEAN;
13241
13276
  exports.CODE = CODE;
13277
+ exports.COINGECKO = COINGECKO;
13242
13278
  exports.COLUMN = COLUMN;
13243
13279
  exports.COLUMNS = COLUMNS;
13244
13280
  exports.COMBIN = COMBIN;
@@ -13301,6 +13337,7 @@ exports.DVAR = DVAR;
13301
13337
  exports.DVARP = DVARP;
13302
13338
  exports.EDATE = EDATE;
13303
13339
  exports.EFFECT = EFFECT;
13340
+ exports.EOA = EOA;
13304
13341
  exports.EOMONTH = EOMONTH;
13305
13342
  exports.ERF = ERF;
13306
13343
  exports.ERFC = ERFC;
@@ -13343,7 +13380,6 @@ exports.GAUSS = GAUSS;
13343
13380
  exports.GCD = GCD;
13344
13381
  exports.GEOMEAN = GEOMEAN;
13345
13382
  exports.GESTEP = GESTEP;
13346
- exports.GETPRICE = GETPRICE;
13347
13383
  exports.GROWTH = GROWTH;
13348
13384
  exports.HARMEAN = HARMEAN;
13349
13385
  exports.HEX2BIN = HEX2BIN;
@@ -13388,6 +13424,7 @@ exports.INTERCEPT = INTERCEPT;
13388
13424
  exports.IPMT = IPMT;
13389
13425
  exports.IRR = IRR;
13390
13426
  exports.ISBLANK = ISBLANK;
13427
+ exports.ISDATE = ISDATE;
13391
13428
  exports.ISERR = ISERR;
13392
13429
  exports.ISERROR = ISERROR;
13393
13430
  exports.ISEVEN = ISEVEN;
@@ -13442,6 +13479,7 @@ exports.NEGBINOM = NEGBINOM;
13442
13479
  exports.NEGBINOMDIST = NEGBINOMDIST;
13443
13480
  exports.NETWORKDAYS = NETWORKDAYS;
13444
13481
  exports.NETWORKDAYSINTL = NETWORKDAYSINTL;
13482
+ exports.NETWORKDAYS_INTL = NETWORKDAYS_INTL;
13445
13483
  exports.NOMINAL = NOMINAL;
13446
13484
  exports.NORM = NORM;
13447
13485
  exports.NORMDIST = NORMDIST;
@@ -13458,7 +13496,6 @@ exports.OCT2DEC = OCT2DEC;
13458
13496
  exports.OCT2HEX = OCT2HEX;
13459
13497
  exports.ODD = ODD;
13460
13498
  exports.OR = OR;
13461
- exports.OX = OX;
13462
13499
  exports.PDURATION = PDURATION;
13463
13500
  exports.PEARSON = PEARSON;
13464
13501
  exports.PERCENTILE = PERCENTILE;
@@ -13504,7 +13541,6 @@ exports.ROW = ROW;
13504
13541
  exports.ROWS = ROWS;
13505
13542
  exports.RRI = RRI;
13506
13543
  exports.RSQ = RSQ;
13507
- exports.SAFE = SAFE;
13508
13544
  exports.SEARCH = SEARCH;
13509
13545
  exports.SEC = SEC;
13510
13546
  exports.SECH = SECH;
@@ -13579,6 +13615,7 @@ exports.WEIBULL = WEIBULL;
13579
13615
  exports.WEIBULLDIST = WEIBULLDIST;
13580
13616
  exports.WORKDAY = WORKDAY;
13581
13617
  exports.WORKDAYINTL = WORKDAYINTL;
13618
+ exports.WORKDAY_INTL = WORKDAY_INTL;
13582
13619
  exports.XIRR = XIRR;
13583
13620
  exports.XNPV = XNPV;
13584
13621
  exports.XOR = XOR;
@@ -1,8 +1,7 @@
1
1
  // src/crypto-constants.js
2
2
  var SERVICE_API_KEY = {
3
3
  Etherscan: "ETHERSCAN_API_KEY",
4
- Coingecko: "COINGECKO_API_KEY",
5
- Safe: "SAFE_API_KEY"
4
+ Coingecko: "COINGECKO_API_KEY"
6
5
  };
7
6
  var FUNCTION_LOCALE = [
8
7
  {
@@ -44,7 +43,7 @@ var FUNCTION_LOCALE = [
44
43
  LOGO: "https://raw.githubusercontent.com/mritunjayz/github-storage/refs/heads/main/1689874988430.jpeg",
45
44
  BRAND_COLOR: "#F6F7F8",
46
45
  BRAND_SECONDARY_COLOR: "#21325B",
47
- n: "0x",
46
+ n: "EOA",
48
47
  t: 20,
49
48
  d: "Fetches address data like transactions, balances, or portfolio info from multiple supported chains.",
50
49
  a: "Dynamically queries blockchain data such as transactions, balances by resolving time ranges to block ranges.",
@@ -84,7 +83,7 @@ var FUNCTION_LOCALE = [
84
83
  ]
85
84
  },
86
85
  {
87
- n: "GETPRICE",
86
+ n: "COINGECKO",
88
87
  t: 20,
89
88
  API_KEY: SERVICE_API_KEY.Coingecko,
90
89
  d: "Query the prices of one or more coins by using their unique Coin API IDs, symbols, or names.",
@@ -125,42 +124,26 @@ var FUNCTION_LOCALE = [
125
124
  ]
126
125
  },
127
126
  {
128
- n: "SAFE",
127
+ n: "PNL",
129
128
  t: 20,
130
- d: "Query the list of transactions performed by a Safe address, with optional pagination.",
131
- a: "Query the list of transactions performed by a Safe address, with optional pagination.",
129
+ d: "Subtract each element from A column from B column and return the total sum.",
130
+ a: "Returns the total of A - B element-wise subtraction across two ranges.",
132
131
  p: [
133
132
  {
134
- name: "address",
135
- detail: "The address to query, in hexadecimal format.",
136
- example: `"0xc5102fE9359FD9a28f877a67E36B0F050d81a3CC"`,
137
- require: "m"
138
- },
139
- {
140
- name: "utility",
141
- detail: "The utility to query, supported values: 'txns'.",
142
- example: `"txns"`,
143
- require: "m"
144
- },
145
- {
146
- name: "chain",
147
- detail: "The chain to query, supported values: 'ethereum', 'gnosis'.",
148
- example: `"ethereum"`,
149
- require: "m"
150
- },
151
- {
152
- name: "limit",
153
- detail: "The number of transactions to return, default is 100.",
154
- example: `100`,
155
- require: "o",
156
- repeat: "n"
133
+ name: "A",
134
+ detail: "The column or array of values to subtract from B (e.g. cost).",
135
+ example: "A1:A10",
136
+ require: "m",
137
+ repeat: "n",
138
+ type: "range"
157
139
  },
158
140
  {
159
- name: "offset",
160
- detail: "The number of transactions to skip, default is 0.",
161
- example: `0`,
162
- require: "o",
163
- repeat: "n"
141
+ name: "B",
142
+ detail: "The column or array of values to subtract A from (e.g. revenue).",
143
+ example: "B1:B10",
144
+ require: "m",
145
+ repeat: "n",
146
+ type: "range"
164
147
  }
165
148
  ]
166
149
  }