diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /shared/core-utils | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip |
Reorganize client shared modules
Diffstat (limited to 'shared/core-utils')
-rw-r--r-- | shared/core-utils/index.ts | 3 | ||||
-rw-r--r-- | shared/core-utils/logs/index.ts | 1 | ||||
-rw-r--r-- | shared/core-utils/miscs/index.ts | 3 | ||||
-rw-r--r-- | shared/core-utils/miscs/types.ts | 41 | ||||
-rw-r--r-- | shared/core-utils/plugins/index.ts | 1 |
5 files changed, 49 insertions, 0 deletions
diff --git a/shared/core-utils/index.ts b/shared/core-utils/index.ts new file mode 100644 index 000000000..54e233522 --- /dev/null +++ b/shared/core-utils/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './logs' | ||
2 | export * from './miscs' | ||
3 | export * from './plugins' | ||
diff --git a/shared/core-utils/logs/index.ts b/shared/core-utils/logs/index.ts new file mode 100644 index 000000000..ceb5d7a7f --- /dev/null +++ b/shared/core-utils/logs/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './logs' | |||
diff --git a/shared/core-utils/miscs/index.ts b/shared/core-utils/miscs/index.ts new file mode 100644 index 000000000..afd147f24 --- /dev/null +++ b/shared/core-utils/miscs/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './date' | ||
2 | export * from './miscs' | ||
3 | export * from './types' | ||
diff --git a/shared/core-utils/miscs/types.ts b/shared/core-utils/miscs/types.ts new file mode 100644 index 000000000..bb64dc830 --- /dev/null +++ b/shared/core-utils/miscs/types.ts | |||
@@ -0,0 +1,41 @@ | |||
1 | /* eslint-disable @typescript-eslint/array-type */ | ||
2 | |||
3 | export type FunctionPropertyNames<T> = { | ||
4 | [K in keyof T]: T[K] extends Function ? K : never | ||
5 | }[keyof T] | ||
6 | |||
7 | export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>> | ||
8 | |||
9 | export type PickWith<T, KT extends keyof T, V> = { | ||
10 | [P in KT]: T[P] extends V ? V : never | ||
11 | } | ||
12 | |||
13 | export type PickWithOpt<T, KT extends keyof T, V> = { | ||
14 | [P in KT]?: T[P] extends V ? V : never | ||
15 | } | ||
16 | |||
17 | // https://github.com/krzkaczor/ts-essentials Rocks! | ||
18 | export type DeepPartial<T> = { | ||
19 | [P in keyof T]?: T[P] extends Array<infer U> | ||
20 | ? Array<DeepPartial<U>> | ||
21 | : T[P] extends ReadonlyArray<infer U> | ||
22 | ? ReadonlyArray<DeepPartial<U>> | ||
23 | : DeepPartial<T[P]> | ||
24 | } | ||
25 | |||
26 | type Primitive = string | Function | number | boolean | Symbol | undefined | null | ||
27 | export type DeepOmitHelper<T, K extends keyof T> = { | ||
28 | [P in K]: // extra level of indirection needed to trigger homomorhic behavior | ||
29 | T[P] extends infer TP // distribute over unions | ||
30 | ? TP extends Primitive | ||
31 | ? TP // leave primitives and functions alone | ||
32 | : TP extends any[] | ||
33 | ? DeepOmitArray<TP, K> // Array special handling | ||
34 | : DeepOmit<TP, K> | ||
35 | : never | ||
36 | } | ||
37 | export type DeepOmit<T, K> = T extends Primitive ? T : DeepOmitHelper<T, Exclude<keyof T, K>> | ||
38 | |||
39 | export type DeepOmitArray<T extends any[], K> = { | ||
40 | [P in keyof T]: DeepOmit<T[P], K> | ||
41 | } | ||
diff --git a/shared/core-utils/plugins/index.ts b/shared/core-utils/plugins/index.ts new file mode 100644 index 000000000..fc78d3512 --- /dev/null +++ b/shared/core-utils/plugins/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './hooks' | |||