@ztimson/utils 0.24.0 → 0.24.2

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/dist/index.mjs CHANGED
@@ -906,15 +906,15 @@ function formatDate(format = "YYYY-MM-DD H:mm", date = /* @__PURE__ */ new Date(
906
906
  };
907
907
  return format.replace(/YYYY|YY|MMMM|MMM|MM|M|DDD|DD|Do|D|dddd|ddd|HH|H|hh|h|mm|m|ss|s|SSS|A|a|ZZ|Z|z/g, (token) => tokens[token]);
908
908
  }
909
- function instantInterval(fn, interval) {
910
- fn();
911
- return setInterval(fn, interval);
909
+ function instantInterval(fn2, interval) {
910
+ fn2();
911
+ return setInterval(fn2, interval);
912
912
  }
913
913
  function sleep(ms) {
914
914
  return new Promise((res) => setTimeout(res, ms));
915
915
  }
916
- async function sleepWhile(fn, checkInterval = 100) {
917
- while (await fn()) await sleep(checkInterval);
916
+ async function sleepWhile(fn2, checkInterval = 100) {
917
+ while (await fn2()) await sleep(checkInterval);
918
918
  }
919
919
  function timeUntil(date) {
920
920
  return (date instanceof Date ? date.getTime() : date) - (/* @__PURE__ */ new Date()).getTime();
@@ -1225,16 +1225,16 @@ const _Http = class _Http {
1225
1225
  defaults.interceptors.forEach((i) => _Http.addInterceptor(i));
1226
1226
  }
1227
1227
  }
1228
- static addInterceptor(fn) {
1228
+ static addInterceptor(fn2) {
1229
1229
  const key = Object.keys(_Http.interceptors).length.toString();
1230
- _Http.interceptors[key] = fn;
1230
+ _Http.interceptors[key] = fn2;
1231
1231
  return () => {
1232
1232
  _Http.interceptors[key] = null;
1233
1233
  };
1234
1234
  }
1235
- addInterceptor(fn) {
1235
+ addInterceptor(fn2) {
1236
1236
  const key = Object.keys(this.interceptors).length.toString();
1237
- this.interceptors[key] = fn;
1237
+ this.interceptors[key] = fn2;
1238
1238
  return () => {
1239
1239
  this.interceptors[key] = null;
1240
1240
  };
@@ -1265,8 +1265,8 @@ const _Http = class _Http {
1265
1265
  body: opts.body
1266
1266
  }).then(async (resp) => {
1267
1267
  var _a2, _b;
1268
- for (let fn of [...Object.values(_Http.interceptors), ...Object.values(this.interceptors)]) {
1269
- await new Promise((res2) => fn(resp, () => res2()));
1268
+ for (let fn2 of [...Object.values(_Http.interceptors), ...Object.values(this.interceptors)]) {
1269
+ await new Promise((res2) => fn2(resp, () => res2()));
1270
1270
  }
1271
1271
  const contentLength = resp.headers.get("Content-Length");
1272
1272
  const total = contentLength ? parseInt(contentLength, 10) : 0;
@@ -1422,6 +1422,10 @@ function fracToDec(frac) {
1422
1422
  split = split.pop().split("/");
1423
1423
  return whole + Number(split[0]) / Number(split[1]);
1424
1424
  }
1425
+ function fn(args, fn2, async = false) {
1426
+ const keys = Object.keys(args);
1427
+ return new Function(...keys, `return (${async ? "async " : ""}(${keys.join(",")}) => { ${fn2} })(${keys.join(",")})`)(...keys.map((k) => args[k]));
1428
+ }
1425
1429
  function gravatar(email, def = "mp") {
1426
1430
  if (!email) return "";
1427
1431
  return `https://www.gravatar.com/avatar/${md5(email)}?d=${def}`;
@@ -1774,6 +1778,7 @@ export {
1774
1778
  findByProp,
1775
1779
  flattenArr,
1776
1780
  flattenObj,
1781
+ fn,
1777
1782
  formData,
1778
1783
  formatBytes,
1779
1784
  formatDate,