@softsky/utils 2.5.4 → 2.5.5

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/README.md CHANGED
@@ -430,6 +430,18 @@ Timers, CRON, etc.
430
430
 
431
431
  __function__ `measurePerformance` - Measure performance of a function
432
432
 
433
+ ---
434
+ __function__ `setSafeTimeout` - Original setTimeout and setIntval known for accumulating delay
435
+ and causing problem with timeouts bigger than 32bit integer.
436
+
437
+ This timeout wrapper fixes them. Returns clear function.
438
+
439
+ ---
440
+ __function__ `setSafeInterval` - Original setTimeout and setIntval known for accumulating delay
441
+ and causing problem with timeouts bigger than 32bit integer.
442
+
443
+ This interval wrapper fixes them. Returns clear function.
444
+
433
445
  ---
434
446
  __function__ `cronInterval` - Like setInterval but with cron.
435
447
  Returns clear function.
@@ -500,3 +512,23 @@ __type__ `ObjectSnakeToCamel` - Convert object keys of this-case to thisCase
500
512
  __type__ `Concat` - Concat types of array or objects
501
513
 
502
514
  ---
515
+ __type__ `Prettify` - Visual only overhaul. Shows final type result on hover.
516
+ ```ts
517
+ type a = {a: '1'}
518
+ type b = Prettify<a & { b: 'b' }>
519
+ ```
520
+ On hovering b it will show
521
+ ```ts
522
+ type b = {
523
+ a: "1";
524
+ b: "b";
525
+ }
526
+ ```
527
+ instead of
528
+ ```ts
529
+ type b = a & {
530
+ b: "b";
531
+ }
532
+ ```
533
+
534
+ ---
package/dist/time.d.ts CHANGED
@@ -1,8 +1,23 @@
1
1
  /**
2
2
  * Timers, CRON, etc.
3
3
  */
4
+ import { AnyFunction } from './types';
4
5
  /** Measure performance of a function */
5
6
  export declare function measurePerformance(function_: () => unknown, timeCheck?: number): number;
7
+ /**
8
+ * Original setTimeout and setIntval known for accumulating delay
9
+ * and causing problem with timeouts bigger than 32bit integer.
10
+ *
11
+ * This timeout wrapper fixes them. Returns clear function.
12
+ */
13
+ export declare function setSafeTimeout(handler: AnyFunction, delay: number): () => void;
14
+ /**
15
+ * Original setTimeout and setIntval known for accumulating delay
16
+ * and causing problem with timeouts bigger than 32bit integer.
17
+ *
18
+ * This interval wrapper fixes them. Returns clear function.
19
+ */
20
+ export declare function setSafeInterval(handler: AnyFunction, delay: number): () => void;
6
21
  /** Like setInterval but with cron.
7
22
  * Returns clear function.
8
23
  * For cron string syntax check __getNextCron()__ description */
package/dist/time.js CHANGED
@@ -13,6 +13,51 @@ export function measurePerformance(function_, timeCheck = 16.6) {
13
13
  }
14
14
  return executions;
15
15
  }
16
+ /**
17
+ * Original setTimeout and setIntval known for accumulating delay
18
+ * and causing problem with timeouts bigger than 32bit integer.
19
+ *
20
+ * This timeout wrapper fixes them. Returns clear function.
21
+ */
22
+ export function setSafeTimeout(handler, delay) {
23
+ const end = Date.now() + delay;
24
+ let timeout;
25
+ function r() {
26
+ const timeLeft = end - Date.now();
27
+ if (timeLeft < 1)
28
+ handler();
29
+ else
30
+ timeout = setTimeout(r, Math.min(timeLeft, HOUR_MS));
31
+ }
32
+ r();
33
+ return () => {
34
+ clearTimeout(timeout);
35
+ };
36
+ }
37
+ /**
38
+ * Original setTimeout and setIntval known for accumulating delay
39
+ * and causing problem with timeouts bigger than 32bit integer.
40
+ *
41
+ * This interval wrapper fixes them. Returns clear function.
42
+ */
43
+ export function setSafeInterval(handler, delay) {
44
+ let end = Date.now() + delay;
45
+ let timeout;
46
+ function r() {
47
+ const timeLeft = end - Date.now();
48
+ if (timeLeft < 1) {
49
+ end += delay;
50
+ handler();
51
+ r();
52
+ }
53
+ else
54
+ timeout = setTimeout(r, Math.min(timeLeft, HOUR_MS));
55
+ }
56
+ r();
57
+ return () => {
58
+ clearInterval(timeout);
59
+ };
60
+ }
16
61
  /** Like setInterval but with cron.
17
62
  * Returns clear function.
18
63
  * For cron string syntax check __getNextCron()__ description */
package/dist/types.d.ts CHANGED
@@ -39,3 +39,26 @@ export type ObjectSnakeToCamel<T> = {
39
39
  };
40
40
  /** Concat types of array or objects */
41
41
  export type Concat<T, U> = T extends any[] ? U extends any[] ? [...T, ...U] : never : T & U;
42
+ /**
43
+ * Visual only overhaul. Shows final type result on hover.
44
+ * ```ts
45
+ * type a = {a: '1'}
46
+ * type b = Prettify<a & { b: 'b' }>
47
+ * ```
48
+ * On hovering b it will show
49
+ * ```ts
50
+ * type b = {
51
+ * a: "1";
52
+ * b: "b";
53
+ * }
54
+ * ```
55
+ * instead of
56
+ * ```ts
57
+ * type b = a & {
58
+ * b: "b";
59
+ * }
60
+ * ```
61
+ * */
62
+ export type Prettify<T extends object> = {
63
+ [k in keyof T]: T[k];
64
+ } & {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softsky/utils",
3
- "version": "2.5.4",
3
+ "version": "2.5.5",
4
4
  "description": "JavaScript/TypeScript utilities",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {