@nickyzj2023/utils 1.0.18 → 1.0.19
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 -35
- package/biome.json +40 -0
- package/dist/index.js +1 -1
- package/dist/string.d.ts +16 -2
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/functions/camelToSnake.html +2 -2
- package/docs/functions/capitalize.html +178 -0
- package/docs/functions/decapitalize.html +178 -0
- package/docs/functions/fetcher.html +1 -1
- package/docs/functions/isObject.html +1 -1
- package/docs/functions/isPrimitive.html +1 -1
- package/docs/functions/mapKeys.html +1 -1
- package/docs/functions/mapValues.html +1 -1
- package/docs/functions/mergeObjects.html +1 -1
- package/docs/functions/sleep.html +1 -1
- package/docs/functions/snakeToCamel.html +2 -2
- package/docs/functions/timeLog.html +1 -1
- package/docs/functions/to.html +1 -1
- package/docs/functions/withCache.html +3 -3
- package/docs/modules.html +1 -1
- package/docs/types/DeepMapKeys.html +1 -1
- package/docs/types/DeepMapValues.html +1 -1
- package/docs/types/Primitive.html +1 -1
- package/docs/types/RequestInit.html +1 -1
- package/docs/types/SetTtl.html +1 -1
- package/package.json +2 -1
- package/src/dom.ts +10 -10
- package/src/hoc.ts +115 -115
- package/src/index.ts +7 -7
- package/src/is.ts +21 -21
- package/src/lru-cache.ts +50 -50
- package/src/network.ts +111 -111
- package/src/object.ts +165 -165
- package/src/string.ts +42 -22
- package/src/time.ts +11 -11
- package/tsconfig.json +32 -32
package/src/object.ts
CHANGED
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
import { isObject, isPrimitive } from "./is";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 深度合并两个对象,规则如下:
|
|
5
|
-
* 1. 原始值覆盖:如果两个值都是原始类型(string、number、boolean、null、undefined、symbol、bigint),则用后者覆盖;
|
|
6
|
-
* 2. 数组拼接:如果两个值都是数组,则拼接为大数组;
|
|
7
|
-
* 3. 对象递归合并:如果两个值都是对象,则进行递归深度合并;
|
|
8
|
-
* 4. 类型不匹配覆盖:如果两个值的类型不同,则用后者覆盖;
|
|
9
|
-
* 5. 独有属性保留:如果字段只存在于其中一个对象中,则保留它。
|
|
10
|
-
*
|
|
11
|
-
* @template T 第一个对象
|
|
12
|
-
* @template U 第二个对象
|
|
13
|
-
* @param {T} obj1 要合并的第一个对象,相同字段可能会被 obj2 覆盖
|
|
14
|
-
* @param {U} obj2 要合并的第二个对象
|
|
15
|
-
*/
|
|
16
|
-
export const mergeObjects = <
|
|
17
|
-
T extends Record<string, any>,
|
|
18
|
-
U extends Record<string, any>,
|
|
19
|
-
>(
|
|
20
|
-
obj1: T,
|
|
21
|
-
obj2: U,
|
|
22
|
-
) => {
|
|
23
|
-
const result: Record<string, any> = { ...obj1 };
|
|
24
|
-
|
|
25
|
-
for (const key of Object.keys(obj2)) {
|
|
26
|
-
const val1 = result[key];
|
|
27
|
-
const val2 = obj2[key];
|
|
28
|
-
|
|
29
|
-
// 如果都是原始值,则用后者覆盖
|
|
30
|
-
if (isPrimitive(val1) && isPrimitive(val2)) {
|
|
31
|
-
result[key] = val2;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 如果都是数组,则拼接为大数组
|
|
36
|
-
if (Array.isArray(val1) && Array.isArray(val2)) {
|
|
37
|
-
result[key] = val1.concat(val2);
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 如果都是对象,则深度递归合并
|
|
42
|
-
if (isObject(val1) && isObject(val2)) {
|
|
43
|
-
result[key] = mergeObjects(val1, val2);
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// 如果类型不同,则用后者覆盖
|
|
48
|
-
result[key] = val2;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return result as T & U;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// --- mapKeys ---
|
|
55
|
-
|
|
56
|
-
// 这里的 DeepMapKeys 只能承诺 key 是 string,无法推断出 key 的具体字面量变化
|
|
57
|
-
// 因为 TS 不支持根据任意函数反推 Key 的字面量类型
|
|
58
|
-
export type DeepMapKeys<T> =
|
|
59
|
-
T extends Array<infer U>
|
|
60
|
-
? Array<DeepMapKeys<U>>
|
|
61
|
-
: T extends object
|
|
62
|
-
? { [key: string]: DeepMapKeys<T[keyof T]> }
|
|
63
|
-
: T;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 递归处理对象里的 key
|
|
67
|
-
*
|
|
68
|
-
* @remarks
|
|
69
|
-
* 无法完整推导出类型,只能做到有递归,key 全为 string,value 为同层级的所有类型的联合
|
|
70
|
-
*
|
|
71
|
-
* @template T 要转换的对象
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* const obj = { a: { b: 1 } };
|
|
75
|
-
* const result = mapKeys(obj, (key) => key.toUpperCase());
|
|
76
|
-
* console.log(result); // { A: { B: 1 } }
|
|
77
|
-
*/
|
|
78
|
-
export const mapKeys = <T>(
|
|
79
|
-
obj: T,
|
|
80
|
-
getNewKey: (key: string) => string,
|
|
81
|
-
): DeepMapKeys<T> => {
|
|
82
|
-
// 递归处理数组
|
|
83
|
-
if (Array.isArray(obj)) {
|
|
84
|
-
return obj.map((item) => mapKeys(item, getNewKey)) as any;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 处理普通对象
|
|
88
|
-
if (isObject(obj)) {
|
|
89
|
-
const keys = Object.keys(obj);
|
|
90
|
-
return keys.reduce(
|
|
91
|
-
(result, key) => {
|
|
92
|
-
const newKey = getNewKey(key);
|
|
93
|
-
const value = (obj as any)[key];
|
|
94
|
-
result[newKey] = mapKeys(value, getNewKey);
|
|
95
|
-
return result;
|
|
96
|
-
},
|
|
97
|
-
{} as Record<string, any>,
|
|
98
|
-
) as DeepMapKeys<T>;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// 处理非数组/对象
|
|
102
|
-
return obj as any;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// --- mapValues ---
|
|
106
|
-
|
|
107
|
-
// 这里的 DeepMapValues 尝试保留 key,但将 value 类型替换为 R
|
|
108
|
-
// 注意:如果原 value 是对象,我们递归处理结构,而不是把整个对象变成 R
|
|
109
|
-
export type DeepMapValues<T, R> =
|
|
110
|
-
T extends Array<infer U>
|
|
111
|
-
? Array<DeepMapValues<U, R>>
|
|
112
|
-
: T extends object
|
|
113
|
-
? { [K in keyof T]: T[K] extends object ? DeepMapValues<T[K], R> : R }
|
|
114
|
-
: R;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 递归处理对象里的 value
|
|
118
|
-
*
|
|
119
|
-
* @remarks
|
|
120
|
-
* 无法完整推导出类型,所有 value 最终都会变为 any
|
|
121
|
-
*
|
|
122
|
-
* @template T 要转换的对象
|
|
123
|
-
* @template R 转换后的值类型,为 any,无法进一步推导
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* const obj = { a: 1, b: { c: 2 } };
|
|
127
|
-
* const result = mapValues(obj, (value, key) => isPrimitive(value) ? value + 1 : value);
|
|
128
|
-
* console.log(result); // { a: 2, b: { c: 3 } }
|
|
129
|
-
*/
|
|
130
|
-
export const mapValues = <T, R = any>(
|
|
131
|
-
obj: T,
|
|
132
|
-
getNewValue: (value: any, key: string | number) => R,
|
|
133
|
-
): DeepMapValues<T, R> => {
|
|
134
|
-
// 处理数组
|
|
135
|
-
if (Array.isArray(obj)) {
|
|
136
|
-
return obj.map((item, index) => {
|
|
137
|
-
// 如果元素是对象,则递归处理
|
|
138
|
-
if (isObject(item)) {
|
|
139
|
-
return mapValues(item, getNewValue);
|
|
140
|
-
}
|
|
141
|
-
// 如果元素是原始值,则直接应用 getNewValue(此时 key 为数组下标)
|
|
142
|
-
return getNewValue(item, index);
|
|
143
|
-
}) as any;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// 处理普通对象
|
|
147
|
-
if (isObject(obj)) {
|
|
148
|
-
const keys = Object.keys(obj);
|
|
149
|
-
return keys.reduce((result, key) => {
|
|
150
|
-
const value = (obj as any)[key];
|
|
151
|
-
// 如果值为对象或数组,则递归处理
|
|
152
|
-
if (!isPrimitive(value)) {
|
|
153
|
-
result[key] = mapValues(value, getNewValue);
|
|
154
|
-
}
|
|
155
|
-
// 否则直接应用 getNewValue
|
|
156
|
-
else {
|
|
157
|
-
result[key] = getNewValue(value, key);
|
|
158
|
-
}
|
|
159
|
-
return result;
|
|
160
|
-
}, {} as any) as DeepMapValues<T, R>;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// 处理非数组/对象
|
|
164
|
-
return obj as any;
|
|
165
|
-
};
|
|
1
|
+
import { isObject, isPrimitive } from "./is";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 深度合并两个对象,规则如下:
|
|
5
|
+
* 1. 原始值覆盖:如果两个值都是原始类型(string、number、boolean、null、undefined、symbol、bigint),则用后者覆盖;
|
|
6
|
+
* 2. 数组拼接:如果两个值都是数组,则拼接为大数组;
|
|
7
|
+
* 3. 对象递归合并:如果两个值都是对象,则进行递归深度合并;
|
|
8
|
+
* 4. 类型不匹配覆盖:如果两个值的类型不同,则用后者覆盖;
|
|
9
|
+
* 5. 独有属性保留:如果字段只存在于其中一个对象中,则保留它。
|
|
10
|
+
*
|
|
11
|
+
* @template T 第一个对象
|
|
12
|
+
* @template U 第二个对象
|
|
13
|
+
* @param {T} obj1 要合并的第一个对象,相同字段可能会被 obj2 覆盖
|
|
14
|
+
* @param {U} obj2 要合并的第二个对象
|
|
15
|
+
*/
|
|
16
|
+
export const mergeObjects = <
|
|
17
|
+
T extends Record<string, any>,
|
|
18
|
+
U extends Record<string, any>,
|
|
19
|
+
>(
|
|
20
|
+
obj1: T,
|
|
21
|
+
obj2: U,
|
|
22
|
+
) => {
|
|
23
|
+
const result: Record<string, any> = { ...obj1 };
|
|
24
|
+
|
|
25
|
+
for (const key of Object.keys(obj2)) {
|
|
26
|
+
const val1 = result[key];
|
|
27
|
+
const val2 = obj2[key];
|
|
28
|
+
|
|
29
|
+
// 如果都是原始值,则用后者覆盖
|
|
30
|
+
if (isPrimitive(val1) && isPrimitive(val2)) {
|
|
31
|
+
result[key] = val2;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 如果都是数组,则拼接为大数组
|
|
36
|
+
if (Array.isArray(val1) && Array.isArray(val2)) {
|
|
37
|
+
result[key] = val1.concat(val2);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 如果都是对象,则深度递归合并
|
|
42
|
+
if (isObject(val1) && isObject(val2)) {
|
|
43
|
+
result[key] = mergeObjects(val1, val2);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 如果类型不同,则用后者覆盖
|
|
48
|
+
result[key] = val2;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return result as T & U;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// --- mapKeys ---
|
|
55
|
+
|
|
56
|
+
// 这里的 DeepMapKeys 只能承诺 key 是 string,无法推断出 key 的具体字面量变化
|
|
57
|
+
// 因为 TS 不支持根据任意函数反推 Key 的字面量类型
|
|
58
|
+
export type DeepMapKeys<T> =
|
|
59
|
+
T extends Array<infer U>
|
|
60
|
+
? Array<DeepMapKeys<U>>
|
|
61
|
+
: T extends object
|
|
62
|
+
? { [key: string]: DeepMapKeys<T[keyof T]> }
|
|
63
|
+
: T;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 递归处理对象里的 key
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* 无法完整推导出类型,只能做到有递归,key 全为 string,value 为同层级的所有类型的联合
|
|
70
|
+
*
|
|
71
|
+
* @template T 要转换的对象
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const obj = { a: { b: 1 } };
|
|
75
|
+
* const result = mapKeys(obj, (key) => key.toUpperCase());
|
|
76
|
+
* console.log(result); // { A: { B: 1 } }
|
|
77
|
+
*/
|
|
78
|
+
export const mapKeys = <T>(
|
|
79
|
+
obj: T,
|
|
80
|
+
getNewKey: (key: string) => string,
|
|
81
|
+
): DeepMapKeys<T> => {
|
|
82
|
+
// 递归处理数组
|
|
83
|
+
if (Array.isArray(obj)) {
|
|
84
|
+
return obj.map((item) => mapKeys(item, getNewKey)) as any;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 处理普通对象
|
|
88
|
+
if (isObject(obj)) {
|
|
89
|
+
const keys = Object.keys(obj);
|
|
90
|
+
return keys.reduce(
|
|
91
|
+
(result, key) => {
|
|
92
|
+
const newKey = getNewKey(key);
|
|
93
|
+
const value = (obj as any)[key];
|
|
94
|
+
result[newKey] = mapKeys(value, getNewKey);
|
|
95
|
+
return result;
|
|
96
|
+
},
|
|
97
|
+
{} as Record<string, any>,
|
|
98
|
+
) as DeepMapKeys<T>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 处理非数组/对象
|
|
102
|
+
return obj as any;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// --- mapValues ---
|
|
106
|
+
|
|
107
|
+
// 这里的 DeepMapValues 尝试保留 key,但将 value 类型替换为 R
|
|
108
|
+
// 注意:如果原 value 是对象,我们递归处理结构,而不是把整个对象变成 R
|
|
109
|
+
export type DeepMapValues<T, R> =
|
|
110
|
+
T extends Array<infer U>
|
|
111
|
+
? Array<DeepMapValues<U, R>>
|
|
112
|
+
: T extends object
|
|
113
|
+
? { [K in keyof T]: T[K] extends object ? DeepMapValues<T[K], R> : R }
|
|
114
|
+
: R;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 递归处理对象里的 value
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* 无法完整推导出类型,所有 value 最终都会变为 any
|
|
121
|
+
*
|
|
122
|
+
* @template T 要转换的对象
|
|
123
|
+
* @template R 转换后的值类型,为 any,无法进一步推导
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* const obj = { a: 1, b: { c: 2 } };
|
|
127
|
+
* const result = mapValues(obj, (value, key) => isPrimitive(value) ? value + 1 : value);
|
|
128
|
+
* console.log(result); // { a: 2, b: { c: 3 } }
|
|
129
|
+
*/
|
|
130
|
+
export const mapValues = <T, R = any>(
|
|
131
|
+
obj: T,
|
|
132
|
+
getNewValue: (value: any, key: string | number) => R,
|
|
133
|
+
): DeepMapValues<T, R> => {
|
|
134
|
+
// 处理数组
|
|
135
|
+
if (Array.isArray(obj)) {
|
|
136
|
+
return obj.map((item, index) => {
|
|
137
|
+
// 如果元素是对象,则递归处理
|
|
138
|
+
if (isObject(item)) {
|
|
139
|
+
return mapValues(item, getNewValue);
|
|
140
|
+
}
|
|
141
|
+
// 如果元素是原始值,则直接应用 getNewValue(此时 key 为数组下标)
|
|
142
|
+
return getNewValue(item, index);
|
|
143
|
+
}) as any;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// 处理普通对象
|
|
147
|
+
if (isObject(obj)) {
|
|
148
|
+
const keys = Object.keys(obj);
|
|
149
|
+
return keys.reduce((result, key) => {
|
|
150
|
+
const value = (obj as any)[key];
|
|
151
|
+
// 如果值为对象或数组,则递归处理
|
|
152
|
+
if (!isPrimitive(value)) {
|
|
153
|
+
result[key] = mapValues(value, getNewValue);
|
|
154
|
+
}
|
|
155
|
+
// 否则直接应用 getNewValue
|
|
156
|
+
else {
|
|
157
|
+
result[key] = getNewValue(value, key);
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}, {} as any) as DeepMapValues<T, R>;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 处理非数组/对象
|
|
164
|
+
return obj as any;
|
|
165
|
+
};
|
package/src/string.ts
CHANGED
|
@@ -1,22 +1,42 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* snakeToCamel("user_name") // 'userName'
|
|
6
|
-
*/
|
|
7
|
-
export const snakeToCamel = (str: string) => {
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* camelToSnake("shouldComponentUpdate") // 'should_component_update'
|
|
16
|
-
*/
|
|
17
|
-
export const camelToSnake = (str: string) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* 下划线命名法转为驼峰命名法
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* snakeToCamel("user_name") // 'userName'
|
|
6
|
+
*/
|
|
7
|
+
export const snakeToCamel = (str: string) => {
|
|
8
|
+
return str.replace(/_([a-zA-Z])/g, (match, pattern) => pattern.toUpperCase());
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 驼峰命名法转为下划线命名法
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* camelToSnake("shouldComponentUpdate") // 'should_component_update'
|
|
16
|
+
*/
|
|
17
|
+
export const camelToSnake = (str: string) => {
|
|
18
|
+
return str.replace(
|
|
19
|
+
/([A-Z])/g,
|
|
20
|
+
(match, pattern) => `_${pattern.toLowerCase()}`,
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 字符串首字母大写
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* capitalize("hello") // 'Hello'
|
|
29
|
+
*/
|
|
30
|
+
export const capitalize = (s: string) => {
|
|
31
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 字符串首字母小写
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* decapitalize("Hello") // 'hello'
|
|
39
|
+
*/
|
|
40
|
+
export const decapitalize = (s: string) => {
|
|
41
|
+
return s.charAt(0).toLowerCase() + s.slice(1);
|
|
42
|
+
};
|
package/src/time.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 延迟一段时间再执行后续代码
|
|
3
|
-
* @param time 延迟时间,默认 150ms
|
|
4
|
-
* @example
|
|
5
|
-
* await sleep(1000); // 等待 1 秒执行后续代码
|
|
6
|
-
*/
|
|
7
|
-
export const sleep = async (time = 150) => {
|
|
8
|
-
return new Promise((resolve) => {
|
|
9
|
-
setTimeout(resolve, time);
|
|
10
|
-
});
|
|
11
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* 延迟一段时间再执行后续代码
|
|
3
|
+
* @param time 延迟时间,默认 150ms
|
|
4
|
+
* @example
|
|
5
|
+
* await sleep(1000); // 等待 1 秒执行后续代码
|
|
6
|
+
*/
|
|
7
|
+
export const sleep = async (time = 150) => {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
setTimeout(resolve, time);
|
|
10
|
+
});
|
|
11
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
// Environment setup & latest features
|
|
4
|
-
"lib": ["ESNext", "DOM"],
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "Preserve",
|
|
7
|
-
"moduleDetection": "force",
|
|
8
|
-
"jsx": "react-jsx",
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
|
|
11
|
-
// Bundler mode
|
|
12
|
-
"moduleResolution": "bundler",
|
|
13
|
-
"allowImportingTsExtensions": true,
|
|
14
|
-
"verbatimModuleSyntax": true,
|
|
15
|
-
"outDir": "dist",
|
|
16
|
-
"declaration": true,
|
|
17
|
-
"emitDeclarationOnly": true,
|
|
18
|
-
|
|
19
|
-
// Best practices
|
|
20
|
-
"strict": true,
|
|
21
|
-
"skipLibCheck": true,
|
|
22
|
-
"noFallthroughCasesInSwitch": true,
|
|
23
|
-
"noUncheckedIndexedAccess": true,
|
|
24
|
-
"noImplicitOverride": true,
|
|
25
|
-
|
|
26
|
-
// Some stricter flags (disabled by default)
|
|
27
|
-
"noUnusedLocals": false,
|
|
28
|
-
"noUnusedParameters": false,
|
|
29
|
-
"noPropertyAccessFromIndexSignature": false
|
|
30
|
-
},
|
|
31
|
-
"include": ["src"]
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": ["ESNext", "DOM"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "Preserve",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
|
|
11
|
+
// Bundler mode
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": true,
|
|
15
|
+
"outDir": "dist",
|
|
16
|
+
"declaration": true,
|
|
17
|
+
"emitDeclarationOnly": true,
|
|
18
|
+
|
|
19
|
+
// Best practices
|
|
20
|
+
"strict": true,
|
|
21
|
+
"skipLibCheck": true,
|
|
22
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
|
+
"noUncheckedIndexedAccess": true,
|
|
24
|
+
"noImplicitOverride": true,
|
|
25
|
+
|
|
26
|
+
// Some stricter flags (disabled by default)
|
|
27
|
+
"noUnusedLocals": false,
|
|
28
|
+
"noUnusedParameters": false,
|
|
29
|
+
"noPropertyAccessFromIndexSignature": false
|
|
30
|
+
},
|
|
31
|
+
"include": ["src"]
|
|
32
|
+
}
|