@cripty2001/utils 0.0.52 → 0.0.53

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.d.ts CHANGED
@@ -84,3 +84,4 @@ export declare function randBetween(min: number, max: number): number;
84
84
  */
85
85
  export declare function getEnv(key: string, defaultValue?: string): string;
86
86
  export declare const CURRENT_TS_MS: Whispr<number>;
87
+ export declare function timediff2HumanReadable(diffMs: number): string;
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ exports.stableLog = stableLog;
15
15
  exports.parseQuery = parseQuery;
16
16
  exports.randBetween = randBetween;
17
17
  exports.getEnv = getEnv;
18
+ exports.timediff2HumanReadable = timediff2HumanReadable;
18
19
  const whispr_1 = require("@cripty2001/whispr");
19
20
  const lodash_1 = require("lodash");
20
21
  /**
@@ -206,3 +207,29 @@ setInterval(() => {
206
207
  setCurrentTsMs(Date.now());
207
208
  }, 200);
208
209
  exports.CURRENT_TS_MS = currentTsMs;
210
+ function timediff2HumanReadable(diffMs) {
211
+ const { unit, diff } = (() => {
212
+ let toReturn = diffMs;
213
+ const OPTIONS = [
214
+ { divisor: 1000, unit: 'milliseconds' },
215
+ { divisor: 60, unit: 'seconds' },
216
+ { divisor: 60, unit: 'minutes' },
217
+ { divisor: 24, unit: 'hours' },
218
+ { divisor: 30, unit: 'days' },
219
+ { divisor: 12, unit: 'months' },
220
+ { divisor: 1, unit: 'years' },
221
+ ];
222
+ while (OPTIONS.length) {
223
+ const { divisor, unit } = OPTIONS.shift();
224
+ if (Math.abs(toReturn) < divisor)
225
+ return {
226
+ unit,
227
+ diff: toReturn
228
+ };
229
+ toReturn = toReturn / divisor;
230
+ }
231
+ return { unit: 'years', diff: toReturn };
232
+ })();
233
+ const rtf = new Intl.RelativeTimeFormat();
234
+ return rtf.format(Math.round(diff), unit);
235
+ }
@@ -62,4 +62,3 @@ export declare function useAsync<I, O>(f: (input: I, setProgress: (p: number) =>
62
62
  * @returns A callback (reactive, will change on refresh) that formats a given timestamp into a relative time string.
63
63
  */
64
64
  export declare function useRelTime(refresh?: number): (ts: Date | number) => string;
65
- export declare function timediff2HumanReadable(diffMs: number): string;
@@ -7,7 +7,6 @@ exports.useCurrentTimestamp = useCurrentTimestamp;
7
7
  exports.useDebounced = useDebounced;
8
8
  exports.useAsync = useAsync;
9
9
  exports.useRelTime = useRelTime;
10
- exports.timediff2HumanReadable = timediff2HumanReadable;
11
10
  const whispr_1 = require("@cripty2001/whispr");
12
11
  const react_1 = require("react");
13
12
  const lodash_1 = require("lodash");
@@ -133,29 +132,3 @@ function useRelTime(refresh = 1000) {
133
132
  }, [currTs, rtf]);
134
133
  return cb;
135
134
  }
136
- function timediff2HumanReadable(diffMs) {
137
- const { unit, diff } = (() => {
138
- let toReturn = diffMs;
139
- const OPTIONS = [
140
- { divisor: 1000, unit: 'milliseconds' },
141
- { divisor: 60, unit: 'seconds' },
142
- { divisor: 60, unit: 'minutes' },
143
- { divisor: 24, unit: 'hours' },
144
- { divisor: 30, unit: 'days' },
145
- { divisor: 12, unit: 'months' },
146
- { divisor: 1, unit: 'years' },
147
- ];
148
- while (OPTIONS.length) {
149
- const { divisor, unit } = OPTIONS.shift();
150
- if (Math.abs(toReturn) < divisor)
151
- return {
152
- unit,
153
- diff: toReturn
154
- };
155
- toReturn = toReturn / divisor;
156
- }
157
- return { unit: 'years', diff: toReturn };
158
- })();
159
- const rtf = new Intl.RelativeTimeFormat();
160
- return rtf.format(Math.round(diff), unit);
161
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.52",
3
+ "version": "0.0.53",
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": {