@fileverse-dev/formulajs 4.4.37 → 4.4.38-col-4

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/esm/index.mjs CHANGED
@@ -8102,20 +8102,32 @@ const WEEKEND_TYPES = [
8102
8102
  [6, 6]
8103
8103
  ];
8104
8104
 
8105
- const datePartition = (date) => {
8105
+ const datePartition = (date, utc = false) => {
8106
8106
  const pad = (n) => n.toString().padStart(2, "0");
8107
8107
 
8108
- const day = pad(date.getUTCDate());
8109
- const month = pad(date.getUTCMonth() + 1);
8110
- const year = date.getUTCFullYear();
8111
- const hours = pad(date.getUTCHours());
8112
- const minutes = pad(date.getUTCMinutes());
8113
- const seconds = pad(date.getUTCSeconds());
8108
+ const day = pad(utc ? date.getUTCDate() : date.getDate());
8109
+ const month = pad(
8110
+ (utc ? date.getUTCMonth() : date.getMonth()) + 1
8111
+ );
8112
+ const year = utc
8113
+ ? date.getUTCFullYear()
8114
+ : date.getFullYear();
8115
+
8116
+ const hours = pad(
8117
+ utc ? date.getUTCHours() : date.getHours()
8118
+ );
8119
+ const minutes = pad(
8120
+ utc ? date.getUTCMinutes() : date.getMinutes()
8121
+ );
8122
+ const seconds = pad(
8123
+ utc ? date.getUTCSeconds() : date.getSeconds()
8124
+ );
8114
8125
 
8115
8126
  return { day, month, year, hours, minutes, seconds };
8116
8127
  };
8117
8128
 
8118
8129
 
8130
+
8119
8131
  /**
8120
8132
  * Returns the serial number of a particular date.
8121
8133
  *
@@ -8469,7 +8481,7 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
8469
8481
 
8470
8482
  const d = new Date(ms);
8471
8483
 
8472
- const { day, month, year, hours, minutes, seconds } = datePartition(d);
8484
+ const { day, month, year, hours, minutes, seconds } = datePartition(d, true);
8473
8485
 
8474
8486
  return `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
8475
8487
  }
@@ -17683,15 +17695,16 @@ const aaveParamsSchema = objectType({
17683
17695
  category: enumType(['tokens','markets']),
17684
17696
  param1: stringType().nonempty(),
17685
17697
  param2: stringType().optional(),
17698
+ columnName: stringType().optional(),
17686
17699
  });
17687
17700
 
17688
17701
  async function AAVE() {
17689
17702
  try {
17690
17703
 
17691
- const [graphType, category, param1, param2] = argsToArray(arguments);
17704
+ const [graphType, category, param1, param2, columnName] = argsToArray(arguments);
17692
17705
 
17693
17706
 
17694
- validateParams(aaveParamsSchema, { graphType, category, param1, param2 });
17707
+ validateParams(aaveParamsSchema, { graphType, category, param1, param2, columnName });
17695
17708
 
17696
17709
  const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
17697
17710
  const url =
@@ -17708,16 +17721,25 @@ async function AAVE() {
17708
17721
  }
17709
17722
 
17710
17723
  const json = await res.json();
17724
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
17725
+
17711
17726
  if (Array.isArray(json)) {
17712
17727
  return json.map(item => {
17713
17728
  const flat = {};
17714
17729
  Object.entries(item).forEach(([k, v]) => {
17715
- if (v === null || typeof v !== 'object') flat[k] = v;
17730
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) flat[k] = v;
17716
17731
  });
17717
17732
  return flat
17718
17733
  })
17719
17734
  }
17720
- return json
17735
+ if(columnName && typeof json === 'object') {
17736
+ const data = {};
17737
+ filterColumnName.forEach(k => {
17738
+ data[k] = json[k];
17739
+ });
17740
+ return data
17741
+ }
17742
+ return json;
17721
17743
  } catch (err) {
17722
17744
  return errorMessageHandler(err, 'AAVE')
17723
17745
  }
@@ -17757,6 +17779,7 @@ const baseSchema = objectType({
17757
17779
  endTime: dateOrTimestamp.optional(),
17758
17780
  page: numberType().int().nonnegative().default(1),
17759
17781
  offset: numberType().int().nonnegative().max(MAX_PAGE_LIMIT, {message: `"offset" must be less than or equal to ${MAX_PAGE_LIMIT}`}).default(10),
17782
+ columnName: stringType().optional(),
17760
17783
  });
17761
17784
 
17762
17785
  const eoaParamsSchema = preprocessType(
@@ -17986,9 +18009,9 @@ function toTimestamp(dateStr) {
17986
18009
 
17987
18010
  async function EOA() {
17988
18011
  try {
17989
- const [addresses, category, chains, startTime, endTime, page = 1, offset = 10] =
18012
+ const [addresses, category, chains, startTime, endTime, page = 1, offset = 10, columnName = null] =
17990
18013
  argsToArray(arguments);
17991
- validateParams(eoaParamsSchema, { addresses, category, chains, startTime, endTime, page, offset });
18014
+ validateParams(eoaParamsSchema, { addresses, category, chains, startTime, endTime, page, offset, columnName });
17992
18015
 
17993
18016
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Etherscan);
17994
18017
 
@@ -18058,6 +18081,16 @@ async function EOA() {
18058
18081
  }
18059
18082
  }
18060
18083
  }
18084
+ if(columnName){
18085
+ const filterColumnName = columnName.split(',').map(s => s.trim());
18086
+ return out.map(obj =>
18087
+ Object.fromEntries(
18088
+ filterColumnName
18089
+ .filter(key => key in obj)
18090
+ .map(key => [key, obj[key]])
18091
+ )
18092
+ );
18093
+ }
18061
18094
  return out
18062
18095
  } catch (err) {
18063
18096
  return errorMessageHandler(err, 'EOA')
@@ -18070,6 +18103,7 @@ const gasSchema$1 = objectType({
18070
18103
  endDate: dateOrTimestamp.optional(),
18071
18104
  page: numberType().int().nonnegative().default(1),
18072
18105
  limit: numberType().int().nonnegative().max(MAX_PAGE_LIMIT, {message: `"limit" must be less than or equal to ${MAX_PAGE_LIMIT}`}).default(10),
18106
+ columnName: stringType().optional(),
18073
18107
  });
18074
18108
 
18075
18109
  const txnSchema$1 = objectType({
@@ -18079,6 +18113,7 @@ const txnSchema$1 = objectType({
18079
18113
  endDate: dateOrTimestamp.optional(),
18080
18114
  page: numberType().int().nonnegative().default(1),
18081
18115
  limit: numberType().int().nonnegative().max(MAX_PAGE_LIMIT, {message: `"limit" must be less than or equal to ${MAX_PAGE_LIMIT}`}).default(10),
18116
+ columnName: stringType().optional(),
18082
18117
  });
18083
18118
 
18084
18119
  const baseParamsSchema = discriminatedUnionType('type', [gasSchema$1, txnSchema$1]);
@@ -18155,11 +18190,11 @@ async function handleScanRequest({
18155
18190
 
18156
18191
  async function BASE() {
18157
18192
  try {
18158
- const [type, address, startDate, endDate, page, limit] = argsToArray(arguments);
18159
- validateParams(baseParamsSchema, { type, address, startDate, endDate, page, limit });
18193
+ const [type, address, startDate, endDate, page, limit, columnName] = argsToArray(arguments);
18194
+ validateParams(baseParamsSchema, { type, address, startDate, endDate, page, limit, columnName });
18160
18195
  const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Basescan);
18161
18196
 
18162
- return await handleScanRequest({
18197
+ const out = await handleScanRequest({
18163
18198
  type,
18164
18199
  address,
18165
18200
  startDate,
@@ -18170,7 +18205,18 @@ async function BASE() {
18170
18205
  functionName: 'BASE',
18171
18206
  chainId: CHAIN_ID_MAP.base,
18172
18207
  network: 'base'
18173
- })
18208
+ });
18209
+ if (columnName) {
18210
+ const filterColumnName = columnName.split(',').map(s => s.trim());
18211
+ return out.map(obj =>
18212
+ Object.fromEntries(
18213
+ filterColumnName
18214
+ .filter(key => key in obj)
18215
+ .map(key => [key, obj[key]])
18216
+ )
18217
+ );
18218
+ }
18219
+ return out
18174
18220
  } catch (error) {
18175
18221
  return errorMessageHandler(error, 'BASE')
18176
18222
  }
@@ -18290,6 +18336,7 @@ const derivativesSchema = objectType({
18290
18336
  category: literalType('derivatives'),
18291
18337
  param1: stringType().nonempty(),
18292
18338
  param2: anyType().optional(),
18339
+ columnName: stringType().optional(),
18293
18340
  });
18294
18341
  const coingeckoParamsSchema = discriminatedUnionType('category', [
18295
18342
  priceSchema$1,
@@ -18304,8 +18351,8 @@ const coingeckoParamsSchema = discriminatedUnionType('category', [
18304
18351
 
18305
18352
  async function COINGECKO() {
18306
18353
  try {
18307
- const [category, param1, param2] = argsToArray(arguments);
18308
- validateParams(coingeckoParamsSchema, { category, param1, param2 });
18354
+ const [category, param1, param2, columnName = null] = argsToArray(arguments);
18355
+ validateParams(coingeckoParamsSchema, { category, param1, param2, columnName });
18309
18356
 
18310
18357
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Coingecko);
18311
18358
 
@@ -18340,7 +18387,7 @@ async function COINGECKO() {
18340
18387
  break
18341
18388
  }
18342
18389
  }
18343
- const {URL: finalUrl, HEADERS} = getUrlAndHeaders({url, serviceName: 'Coingecko', headers});
18390
+ const { URL: finalUrl, HEADERS } = getUrlAndHeaders({ url, serviceName: 'Coingecko', headers });
18344
18391
 
18345
18392
  const res = await fetch(finalUrl + "?refresh=true", { headers: HEADERS });
18346
18393
  const json = await res.json();
@@ -18366,6 +18413,16 @@ async function COINGECKO() {
18366
18413
  flat[key] = value;
18367
18414
  }
18368
18415
  }
18416
+ if (columnName) {
18417
+ const filterData = {};
18418
+ const filterColumnName = columnName.split(',').map(s => s.trim());
18419
+ filterColumnName.forEach(col => {
18420
+ if (flat[col] !== undefined) {
18421
+ filterData[col] = flat[col];
18422
+ }
18423
+ });
18424
+ return filterData;
18425
+ }
18369
18426
  return flat
18370
18427
  })
18371
18428
  } catch (err) {
@@ -18375,7 +18432,8 @@ async function COINGECKO() {
18375
18432
 
18376
18433
  const categories = ['protocols','yields','dex','fees'];
18377
18434
  const defillamaParamsSchema = objectType({
18378
- category: enumType(categories)
18435
+ category: enumType(categories),
18436
+ columnName: stringType().optional(),
18379
18437
  });
18380
18438
 
18381
18439
  const CATEGORY_URLS = {
@@ -18387,8 +18445,8 @@ const CATEGORY_URLS = {
18387
18445
 
18388
18446
  async function DEFILLAMA() {
18389
18447
  try {
18390
- const [category] = argsToArray(arguments);
18391
- validateParams(defillamaParamsSchema, { category });
18448
+ const [category, columnName = null] = argsToArray(arguments);
18449
+ validateParams(defillamaParamsSchema, { category, columnName });
18392
18450
  const url = CATEGORY_URLS[category];
18393
18451
  if (!url) throw new ValidationError(`Invalid category: ${category}`)
18394
18452
  const res = await fetch(url);
@@ -18408,10 +18466,12 @@ async function DEFILLAMA() {
18408
18466
  break
18409
18467
  }
18410
18468
 
18469
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
18470
+
18411
18471
  return (Array.isArray(json) ? json : [json]).map(item => {
18412
18472
  const out = {};
18413
18473
  for (const [k, v] of Object.entries(item)) {
18414
- if (v === null || typeof v !== 'object') out[k] = v;
18474
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) out[k] = v;
18415
18475
  }
18416
18476
  return out
18417
18477
  })
@@ -18426,6 +18486,7 @@ const gasSchema = objectType({
18426
18486
  endDate: dateOrTimestamp.optional(),
18427
18487
  page: numberType().int().nonnegative().default(1),
18428
18488
  limit: numberType().int().nonnegative().max(MAX_PAGE_LIMIT, {message: `"limit" must be less than or equal to ${MAX_PAGE_LIMIT}`}).default(10),
18489
+ columnName: stringType().optional(),
18429
18490
  });
18430
18491
 
18431
18492
  const txnSchema = objectType({
@@ -18436,6 +18497,7 @@ const txnSchema = objectType({
18436
18497
  chain: enumType(['ethereum','base','gnosis']),
18437
18498
  page: numberType().int().nonnegative().default(1),
18438
18499
  limit: numberType().int().nonnegative().max(MAX_PAGE_LIMIT, {message: `"limit" must be less than or equal to ${MAX_PAGE_LIMIT}`}).default(10),
18500
+ columnName: stringType().optional(),
18439
18501
  });
18440
18502
 
18441
18503
  const etherscanParamsSchema = discriminatedUnionType('type', [gasSchema, txnSchema]);
@@ -18449,18 +18511,18 @@ const etherscanParamsSchema = discriminatedUnionType('type', [gasSchema, txnSche
18449
18511
 
18450
18512
  async function ETHERSCAN() {
18451
18513
  try {
18452
- const [type, chain, address, startDate, endDate, page = 1, limit = 10] =
18514
+ const [type, chain, address, startDate, endDate, page = 1, limit = 10, columnName = null] =
18453
18515
  argsToArray(arguments);
18454
18516
 
18455
18517
 
18456
- validateParams(etherscanParamsSchema, { type, chain, address, startDate, endDate, page, limit });
18518
+ validateParams(etherscanParamsSchema, { type, chain, address, startDate, endDate, page, limit, columnName });
18457
18519
 
18458
18520
  const chainId = CHAIN_ID_MAP[chain];
18459
18521
  if (!chainId) throw new ValidationError(`Invalid chain: ${chain}`)
18460
18522
 
18461
18523
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Etherscan);
18462
18524
 
18463
- return await handleScanRequest({
18525
+ const out = await handleScanRequest({
18464
18526
  type,
18465
18527
  address,
18466
18528
  startDate,
@@ -18471,7 +18533,18 @@ async function ETHERSCAN() {
18471
18533
  functionName: 'ETHERSCAN',
18472
18534
  chainId,
18473
18535
  network: chain,
18474
- })
18536
+ });
18537
+ if (columnName) {
18538
+ const filterColumnName = columnName.split(',').map(s => s.trim());
18539
+ return out.map(obj =>
18540
+ Object.fromEntries(
18541
+ filterColumnName
18542
+ .filter(key => key in obj)
18543
+ .map(key => [key, obj[key]])
18544
+ )
18545
+ );
18546
+ }
18547
+ return out
18475
18548
  } catch (err) {
18476
18549
  return errorMessageHandler(err, 'ETHERSCAN')
18477
18550
  }
@@ -18910,13 +18983,14 @@ const uniswapParamsSchema = objectType({
18910
18983
  category: enumType(['tokens','markets']),
18911
18984
  param1: stringType().nonempty(),
18912
18985
  param2: stringType().optional(),
18986
+ colummnName: stringType().optional(),
18913
18987
  });
18914
18988
 
18915
18989
  async function UNISWAP() {
18916
18990
  try {
18917
- const [graphType, category, param1, param2] = argsToArray(arguments);
18991
+ const [graphType, category, param1, param2, columnName] = argsToArray(arguments);
18918
18992
 
18919
- validateParams(uniswapParamsSchema, { graphType, category, param1, param2 });
18993
+ validateParams(uniswapParamsSchema, { graphType, category, param1, param2, columnName });
18920
18994
 
18921
18995
  const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
18922
18996
  const url =
@@ -18934,16 +19008,24 @@ async function UNISWAP() {
18934
19008
  }
18935
19009
 
18936
19010
  const json = await res.json();
19011
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
18937
19012
  if (Array.isArray(json)) {
18938
19013
  // flatten nested
18939
19014
  return json.map(item => {
18940
19015
  const flat = {};
18941
19016
  Object.entries(item).forEach(([k, v]) => {
18942
- if (v === null || typeof v !== 'object') flat[k] = v;
19017
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) flat[k] = v;
18943
19018
  });
18944
19019
  return flat
18945
19020
  })
18946
19021
  }
19022
+ if(columnName && typeof json === 'object') {
19023
+ const data = {};
19024
+ filterColumnName.forEach(k => {
19025
+ data[k] = json[k];
19026
+ });
19027
+ return data
19028
+ }
18947
19029
  return json
18948
19030
  } catch (err) {
18949
19031
  return errorMessageHandler(err, 'UNISWAP')
@@ -18953,6 +19035,7 @@ async function UNISWAP() {
18953
19035
  async function SMARTCONTRACT() {
18954
19036
  try {
18955
19037
  const args = argsToArray(arguments);
19038
+ console.log(args, arguments);
18956
19039
 
18957
19040
  return new Promise((resolve) => {
18958
19041
  resolve( {
@@ -29856,14 +29939,15 @@ class CirclesData {
29856
29939
  const circlesParamsSchema = objectType({
29857
29940
  functionName: enumType(['trust', 'profile', 'transactions', 'balances']),
29858
29941
  address: stringType().nonempty(),
29859
- entries: numberType().int().nonnegative().default(10)
29942
+ entries: numberType().int().nonnegative().default(10),
29943
+ columnName: stringType().optional(),
29860
29944
  });
29861
29945
 
29862
29946
  async function CIRCLES() {
29863
29947
  try {
29864
- const [functionName, address, entries] = argsToArray(arguments);
29948
+ const [functionName, address, entries, columnName] = argsToArray(arguments);
29865
29949
 
29866
- validateParams(circlesParamsSchema, { functionName, address, entries });
29950
+ validateParams(circlesParamsSchema, { functionName, address, entries, columnName });
29867
29951
 
29868
29952
  const resolved = await fromEnsNameToAddress$1.validateAndGetAddress(address);
29869
29953
  const dataClient = new CirclesData('https://rpc.aboutcircles.com');
@@ -29881,10 +29965,34 @@ async function CIRCLES() {
29881
29965
 
29882
29966
  switch (functionName) {
29883
29967
  case 'trust':
29884
- return await runOnePage(dataClient.getTrustRelations(resolved, limit))
29968
+ const dataTrust = await runOnePage(dataClient.getTrustRelations(resolved, limit));
29969
+ if (columnName) {
29970
+ const filterColumnName = columnName.split(',').map(s => s.trim());
29971
+ return dataTrust.map(obj =>
29972
+ Object.fromEntries(
29973
+ filterColumnName
29974
+ .filter(key => key in obj)
29975
+ .map(key => [key, obj[key]])
29976
+ )
29977
+ );
29978
+ } else {
29979
+ return dataTrust;
29980
+ }
29885
29981
 
29886
29982
  case 'transactions':
29887
- return await runOnePage(dataClient.getTransactionHistory(resolved, limit))
29983
+ const data = await runOnePage(dataClient.getTransactionHistory(resolved, limit));
29984
+ if (columnName) {
29985
+ const filterColumnName = columnName.split(',').map(s => s.trim());
29986
+ return data.map(obj =>
29987
+ Object.fromEntries(
29988
+ filterColumnName
29989
+ .filter(key => key in obj)
29990
+ .map(key => [key, obj[key]])
29991
+ )
29992
+ );
29993
+ } else {
29994
+ return data;
29995
+ }
29888
29996
 
29889
29997
  case 'profile': {
29890
29998
  const res = await dataClient.getAvatarInfo(resolved);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/formulajs",
3
- "version": "4.4.37",
3
+ "version": "4.4.38-col-4",
4
4
  "description": "JavaScript implementation of most Microsoft Excel formula functions",
5
5
  "author": "Formulajs",
6
6
  "publishConfig": {