@fileverse-dev/formulajs 4.4.11-mod-20 → 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,46 +549,10 @@ 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
 
@@ -5226,6 +5182,76 @@ Z.TEST = (array, x, sigma) => {
5226
5182
  return 1 - NORM.S.DIST((AVERAGE(array) - x) / (sigma / Math.sqrt(n)), true)
5227
5183
  };
5228
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
+
5229
5255
  /**
5230
5256
  * Returns the absolute value of a number.
5231
5257
  *
@@ -7800,9 +7826,8 @@ function DAYS(end_date, start_date) {
7800
7826
  if (start_date instanceof Error) {
7801
7827
  return start_date
7802
7828
  }
7803
- console.log({x: formatDate(startOfDay(end_date)), y: formatDate(startOfDay(start_date)) });
7804
7829
 
7805
- return formatDate(startOfDay(end_date)) - formatDate(startOfDay(start_date))
7830
+ return dateToSerial(startOfDay(end_date)) - dateToSerial(startOfDay(start_date))
7806
7831
  }
7807
7832
 
7808
7833
  /**
@@ -8117,8 +8142,6 @@ NETWORKDAYS.INTL = (start_date, end_date, weekend, holidays) => {
8117
8142
  return total
8118
8143
  };
8119
8144
 
8120
- const NETWORKDAYS_INTL = NETWORKDAYS.INTL;
8121
-
8122
8145
  /**
8123
8146
  * Returns the serial number of the current date and time.
8124
8147
  *
@@ -8171,14 +8194,9 @@ function TIME(hour, minute, second) {
8171
8194
  return num
8172
8195
  }
8173
8196
 
8174
- const hh = String(hour).padStart(2, '0');
8175
- const mm = String(minute).padStart(2, '0');
8176
- const ss = String(second).padStart(2, '0');
8177
-
8178
- return `${hh}:${mm}:${ss}`
8197
+ return (3600 * hour + 60 * minute + second) / 86400
8179
8198
  }
8180
8199
 
8181
-
8182
8200
  /**
8183
8201
  * Converts a time in the form of text to a serial number.
8184
8202
  *
@@ -8206,7 +8224,7 @@ function TIMEVALUE(time_text) {
8206
8224
  */
8207
8225
  function TODAY() {
8208
8226
  const today = startOfDay(new Date());
8209
- return formatDate(today)
8227
+ return returnSerial ? dateToSerial(today) : today
8210
8228
  }
8211
8229
 
