@softsky/utils 2.8.2 → 2.8.4
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 +33 -2
- package/dist/signals.d.ts +2 -2
- package/dist/types.d.ts +34 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -469,11 +469,11 @@ console.log(untrack($a)+$b())
|
|
|
469
469
|
---
|
|
470
470
|
__function__ `computed` - __SIGNALS SYSTEM__
|
|
471
471
|
|
|
472
|
-
Creates a
|
|
472
|
+
Creates a computed reactive memoized signal.
|
|
473
473
|
|
|
474
474
|
```ts
|
|
475
475
|
// Sum of all changes of $a()
|
|
476
|
-
const { signal: $sumOfTwo, clear: clearSum } =
|
|
476
|
+
const { signal: $sumOfTwo, clear: clearSum } = computed((value) => value + $a(), 0)
|
|
477
477
|
```
|
|
478
478
|
|
|
479
479
|
---
|
|
@@ -677,3 +677,34 @@ type b = [number, number, number]
|
|
|
677
677
|
```
|
|
678
678
|
|
|
679
679
|
---
|
|
680
|
+
__type__ `UnionToIntersection` - Convert union type to intersection type
|
|
681
|
+
|
|
682
|
+
```ts
|
|
683
|
+
type a = UnionToIntersection<{a:1} | {b:2}>
|
|
684
|
+
// Result:
|
|
685
|
+
type a = {
|
|
686
|
+
a: 1;
|
|
687
|
+
} & {
|
|
688
|
+
b: 2;
|
|
689
|
+
}
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
---
|
|
693
|
+
__type__ `LastOfUnion` - Get last type in union
|
|
694
|
+
|
|
695
|
+
```ts
|
|
696
|
+
type a = LastOfUnion<'a' | 'b' | 'c'>
|
|
697
|
+
// Result:
|
|
698
|
+
type a = "c"
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
---
|
|
702
|
+
__type__ `LastValueInObject` - Get last value in object
|
|
703
|
+
|
|
704
|
+
```ts
|
|
705
|
+
type a = LastValueInObject<{a:1, b:2, c:3}>
|
|
706
|
+
// Result:
|
|
707
|
+
type a = 3
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
---
|
package/dist/signals.d.ts
CHANGED
|
@@ -59,11 +59,11 @@ export declare function untrack<T>(handler: () => T): T;
|
|
|
59
59
|
/**
|
|
60
60
|
* __SIGNALS SYSTEM__
|
|
61
61
|
*
|
|
62
|
-
* Creates a
|
|
62
|
+
* Creates a computed reactive memoized signal.
|
|
63
63
|
*
|
|
64
64
|
* @example
|
|
65
65
|
* // Sum of all changes of $a()
|
|
66
|
-
* const { signal: $sumOfTwo, clear: clearSum } =
|
|
66
|
+
* const { signal: $sumOfTwo, clear: clearSum } = computed((value) => value + $a(), 0)
|
|
67
67
|
*/
|
|
68
68
|
export declare function computed<T>(handler: (argument: T | undefined) => T): {
|
|
69
69
|
signal: Signal<T>;
|
package/dist/types.d.ts
CHANGED
|
@@ -66,3 +66,37 @@ export type Prettify<T extends object> = {
|
|
|
66
66
|
* type b = [number, number, number]
|
|
67
67
|
*/
|
|
68
68
|
export type Tuple<T, N extends number, R extends readonly T[] = []> = R['length'] extends N ? R : Tuple<T, N, [...R, T]>;
|
|
69
|
+
/**
|
|
70
|
+
* Convert union type to intersection type
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* type a = UnionToIntersection<{a:1} | {b:2}>
|
|
74
|
+
* // Result:
|
|
75
|
+
* type a = {
|
|
76
|
+
* a: 1;
|
|
77
|
+
* } & {
|
|
78
|
+
* b: 2;
|
|
79
|
+
* }
|
|
80
|
+
*/
|
|
81
|
+
export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
82
|
+
/**
|
|
83
|
+
* Get last type in union
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* type a = LastOfUnion<'a' | 'b' | 'c'>
|
|
87
|
+
* // Result:
|
|
88
|
+
* type a = "c"
|
|
89
|
+
*/
|
|
90
|
+
export type LastOfUnion<U> = UnionToIntersection<U extends any ? (x: U) => void : never> extends (x: infer L) => void ? L : never;
|
|
91
|
+
/**
|
|
92
|
+
* Get last value in object
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* type a = LastValueInObject<{a:1, b:2, c:3}>
|
|
96
|
+
* // Result:
|
|
97
|
+
* type a = 3
|
|
98
|
+
*/
|
|
99
|
+
export type LastValueInObject<S extends object> = S[LastOfUnion<keyof S> & keyof S];
|
|
100
|
+
export type DeepPartial<T extends object> = {
|
|
101
|
+
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
|
|
102
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softsky/utils",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.4",
|
|
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.5",
|
|
24
|
-
"@types/bun": "^1.3.
|
|
24
|
+
"@types/bun": "^1.3.5"
|
|
25
25
|
},
|
|
26
26
|
"files": ["dist/**/*"]
|
|
27
27
|
}
|