@cripty2001/utils 0.0.128 → 0.0.129

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.
@@ -166,27 +166,23 @@ function useAsync(f, data, debouce = 200) {
166
166
  function useRelTime(refresh = 1000) {
167
167
  const currTs = useCurrentTimestamp(refresh);
168
168
  const rtf = (0, react_1.useRef)(new Intl.RelativeTimeFormat(navigator.language, { numeric: "auto" })).current;
169
+ const getFormat = (seconds) => {
170
+ if (seconds < 60)
171
+ return "second";
172
+ if (seconds < 3600)
173
+ return "minute";
174
+ if (seconds < 86400)
175
+ return "hour";
176
+ if (seconds < 604800)
177
+ return "day";
178
+ return "week";
179
+ };
169
180
  const cb = (0, react_1.useCallback)((ts) => {
170
181
  const now = currTs;
171
182
  const then = ts instanceof Date ? ts.getTime() : ts;
172
183
  const delta = then - now;
173
184
  const seconds = Math.round(delta / 1000);
174
- const format = (() => {
175
- if (seconds < 60)
176
- return "second";
177
- if (seconds < 3600)
178
- return "minute";
179
- if (seconds < 86400)
180
- return "hour";
181
- if (seconds < 604800)
182
- return "day";
183
- if (seconds < 2592000)
184
- return "week";
185
- if (seconds < 31536000)
186
- return "month";
187
- return "year";
188
- })();
189
- return rtf.format(seconds, format);
185
+ return rtf.format(seconds, getFormat(seconds));
190
186
  }, [currTs, rtf]);
191
187
  return cb;
192
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.128",
3
+ "version": "0.0.129",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {