@investtal/types 1.0.1
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/CHANGELOG.md +13 -0
- package/package.json +24 -0
- package/src/common.d.ts +69 -0
- package/src/index.d.ts +4 -0
- package/src/index.js +1 -0
package/CHANGELOG.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@investtal/types",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"author": "harrytran998",
|
|
5
|
+
"description": "Investtal base types",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"types": "src/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"private": false,
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@total-typescript/ts-reset": "^0.6.1",
|
|
13
|
+
"type-fest": "^4.39.1"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22"
|
|
17
|
+
},
|
|
18
|
+
"files": ["src", "package.json", "README.md", "CHANGELOG.md", "LICENSE"],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public",
|
|
21
|
+
"tag": "latest",
|
|
22
|
+
"registry": "https://registry.npmjs.org"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/common.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export type Nullable<T> = T | null
|
|
2
|
+
export type UnDef<T> = T | undefined
|
|
3
|
+
export type NullList<T> = T | undefined | null
|
|
4
|
+
export type EntityId = number | string
|
|
5
|
+
export type Entity = number | string | symbol
|
|
6
|
+
|
|
7
|
+
export interface DictNum<T> {
|
|
8
|
+
[id: number]: T
|
|
9
|
+
}
|
|
10
|
+
export interface Dict<T> extends DictNum<T> {
|
|
11
|
+
[id: string]: T
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface EntityState<T> {
|
|
15
|
+
ids: string[]
|
|
16
|
+
entities: Dict<T>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type VoidFunc<T> = (value: T) => void
|
|
20
|
+
export type StringEnum<T> = T | (string & Record<never, never>)
|
|
21
|
+
|
|
22
|
+
export type Records<T = any> = Record<Entity, T>
|
|
23
|
+
|
|
24
|
+
// test if we are going the left AND right path in the condition
|
|
25
|
+
export type IsAny<T, True, False = never> = true | false extends (T extends never ? true : false)
|
|
26
|
+
? True
|
|
27
|
+
: False
|
|
28
|
+
|
|
29
|
+
export type PreventAny<S, T> = IsAny<S, EntityState<T>, S>
|
|
30
|
+
|
|
31
|
+
export type Comparer<T> = (a: T, b: T) => number
|
|
32
|
+
|
|
33
|
+
export type MergeInsertions<T> = T extends Record<string, any>
|
|
34
|
+
? {
|
|
35
|
+
[K in keyof T]: MergeInsertions<T[K]>
|
|
36
|
+
}
|
|
37
|
+
: T
|
|
38
|
+
|
|
39
|
+
export type MergeDeep<F, S> = MergeInsertions<{
|
|
40
|
+
[K in keyof F | keyof S]: K extends keyof S & keyof F
|
|
41
|
+
? MergeDeep<F[K], S[K]>
|
|
42
|
+
: K extends keyof S
|
|
43
|
+
? S[K]
|
|
44
|
+
: K extends keyof F
|
|
45
|
+
? F[K]
|
|
46
|
+
: never
|
|
47
|
+
}>
|
|
48
|
+
|
|
49
|
+
export type RuntimeEnv = "development" | "staging" | "production"
|
|
50
|
+
export type NodeEnv = "development" | "test" | "production"
|
|
51
|
+
|
|
52
|
+
export type ComputeRange<
|
|
53
|
+
N extends number,
|
|
54
|
+
Result extends unknown[] = [],
|
|
55
|
+
> = Result["length"] extends N ? Result : ComputeRange<N, [...Result, Result["length"]]>
|
|
56
|
+
|
|
57
|
+
type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N
|
|
58
|
+
? Acc[number]
|
|
59
|
+
: Enumerate<N, [...Acc, Acc["length"]]>
|
|
60
|
+
|
|
61
|
+
export type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}`
|
|
62
|
+
? `${T extends Capitalize<T> ? "_" : ""}${Lowercase<T>}${CamelToSnakeCase<U>}`
|
|
63
|
+
: S
|
|
64
|
+
|
|
65
|
+
export type CamelToSnakeNested<T> = T extends object
|
|
66
|
+
? {
|
|
67
|
+
[K in keyof T as CamelToSnakeCase<K & string>]: CamelToSnakeNested<T[K]>
|
|
68
|
+
}
|
|
69
|
+
: T
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Nothing here
|