@softsky/utils 2.5.3 → 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 +35 -2
- package/dist/signals.d.ts +1 -0
- package/dist/signals.js +1 -0
- package/dist/time.d.ts +15 -0
- package/dist/time.js +45 -0
- package/dist/types.d.ts +23 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
`npm i @softsky/utils`
|
|
12
12
|
|
|
13
|
+
__ZERO DEPENDENCIES__ utils library. Test coverage __100%__.
|
|
14
|
+
|
|
13
15
|
Usual utils plus more obscure stuff that I've never seen in any library.
|
|
14
16
|
Also fancy TypeScript generics and types that I often use.
|
|
15
|
-
|
|
16
|
-
Test coverage __100%__.
|
|
17
17
|
</div>
|
|
18
18
|
|
|
19
19
|
# Contribute
|
|
@@ -363,6 +363,7 @@ const mySignal = $mySignal()
|
|
|
363
363
|
if(last>mySignal) console.log('Increment!')
|
|
364
364
|
return mySignal;
|
|
365
365
|
})
|
|
366
|
+
```
|
|
366
367
|
|
|
367
368
|
---
|
|
368
369
|
__function__ `untrack` - __SIGNALS SYSTEM__
|
|
@@ -429,6 +430,18 @@ Timers, CRON, etc.
|
|
|
429
430
|
|
|
430
431
|
__function__ `measurePerformance` - Measure performance of a function
|
|
431
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
|
+
|
|
432
445
|
---
|
|
433
446
|
__function__ `cronInterval` - Like setInterval but with cron.
|
|
434
447
|
Returns clear function.
|
|
@@ -499,3 +512,23 @@ __type__ `ObjectSnakeToCamel` - Convert object keys of this-case to thisCase
|
|
|
499
512
|
__type__ `Concat` - Concat types of array or objects
|
|
500
513
|
|
|
501
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/signals.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare function signal<T>(value: T): Signal<T>;
|
|
|
42
42
|
* if(last>mySignal) console.log('Increment!')
|
|
43
43
|
* return mySignal;
|
|
44
44
|
* })
|
|
45
|
+
* ```
|
|
45
46
|
*/
|
|
46
47
|
export declare function effect<T>(handler: (argument: T | undefined) => T, initialValue?: T): () => void;
|
|
47
48
|
/**
|
package/dist/signals.js
CHANGED
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.
|
|
3
|
+
"version": "2.5.5",
|
|
4
4
|
"description": "JavaScript/TypeScript utilities",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"homepage": "https://github.com/SoundOfTheSky/utils#readme",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@softsky/configs": "^1.3.3",
|
|
24
|
-
"@types/bun": "^1.2.
|
|
24
|
+
"@types/bun": "^1.2.16"
|
|
25
25
|
},
|
|
26
26
|
"files": ["dist/**/*"]
|
|
27
27
|
}
|