@fileverse-dev/formulajs 4.4.36 → 4.4.38-col-3

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,18 +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.getDate());
8109
- const month = pad(date.getMonth() + 1);
8110
- const year = date.getFullYear();
8111
- const hours = pad(date.getHours());
8112
- const minutes = pad(date.getMinutes());
8113
- const seconds = pad(date.getSeconds());
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
+ );
8125
+
8114
8126
  return { day, month, year, hours, minutes, seconds };
8115
8127
  };
8116
8128
 
8129
+
8130
+
8117
8131
  /**
8118
8132
  * Returns the serial number of a particular date.
8119
8133
  *
@@ -8467,7 +8481,7 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
8467
8481
 
8468
8482
  const d = new Date(ms);
8469
8483
 
8470
- const { day, month, year, hours, minutes, seconds } = datePartition(d);
8484
+ const { day, month, year, hours, minutes, seconds } = datePartition(d, true);
8471
8485
 
8472
8486
  return `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
8473
8487
  }
@@ -17681,15 +17695,16 @@ const aaveParamsSchema = objectType({
17681
17695
  category: enumType(['tokens','markets']),
17682
17696
  param1: stringType().nonempty(),
17683
17697
  param2: stringType().optional(),
17698
+ columnName: stringType().optional(),
17684
17699
  });
17685
17700
 
17686
17701
  async function AAVE() {
17687
17702
  try {
17688
17703
 
17689
- const [graphType, category, param1, param2] = argsToArray(arguments);
17704
+ const [graphType, category, param1, param2, columnName] = argsToArray(arguments);
17690
17705
 
17691
17706
 
17692
- validateParams(aaveParamsSchema, { graphType, category, param1, param2 });
17707
+ validateParams(aaveParamsSchema, { graphType, category, param1, param2, columnName });
17693
17708
 
17694
17709
  const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
17695
17710
  const url =
@@ -17706,16 +17721,25 @@ async function AAVE() {
17706
17721
  }
17707
17722
 
17708
17723
  const json = await res.json();
17724
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
17725
+
17709
17726
  if (Array.isArray(json)) {
17710
17727
  return json.map(item => {
17711
17728
  const flat = {};
17712
17729
  Object.entries(item).forEach(([k, v]) => {
17713
- if (v === null || typeof v !== 'object') flat[k] = v;
17730
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) flat[k] = v;
17714
17731
  });
17715
17732
  return flat
17716
17733
  })
17717
17734
  }
17718
- 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;
17719
17743
  } catch (err) {
17720
17744
  return errorMessageHandler(err, 'AAVE')
17721
17745
  }
@@ -17755,6 +17779,7 @@ const baseSchema = objectType({
17755
17779
  endTime: dateOrTimestamp.optional(),
17756
17780
  page: numberType().int().nonnegative().default(1),
17757
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(),
17758
17783
  });
17759
17784
 
17760
17785
  const eoaParamsSchema = preprocessType(
@@ -17984,9 +18009,9 @@ function toTimestamp(dateStr) {
17984
18009
 
17985
18010
  async function EOA() {
17986
18011
  try {
17987
- const [addresses, category, chains, startTime, endTime, page = 1, offset = 10] =
18012
+ const [addresses, category, chains, startTime, endTime, page = 1, offset = 10, columnName = null] =
17988
18013
  argsToArray(arguments);
17989
- validateParams(eoaParamsSchema, { addresses, category, chains, startTime, endTime, page, offset });
18014
+ validateParams(eoaParamsSchema, { addresses, category, chains, startTime, endTime, page, offset, columnName });
17990
18015
 
17991
18016
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Etherscan);
17992
18017
 
@@ -18056,6 +18081,16 @@ async function EOA() {
18056
18081
  }
18057
18082
  }
18058
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
+ }
18059
18094
  return out
18060
18095
  } catch (err) {
18061
18096
  return errorMessageHandler(err, 'EOA')
@@ -18068,6 +18103,7 @@ const gasSchema$1 = objectType({
18068
18103
  endDate: dateOrTimestamp.optional(),
18069
18104
  page: numberType().int().nonnegative().default(1),
18070
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(),
18071
18107
  });
18072
18108
 
18073
18109
  const txnSchema$1 = objectType({
@@ -18077,6 +18113,7 @@ const txnSchema$1 = objectType({
18077
18113
  endDate: dateOrTimestamp.optional(),
18078
18114
  page: numberType().int().nonnegative().default(1),
18079
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(),
18080
18117
  });
18081
18118
 
18082
18119
  const baseParamsSchema = discriminatedUnionType('type', [gasSchema$1, txnSchema$1]);
@@ -18153,11 +18190,11 @@ async function handleScanRequest({
18153
18190
 
18154
18191
  async function BASE() {
18155
18192
  try {
18156
- const [type, address, startDate, endDate, page, limit] = argsToArray(arguments);
18157
- 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 });
18158
18195
  const API_KEY = window.localStorage.getItem(SERVICES_API_KEY.Basescan);
18159
18196
 
18160
- return await handleScanRequest({
18197
+ const out = await handleScanRequest({
18161
18198
  type,
18162
18199
  address,
18163
18200
  startDate,
@@ -18168,7 +18205,18 @@ async function BASE() {
18168
18205
  functionName: 'BASE',
18169
18206
  chainId: CHAIN_ID_MAP.base,
18170
18207
  network: 'base'
18171
- })
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
18172
18220
  } catch (error) {
18173
18221
  return errorMessageHandler(error, 'BASE')
18174
18222
  }
@@ -18288,6 +18336,7 @@ const derivativesSchema = objectType({
18288
18336
  category: literalType('derivatives'),
18289
18337
  param1: stringType().nonempty(),
18290
18338
  param2: anyType().optional(),
18339
+ columnName: stringType().optional(),
18291
18340
  });
18292
18341
  const coingeckoParamsSchema = discriminatedUnionType('category', [
18293
18342
  priceSchema$1,
@@ -18302,8 +18351,8 @@ const coingeckoParamsSchema = discriminatedUnionType('category', [
18302
18351
 
18303
18352
  async function COINGECKO() {
18304
18353
  try {
18305
- const [category, param1, param2] = argsToArray(arguments);
18306
- validateParams(coingeckoParamsSchema, { category, param1, param2 });
18354
+ const [category, param1, param2, columnName = null] = argsToArray(arguments);
18355
+ validateParams(coingeckoParamsSchema, { category, param1, param2, columnName });
18307
18356
 
18308
18357
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Coingecko);
18309
18358
 
@@ -18338,7 +18387,7 @@ async function COINGECKO() {
18338
18387
  break
18339
18388
  }
18340
18389
  }
18341
- const {URL: finalUrl, HEADERS} = getUrlAndHeaders({url, serviceName: 'Coingecko', headers});
18390
+ const { URL: finalUrl, HEADERS } = getUrlAndHeaders({ url, serviceName: 'Coingecko', headers });
18342
18391
 
18343
18392
  const res = await fetch(finalUrl + "?refresh=true", { headers: HEADERS });
18344
18393
  const json = await res.json();
@@ -18364,6 +18413,16 @@ async function COINGECKO() {
18364
18413
  flat[key] = value;
18365
18414
  }
18366
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
+ }
18367
18426
  return flat
18368
18427
  })
18369
18428
  } catch (err) {
@@ -18373,7 +18432,8 @@ async function COINGECKO() {
18373
18432
 
18374
18433
  const categories = ['protocols','yields','dex','fees'];
18375
18434
  const defillamaParamsSchema = objectType({
18376
- category: enumType(categories)
18435
+ category: enumType(categories),
18436
+ columnName: stringType().optional(),
18377
18437
  });
18378
18438
 
18379
18439
  const CATEGORY_URLS = {
@@ -18385,8 +18445,8 @@ const CATEGORY_URLS = {
18385
18445
 
18386
18446
  async function DEFILLAMA() {
18387
18447
  try {
18388
- const [category] = argsToArray(arguments);
18389
- validateParams(defillamaParamsSchema, { category });
18448
+ const [category, columnName = null] = argsToArray(arguments);
18449
+ validateParams(defillamaParamsSchema, { category, columnName });
18390
18450
  const url = CATEGORY_URLS[category];
18391
18451
  if (!url) throw new ValidationError(`Invalid category: ${category}`)
18392
18452
  const res = await fetch(url);
@@ -18406,10 +18466,12 @@ async function DEFILLAMA() {
18406
18466
  break
18407
18467
  }
18408
18468
 
18469
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
18470
+
18409
18471
  return (Array.isArray(json) ? json : [json]).map(item => {
18410
18472
  const out = {};
18411
18473
  for (const [k, v] of Object.entries(item)) {
18412
- if (v === null || typeof v !== 'object') out[k] = v;
18474
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) out[k] = v;
18413
18475
  }
18414
18476
  return out
18415
18477
  })
@@ -18424,6 +18486,7 @@ const gasSchema = objectType({
18424
18486
  endDate: dateOrTimestamp.optional(),
18425
18487
  page: numberType().int().nonnegative().default(1),
18426
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(),
18427
18490
  });
18428
18491
 
18429
18492
  const txnSchema = objectType({
@@ -18434,6 +18497,7 @@ const txnSchema = objectType({
18434
18497
  chain: enumType(['ethereum','base','gnosis']),
18435
18498
  page: numberType().int().nonnegative().default(1),
18436
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(),
18437
18501
  });
18438
18502
 
18439
18503
  const etherscanParamsSchema = discriminatedUnionType('type', [gasSchema, txnSchema]);
@@ -18447,18 +18511,18 @@ const etherscanParamsSchema = discriminatedUnionType('type', [gasSchema, txnSche
18447
18511
 
18448
18512
  async function ETHERSCAN() {
18449
18513
  try {
18450
- const [type, chain, address, startDate, endDate, page = 1, limit = 10] =
18514
+ const [type, chain, address, startDate, endDate, page = 1, limit = 10, columnName = null] =
18451
18515
  argsToArray(arguments);
18452
18516
 
18453
18517
 
18454
- validateParams(etherscanParamsSchema, { type, chain, address, startDate, endDate, page, limit });
18518
+ validateParams(etherscanParamsSchema, { type, chain, address, startDate, endDate, page, limit, columnName });
18455
18519
 
18456
18520
  const chainId = CHAIN_ID_MAP[chain];
18457
18521
  if (!chainId) throw new ValidationError(`Invalid chain: ${chain}`)
18458
18522
 
18459
18523
  const apiKey = window.localStorage.getItem(SERVICES_API_KEY.Etherscan);
18460
18524
 
18461
- return await handleScanRequest({
18525
+ const out = await handleScanRequest({
18462
18526
  type,
18463
18527
  address,
18464
18528
  startDate,
@@ -18469,7 +18533,18 @@ async function ETHERSCAN() {
18469
18533
  functionName: 'ETHERSCAN',
18470
18534
  chainId,
18471
18535
  network: chain,
18472
- })
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
18473
18548
  } catch (err) {
18474
18549
  return errorMessageHandler(err, 'ETHERSCAN')
18475
18550
  }
@@ -18908,13 +18983,14 @@ const uniswapParamsSchema = objectType({
18908
18983
  category: enumType(['tokens','markets']),
18909
18984
  param1: stringType().nonempty(),
18910
18985
  param2: stringType().optional(),
18986
+ colummnName: stringType().optional(),
18911
18987
  });
18912
18988
 
18913
18989
  async function UNISWAP() {
18914
18990
  try {
18915
- const [graphType, category, param1, param2] = argsToArray(arguments);
18991
+ const [graphType, category, param1, param2, columnName] = argsToArray(arguments);
18916
18992
 
18917
- validateParams(uniswapParamsSchema, { graphType, category, param1, param2 });
18993
+ validateParams(uniswapParamsSchema, { graphType, category, param1, param2, columnName });
18918
18994
 
18919
18995
  const baseUrl = 'https://onchain-proxy.fileverse.io/third-party';
18920
18996
  const url =
@@ -18932,16 +19008,24 @@ async function UNISWAP() {
18932
19008
  }
18933
19009
 
18934
19010
  const json = await res.json();
19011
+ const filterColumnName = columnName?.split(',').map(s => s.trim());
18935
19012
  if (Array.isArray(json)) {
18936
19013
  // flatten nested
18937
19014
  return json.map(item => {
18938
19015
  const flat = {};
18939
19016
  Object.entries(item).forEach(([k, v]) => {
18940
- if (v === null || typeof v !== 'object') flat[k] = v;
19017
+ if ((columnName && filterColumnName.includes(k)) && (v === null || typeof v !== 'object')) flat[k] = v;
18941
19018
  });
18942
19019
  return flat
18943
19020
  })
18944
19021
  }
19022
+ if(columnName && typeof json === 'object') {
19023
+ const data = {};
19024
+ filterColumnName.forEach(k => {
19025
+ data[k] = json[k];
19026
+ });
19027
+ return data
19028
+ }
18945
19029
  return json
18946
19030
  } catch (err) {
18947
19031
  return errorMessageHandler(err, 'UNISWAP')
@@ -18951,6 +19035,7 @@ async function UNISWAP() {
18951
19035
  async function SMARTCONTRACT() {
18952
19036
  try {
18953
19037
  const args = argsToArray(arguments);
19038
+ console.log(args, arguments);
18954
19039
 
18955
19040
  return new Promise((resolve) => {
18956
19041
  resolve( {
@@ -29854,14 +29939,15 @@ class CirclesData {
29854
29939
  const circlesParamsSchema = objectType({
29855
29940
  functionName: enumType(['trust', 'profile', 'transactions', 'balances']),
29856
29941
  address: stringType().nonempty(),
29857
- entries: numberType().int().nonnegative().default(10)
29942
+ entries: numberType().int().nonnegative().default(10),
29943
+ columnName: stringType().optional(),
29858
29944
  });
29859
29945
 
29860
29946
  async function CIRCLES() {
29861
29947
  try {
29862
- const [functionName, address, entries] = argsToArray(arguments);
29948
+ const [functionName, address, entries, columnName] = argsToArray(arguments);
29863
29949
 
29864
- validateParams(circlesParamsSchema, { functionName, address, entries });
29950
+ validateParams(circlesParamsSchema, { functionName, address, entries, columnName });
29865
29951
 
29866
29952
  const resolved = await fromEnsNameToAddress$1.validateAndGetAddress(address);
29867
29953
  const dataClient = new CirclesData('https://rpc.aboutcircles.com');
@@ -29879,10 +29965,34 @@ async function CIRCLES() {
29879
29965
 
29880
29966
  switch (functionName) {
29881
29967
  case 'trust':
29882
- 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
+ }
29883
29981
 
29884
29982
  case 'transactions':
29885
- 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
+ }
29886
29996
 
29887
29997
  case 'profile': {
29888
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.36",
3
+ "version": "4.4.38-col-3",
4
4
  "description": "JavaScript implementation of most Microsoft Excel formula functions",
5
5
  "author": "Formulajs",
6
6
  "publishConfig": {