@fileverse-dev/formulajs 4.4.11-mod-19-patch-4 → 4.4.11-mod-18-patch-20

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,17 +73,9 @@ 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
-
83
76
  var date = /*#__PURE__*/Object.freeze({
84
77
  __proto__: null,
85
78
  dateToSerial: dateToSerial,
86
- formatDate: formatDate,
87
79
  get returnSerial () { return returnSerial; },
88
80
  serialToDate: serialToDate,
89
81
  useDate: useDate,
@@ -557,54 +549,16 @@ function parseDate(date) {
557
549
  }
558
550
 
559
551
  if (typeof date === 'string') {
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
- }
574
-
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
- }
552
+ date = /(\d{4})-(\d\d?)-(\d\d?)$/.test(date) ? new Date(date + 'T00:00:00.000') : new Date(date);
582
553
 
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
554
+ if (!isNaN(date)) {
555
+ return date
600
556
  }
601
557
  }
602
558
 
603
559
  return value
604
560
  }
605
561
 
606
-
607
-
608
562
  function parseDateArray(arr) {
609
563
  let len = arr.length;
610
564
  let parsed;
@@ -5228,6 +5182,76 @@ Z.TEST = (array, x, sigma) => {
5228
5182
  return 1 - NORM.S.DIST((AVERAGE(array) - x) / (sigma / Math.sqrt(n)), true)
5229
5183
  };
5230
5184
 
5185
+ function PNL() {
5186
+ const [A, B] = argsToArray(arguments);
5187
+
5188
+ const toNumberOrThrow = (val) => {
5189
+ const num = Number(val);
5190
+ if (isNaN(num)) throw new Error(`Invalid number value: ${val}`);
5191
+ return num;
5192
+ };
5193
+
5194
+ // Single numbers
5195
+ if (typeof A === "number" && typeof B === "number") {
5196
+ return A - B;
5197
+ }
5198
+
5199
+ // 1D arrays
5200
+ if (Array.isArray(A) && Array.isArray(B) && typeof A[0] !== "object") {
5201
+ const maxLen = Math.max(A.length, B.length);
5202
+ let total = 0;
5203
+ for (let i = 0; i < maxLen; i++) {
5204
+ const aVal = i < A.length ? toNumberOrThrow(A[i]) : 0;
5205
+ const bVal = i < B.length ? toNumberOrThrow(B[i]) : 0;
5206
+ total += aVal - bVal;
5207
+ }
5208
+ return total;
5209
+ }
5210
+
5211
+ // 2D arrays
5212
+ if (Array.isArray(A[0]) && typeof A[0][0] !== "object") {
5213
+ let total = 0;
5214
+ const maxRows = Math.max(A.length, B.length);
5215
+ for (let i = 0; i < maxRows; i++) {
5216
+ const rowA = A[i] || [];
5217
+ const rowB = B[i] || [];
5218
+ const maxCols = Math.max(rowA.length, rowB.length);
5219
+ for (let j = 0; j < maxCols; j++) {
5220
+ const aVal = j < rowA.length ? toNumberOrThrow(rowA[j]) : 0;
5221
+ const bVal = j < rowB.length ? toNumberOrThrow(rowB[j]) : 0;
5222
+ total += aVal - bVal;
5223
+ }
5224
+ }
5225
+ return total;
5226
+ }
5227
+
5228
+ // 3D arrays
5229
+ if (Array.isArray(A[0][0])) {
5230
+ let total = 0;
5231
+ const maxX = Math.max(A.length, B.length);
5232
+ for (let i = 0; i < maxX; i++) {
5233
+ const matA = A[i] || [];
5234
+ const matB = B[i] || [];
5235
+ const maxY = Math.max(matA.length, matB.length);
5236
+ for (let j = 0; j < maxY; j++) {
5237
+ const rowA = matA[j] || [];
5238
+ const rowB = matB[j] || [];
5239
+ const maxZ = Math.max(rowA.length, rowB.length);
5240
+ for (let k = 0; k < maxZ; k++) {
5241
+ const aVal = k < rowA.length ? toNumberOrThrow(rowA[k]) : 0;
5242
+ const bVal = k < rowB.length ? toNumberOrThrow(rowB[k]) : 0;
5243
+ total += aVal - bVal;
5244
+ }
5245
+ }
5246
+ }
5247
+ return total;
5248
+ }
5249
+
5250
+ throw new Error("Unsupported or mismatched structure");
5251
+ }
5252
+
5253
+
5254
+
5231
5255
  /**
5232
5256
  * Returns the absolute value of a number.
5233
5257
  *
@@ -7802,9 +7826,8 @@ function DAYS(end_date, start_date) {
7802
7826
  if (start_date instanceof Error) {
7803
7827
  return start_date
7804
7828
  }
7805
- console.log({x: formatDate(startOfDay(end_date)), y: formatDate(startOfDay(start_date)) });
7806
7829
 
7807
- return formatDate(startOfDay(end_date)) - formatDate(startOfDay(start_date))
7830
+ return dateToSerial(startOfDay(end_date)) - dateToSerial(startOfDay(start_date))
7808
7831
  }
7809
7832
 
7810
7833
  /**
@@ -8119,8 +8142,6 @@ NETWORKDAYS.INTL = (start_date, end_date, weekend, holidays) => {
8119
8142
  return total
8120
8143
  };
8121
8144
 
8122
- const NETWORKDAYS_INTL = NETWORKDAYS.INTL;
8123
-
8124
8145
  /**
8125
8146
  * Returns the serial number of the current date and time.
8126
8147
  *
@@ -8173,14 +8194,9 @@ function TIME(hour, minute, second) {
8173
8194
  return num
8174
8195
  }
8175
8196
 
8176
- const hh = String(hour).padStart(2, '0');
8177
- const mm = String(minute).padStart(2, '0');
8178
- const ss = String(second).padStart(2, '0');
8179
-
8180
- return `${hh}:${mm}:${ss}`
8197
+ return (3600 * hour + 60 * minute + second) / 86400
8181
8198
  }
8182
8199
 
8183
-
8184
8200
  /**
8185
8201
  * Converts a time in the form of text to a serial number.
8186
8202
  *
@@ -8208,7 +8224,7 @@ function TIMEVALUE(time_text) {
8208
8224
  */
8209
8225
  function TODAY() {
8210
8226
  const today = startOfDay(new Date());
8211
- return formatDate(today)
8227
+ return returnSerial ? dateToSerial(today) : today
8212
8228
  }
8213
8229
 
8214
8230
  /**
@@ -8282,11 +8298,6 @@ function WORKDAY(start_date, days, holidays) {
8282
8298
  return WORKDAY.INTL(start_date, days, 1, holidays)
8283
8299
  }
8284
8300
 
8285
- function ISDATE(value) {
8286
- const parsed = parseDate(value);
8287
- return !(parsed instanceof Error)
8288
- }
8289
-
8290
8301
  /**
8291
8302
  * 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.
8292
8303
  *
@@ -8371,11 +8382,9 @@ WORKDAY.INTL = (start_date, days, weekend, holidays) => {
8371
8382
  return value
8372
8383
  }
8373
8384
 
8374
- return formatDate(start_date)
8385
+ return start_date
8375
8386
  };
8376
8387
 
8377
- const WORKDAY_INTL = WORKDAY.INTL;
8378
-
8379
8388
  /**
8380
8389
  * Converts a serial number to a year.
8381
8390
  *
@@ -13015,13 +13024,19 @@ function SWITCH() {
13015
13024
  const SERVICE_API_KEY = {
13016
13025
  Etherscan: "ETHERSCAN_API_KEY",
13017
13026
  Coingecko: "COINGECKO_API_KEY",
13027
+ Safe: "SAFE_API_KEY",
13018
13028
  };
13019
13029
 
13020
13030
  const CHAIN_ID_MAP = {
13021
- ethereum: 1,
13022
- gnosis: 100,
13023
- base: 8453,
13024
- };
13031
+ ethereum: 1,
13032
+ gnosis: 100,
13033
+ base: 8453,
13034
+ };
13035
+
13036
+ const SAFE_CHAIN_MAP = {
13037
+ ethereum: 'eth',
13038
+ gnosis: 'gno',
13039
+ };
13025
13040
 
13026
13041
  const fromTimeStampToBlock = async (timestamp, chain, apiKey) => {
13027
13042
  if(!timestamp || !chain || !apiKey) return
@@ -13092,7 +13107,7 @@ async function GETPRICE(token, vs_currencies) {
13092
13107
  }
13093
13108
  }
13094
13109
 
13095
- async function EOA(address, categories, chain, startTime, endTime) {
13110
+ async function OX(address, categories, chain, startTime, endTime) {
13096
13111
  const API_KEYS = {
13097
13112
  ethereum: window.localStorage.getItem(SERVICE_API_KEY.Etherscan),
13098
13113
  gnosis: window.localStorage.getItem(SERVICE_API_KEY.Gnosisscan),
@@ -13104,12 +13119,12 @@ async function EOA(address, categories, chain, startTime, endTime) {
13104
13119
 
13105
13120
  let action = '';
13106
13121
  if (categories === 'txns') action = 'account.txlist';
13107
- else {action = 'account.balance';} let timeQuery = '';
13108
- if(!isNaN(startTime) && !isNaN(endTime)){
13109
- const startBlock = await fromTimeStampToBlock(startTime, chain, apiKey);
13110
- const endBlock = await fromTimeStampToBlock(endTime, chain, apiKey);
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);
13111
13126
  timeQuery = `&startblock=${startBlock}&endblock=${endBlock}`;
13112
- } else if(categories === 'balance') {
13127
+ } else if (categories === 'balance') {
13113
13128
  timeQuery = `&tag=latest`;
13114
13129
  } else {
13115
13130
  throw new Error('Start and End Time is required for querying transaction list ')
@@ -13130,81 +13145,46 @@ async function EOA(address, categories, chain, startTime, endTime) {
13130
13145
  }
13131
13146
 
13132
13147
 
13133
- function PnL() {
13134
- const [A, B] = argsToArray(arguments);
13148
+ async function FLVURL(token, vs_currencies) {
13149
+ return new Promise((resolve) => {
13150
+ setTimeout(() => {
13151
+ resolve([{ "Yoo": "gotcha" }]);
13152
+ }, 10000);
13153
+ });
13154
+ }
13135
13155
 
13136
- const toNumberOrThrow = (val) => {
13137
- const num = Number(val);
13138
- if (isNaN(num)) throw new Error(`Invalid number value: ${val}`);
13139
- return num;
13140
- };
13156
+ async function SAFE(address, utility, chain, limit, offset) {
13141
13157
 
13142
- // Single numbers
13143
- if (typeof A === "number" && typeof B === "number") {
13144
- return A - B;
13145
- }
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';
13146
13161
 
13147
- // 1D arrays
13148
- if (Array.isArray(A) && Array.isArray(B) && typeof A[0] !== "object") {
13149
- const maxLen = Math.max(A.length, B.length);
13150
- let total = 0;
13151
- for (let i = 0; i < maxLen; i++) {
13152
- const aVal = i < A.length ? toNumberOrThrow(A[i]) : 0;
13153
- const bVal = i < B.length ? toNumberOrThrow(B[i]) : 0;
13154
- total += aVal - bVal;
13155
- }
13156
- return total;
13157
- }
13162
+ const apiKey = window.localStorage.getItem(SERVICE_API_KEY.Safe);
13163
+ const chainIdentifier = SAFE_CHAIN_MAP[chain];
13158
13164
 
13159
- // 2D arrays
13160
- if (Array.isArray(A[0]) && typeof A[0][0] !== "object") {
13161
- let total = 0;
13162
- const maxRows = Math.max(A.length, B.length);
13163
- for (let i = 0; i < maxRows; i++) {
13164
- const rowA = A[i] || [];
13165
- const rowB = B[i] || [];
13166
- const maxCols = Math.max(rowA.length, rowB.length);
13167
- for (let j = 0; j < maxCols; j++) {
13168
- const aVal = j < rowA.length ? toNumberOrThrow(rowA[j]) : 0;
13169
- const bVal = j < rowB.length ? toNumberOrThrow(rowB[j]) : 0;
13170
- total += aVal - bVal;
13171
- }
13172
- }
13173
- return total;
13174
- }
13165
+ if (!apiKey) return `${SERVICE_API_KEY.Safe}_MISSING`;
13166
+ if (!chainIdentifier) return 'CHAIN IS NOT SUPPORTED';
13175
13167
 
13176
- // 3D arrays
13177
- if (Array.isArray(A[0][0])) {
13178
- let total = 0;
13179
- const maxX = Math.max(A.length, B.length);
13180
- for (let i = 0; i < maxX; i++) {
13181
- const matA = A[i] || [];
13182
- const matB = B[i] || [];
13183
- const maxY = Math.max(matA.length, matB.length);
13184
- for (let j = 0; j < maxY; j++) {
13185
- const rowA = matA[j] || [];
13186
- const rowB = matB[j] || [];
13187
- const maxZ = Math.max(rowA.length, rowB.length);
13188
- for (let k = 0; k < maxZ; k++) {
13189
- const aVal = k < rowA.length ? toNumberOrThrow(rowA[k]) : 0;
13190
- const bVal = k < rowB.length ? toNumberOrThrow(rowB[k]) : 0;
13191
- total += aVal - bVal;
13192
- }
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
+ },
13193
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";
13194
13181
  }
13195
- return total;
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";
13196
13187
  }
13197
-
13198
- throw new Error("Unsupported or mismatched structure");
13199
- }
13200
-
13201
-
13202
- async function FLVURL(token, vs_currencies) {
13203
- return new Promise((resolve) => {
13204
- setTimeout(() => {
13205
- resolve([{"Yoo": "gotcha"}]);
13206
- }, 10000);
13207
- });
13208
13188
  }
13209
13189
 
13210
13190
  const utils = { errors, symbols, date };
@@ -13321,7 +13301,6 @@ exports.DVAR = DVAR;
13321
13301
  exports.DVARP = DVARP;
13322
13302
  exports.EDATE = EDATE;
13323
13303
  exports.EFFECT = EFFECT;
13324
- exports.EOA = EOA;
13325
13304
  exports.EOMONTH = EOMONTH;
13326
13305
  exports.ERF = ERF;
13327
13306
  exports.ERFC = ERFC;
@@ -13409,7 +13388,6 @@ exports.INTERCEPT = INTERCEPT;
13409
13388
  exports.IPMT = IPMT;
13410
13389
  exports.IRR = IRR;
13411
13390
  exports.ISBLANK = ISBLANK;
13412
- exports.ISDATE = ISDATE;
13413
13391
  exports.ISERR = ISERR;
13414
13392
  exports.ISERROR = ISERROR;
13415
13393
  exports.ISEVEN = ISEVEN;
@@ -13464,7 +13442,6 @@ exports.NEGBINOM = NEGBINOM;
13464
13442
  exports.NEGBINOMDIST = NEGBINOMDIST;
13465
13443
  exports.NETWORKDAYS = NETWORKDAYS;
13466
13444
  exports.NETWORKDAYSINTL = NETWORKDAYSINTL;
13467
- exports.NETWORKDAYS_INTL = NETWORKDAYS_INTL;
13468
13445
  exports.NOMINAL = NOMINAL;
13469
13446
  exports.NORM = NORM;
13470
13447
  exports.NORMDIST = NORMDIST;
@@ -13481,6 +13458,7 @@ exports.OCT2DEC = OCT2DEC;
13481
13458
  exports.OCT2HEX = OCT2HEX;
13482
13459
  exports.ODD = ODD;
13483
13460
  exports.OR = OR;
13461
+ exports.OX = OX;
13484
13462
  exports.PDURATION = PDURATION;
13485
13463
  exports.PEARSON = PEARSON;
13486
13464
  exports.PERCENTILE = PERCENTILE;
@@ -13494,6 +13472,7 @@ exports.PERMUTATIONA = PERMUTATIONA;
13494
13472
  exports.PHI = PHI;
13495
13473
  exports.PI = PI;
13496
13474
  exports.PMT = PMT;
13475
+ exports.PNL = PNL;
13497
13476
  exports.POISSON = POISSON;
13498
13477
  exports.POISSONDIST = POISSONDIST;
13499
13478
  exports.POWER = POWER;
@@ -13503,7 +13482,6 @@ exports.PROB = PROB;
13503
13482
  exports.PRODUCT = PRODUCT;
13504
13483
  exports.PROPER = PROPER;
13505
13484
  exports.PV = PV;
13506
- exports.PnL = PnL;
13507
13485
  exports.QUARTILE = QUARTILE;
13508
13486
  exports.QUARTILEEXC = QUARTILEEXC;
13509
13487
  exports.QUARTILEINC = QUARTILEINC;
@@ -13526,6 +13504,7 @@ exports.ROW = ROW;
13526
13504
  exports.ROWS = ROWS;
13527
13505
  exports.RRI = RRI;
13528
13506
  exports.RSQ = RSQ;
13507
+ exports.SAFE = SAFE;
13529
13508
  exports.SEARCH = SEARCH;
13530
13509
  exports.SEC = SEC;
13531
13510
  exports.SECH = SECH;
@@ -13600,7 +13579,6 @@ exports.WEIBULL = WEIBULL;
13600
13579
  exports.WEIBULLDIST = WEIBULLDIST;
13601
13580
  exports.WORKDAY = WORKDAY;
13602
13581
  exports.WORKDAYINTL = WORKDAYINTL;
13603
- exports.WORKDAY_INTL = WORKDAY_INTL;
13604
13582
  exports.XIRR = XIRR;
13605
13583
  exports.XNPV = XNPV;
13606
13584
  exports.XOR = XOR;
@@ -1,7 +1,8 @@
1
1
  // src/crypto-constants.js
2
2
  var SERVICE_API_KEY = {
3
3
  Etherscan: "ETHERSCAN_API_KEY",
4
- Coingecko: "COINGECKO_API_KEY"
4
+ Coingecko: "COINGECKO_API_KEY",
5
+ Safe: "SAFE_API_KEY"
5
6
  };
6
7
  var FUNCTION_LOCALE = [
7
8
  {
@@ -43,7 +44,7 @@ var FUNCTION_LOCALE = [
43
44
  LOGO: "https://raw.githubusercontent.com/mritunjayz/github-storage/refs/heads/main/1689874988430.jpeg",
44
45
  BRAND_COLOR: "#F6F7F8",
45
46
  BRAND_SECONDARY_COLOR: "#21325B",
46
- n: "EOA",
47
+ n: "0x",
47
48
  t: 20,
48
49
  d: "Fetches address data like transactions, balances, or portfolio info from multiple supported chains.",
49
50
  a: "Dynamically queries blockchain data such as transactions, balances by resolving time ranges to block ranges.",
@@ -124,26 +125,42 @@ var FUNCTION_LOCALE = [
124
125
  ]
125
126
  },
126
127
  {
127
- n: "PnL",
128
+ n: "SAFE",
128
129
  t: 20,
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.",
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.",
131
132
  p: [
132
133
  {
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"
134
+ name: "address",
135
+ detail: "The address to query, in hexadecimal format.",
136
+ example: `"0xc5102fE9359FD9a28f877a67E36B0F050d81a3CC"`,
137
+ require: "m"
139
138
  },
140
139
  {
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"
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"
157
+ },
158
+ {
159
+ name: "offset",
160
+ detail: "The number of transactions to skip, default is 0.",
161
+ example: `0`,
162
+ require: "o",
163
+ repeat: "n"
147
164
  }
148
165
  ]
149
166
  }