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

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