8212
8230
  /**
@@ -8280,11 +8298,6 @@ function WORKDAY(start_date, days, holidays) {
8280
8298
  return WORKDAY.INTL(start_date, days, 1, holidays)
8281
8299
  }
8282
8300
 
8283
- function ISDATE(value) {
8284
- const parsed = parseDate(value);
8285
- return !(parsed instanceof Error)
8286
- }
8287
-
8288
8301
  /**
8289
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.
8290
8303
  *
@@ -8369,11 +8382,9 @@ WORKDAY.INTL = (start_date, days, weekend, holidays) => {
8369
8382
  return value
8370
8383
  }
8371
8384
 
8372
- return formatDate(start_date)
8385
+ return start_date
8373
8386
  };
8374
8387
 
8375
- const WORKDAY_INTL = WORKDAY.INTL;
8376
-
8377
8388
  /**
8378
8389
  * Converts a serial number to a year.
8379
8390
  *
@@ -13013,13 +13024,19 @@ function SWITCH() {
13013
13024
  const SERVICE_API_KEY = {
13014
13025
  Etherscan: "ETHERSCAN_API_KEY",
13015
13026
  Coingecko: "COINGECKO_API_KEY",
13027
+ Safe: "SAFE_API_KEY",
13016
13028
  };
13017
13029
 
13018
13030
  const CHAIN_ID_MAP = {
13019
- ethereum: 1,
13020
- gnosis: 100,
13021
- base: 8453,
13022
- };
13031
+ ethereum: 1,
13032
+ gnosis: 100,
13033
+ base: 8453,
13034
+ };
13035
+
13036
+ const SAFE_CHAIN_MAP = {
13037
+ ethereum: 'eth',
13038
+ gnosis: 'gno',
13039
+ };
13023
13040
 
13024
13041
  const fromTimeStampToBlock = async (timestamp, chain, apiKey) => {
13025
13042
  if(!timestamp || !chain || !apiKey) return
@@ -13090,7 +13107,7 @@ async function GETPRICE(token, vs_currencies) {
13090
13107
  }
13091
13108
  }
13092
13109
 
13093
- async function EOA(address, categories, chain, startTime, endTime) {
13110
+ async function OX(address, categories, chain, startTime, endTime) {
13094
13111
  const API_KEYS = {
13095
13112
  ethereum: window.localStorage.getItem(SERVICE_API_KEY.Etherscan),
13096
13113
  gnosis: window.localStorage.getItem(SERVICE_API_KEY.Gnosisscan),
@@ -13102,12 +13119,12 @@ async function EOA(address, categories, chain, startTime, endTime) {
13102
13119
 
13103
13120
  let action = '';
13104
13121
  if (categories === 'txns') action = 'account.txlist';
13105
- else {action = 'account.balance';} let timeQuery = '';
13106
- if(!isNaN(startTime) && !isNaN(endTime)){
13107
- const startBlock = await fromTimeStampToBlock(startTime, chain, apiKey);
13108
- 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);
13109
13126
  timeQuery = `&startblock=${startBlock}&endblock=${endBlock}`;
13110
- } else if(categories === 'balance') {
13127
+ } else if (categories === 'balance') {
13111
13128
  timeQuery = `&tag=latest`;
13112
13129
  } else {
13113
13130
  throw new Error('Start and End Time is required for querying transaction list ')
@@ -13128,81 +13145,46 @@ async function EOA(address, categories, chain, startTime, endTime) {
13128
13145
  }
13129
13146
 
13130
13147
 
13131
- function PNL() {
13132
- 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
+ }
13133
13155
 
13134
- const toNumberOrThrow = (val) => {
13135
- const num = Number(val);
13136
- if (isNaN(num)) throw new Error(`Invalid number value: ${val}`);
13137
- return num;
13138
- };
13156
+ async function SAFE(address, utility, chain, limit, offset) {
13139
13157
 
13140
- // Single numbers
13141
- if (typeof A === "number" && typeof B === "number") {
13142
- return A - B;
13143
- }
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';
13144
13161
 
13145
- // 1D arrays
13146
- if (Array.isArray(A) && Array.isArray(B) && typeof A[0] !== "object") {
13147
- const maxLen = Math.max(A.length, B.length);
13148
- let total = 0;
13149
- for (let i = 0; i < maxLen; i++) {
13150
- const aVal = i < A.length ? toNumberOrThrow(A[i]) : 0;
13151
- const bVal = i < B.length ? toNumberOrThrow(B[i]) : 0;
13152
- total += aVal - bVal;
13153
- }
13154
- return total;
13155
- }
13162
+ const apiKey = window.localStorage.getItem(SERVICE_API_KEY.Safe);
13163
+ const chainIdentifier = SAFE_CHAIN_MAP[chain];
13156
13164
 
13157
- // 2D arrays
13158
- if (Array.isArray(A[0]) && typeof A[0][0] !== "object") {
13159
- let total = 0;
13160
- const maxRows = Math.max(A.length, B.length);
13161
- for (let i = 0; i < maxRows; i++) {
13162
- const rowA = A[i] || [];
13163
- const rowB = B[i] || [];
13164
- const maxCols = Math.max(rowA.length, rowB.length);
13165
- for (let j = 0; j < maxCols; j++) {
13166
- const aVal = j < rowA.length ? toNumberOrThrow(rowA[j]) : 0;
13167
- const bVal = j < rowB.length ? toNumberOrThrow(rowB[j]) : 0;
13168
- total += aVal - bVal;
13169
- }
13170
- }
13171
- return total;
13172
- }
13165
+ if (!apiKey) return `${SERVICE_API_KEY.Safe}_MISSING`;
13166
+ if (!chainIdentifier) return 'CHAIN IS NOT SUPPORTED';
13173
13167
 
13174
- // 3D arrays
13175
- if (Array.isArray(A[0][0])) {
13176
- let total = 0;
13177
- const maxX = Math.max(A.length, B.length);
13178
- for (let i = 0; i < maxX; i++) {
13179
- const matA = A[i] || [];
13180
- const matB = B[i] || [];
13181
- const maxY = Math.max(matA.length, matB.length);
13182
- for (let j = 0; j < maxY; j++) {
13183
- const rowA = matA[j] || [];
13184
- const rowB = matB[j] || [];
13185
- const maxZ = Math.max(rowA.length, rowB.length);
13186
- for (let k = 0; k < maxZ; k++) {
13187
- const aVal = k < rowA.length ? toNumberOrThrow(rowA[k]) : 0;
13188
- const bVal = k < rowB.length ? toNumberOrThrow(rowB[k]) : 0;
13189
- total += aVal - bVal;
13190
- }
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
+ },
13191
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";
13192
13181
  }
13193
- 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";
13194
13187
  }
13195
-
13196
- throw new Error("Unsupported or mismatched structure");
13197
- }
13198
-
13199
-
13200
- async function FLVURL(token, vs_currencies) {
13201
- return new Promise((resolve) => {
13202
- setTimeout(() => {
13203
- resolve([{"Yoo": "gotcha"}]);
13204
- }, 10000);
13205
- });
13206
13188
  }
13207
13189
 
13208
13190
  const utils = { errors, symbols, date };
@@ -13319,7 +13301,6 @@ exports.DVAR = DVAR;
13319
13301
  exports.DVARP = DVARP;
13320
13302
  exports.EDATE = EDATE;
13321
13303
  exports.EFFECT = EFFECT;
13322
- exports.EOA = EOA;
13323
13304
  exports.EOMONTH = EOMONTH;
13324
13305
  exports.ERF = ERF;
13325
13306
  exports.ERFC = ERFC;
@@ -13407,7 +13388,6 @@ exports.INTERCEPT = INTERCEPT;
13407
13388
  exports.IPMT = IPMT;
13408
13389
  exports.IRR = IRR;
13409
13390
  exports.ISBLANK = ISBLANK;
13410
- exports.ISDATE = ISDATE;
13411
13391
  exports.ISERR = ISERR;
13412
13392
  exports.ISERROR = ISERROR;
13413
13393
  exports.ISEVEN = ISEVEN;
@@ -13462,7 +13442,6 @@ exports.NEGBINOM = NEGBINOM;
13462
13442
  exports.NEGBINOMDIST = NEGBINOMDIST;
13463
13443
  exports.NETWORKDAYS = NETWORKDAYS;
13464
13444
  exports.NETWORKDAYSINTL = NETWORKDAYSINTL;
13465
- exports.NETWORKDAYS_INTL = NETWORKDAYS_INTL;
13466
13445
  exports.NOMINAL = NOMINAL;
13467
13446
  exports.NORM = NORM;
13468
13447
  exports.NORMDIST = NORMDIST;
@@ -13479,6 +13458,7 @@ exports.OCT2DEC = OCT2DEC;
13479
13458
  exports.OCT2HEX = OCT2HEX;
13480
13459
  exports.ODD = ODD;
13481
13460
  exports.OR = OR;
13461
+ exports.OX = OX;
13482
13462
  exports.PDURATION = PDURATION;
13483
13463
  exports.PEARSON = PEARSON;
13484
13464
  exports.PERCENTILE = PERCENTILE;
@@ -13524,6 +13504,7 @@ exports.ROW = ROW;
13524
13504
  exports.ROWS = ROWS;
13525
13505
  exports.RRI = RRI;
13526
13506
  exports.RSQ = RSQ;
13507
+ exports.SAFE = SAFE;
13527
13508
  exports.SEARCH = SEARCH;
13528
13509
  exports.SEC = SEC;
13529
13510
  exports.SECH = SECH;
@@ -13598,7 +13579,6 @@ exports.WEIBULL = WEIBULL;
13598
13579
  exports.WEIBULLDIST = WEIBULLDIST;
13599
13580
  exports.WORKDAY = WORKDAY;
13600
13581
  exports.WORKDAYINTL = WORKDAYINTL;
13601
- exports.WORKDAY_INTL = WORKDAY_INTL;
13602
13582
  exports.XIRR = XIRR;
13603
13583
  exports.XNPV = XNPV;
13604
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
  }