Skip to content

Commit 0031a6b

Browse files
author
maqiyang
committed
chore: 调整TS声明
1 parent b7cabc8 commit 0031a6b

File tree

4 files changed

+29
-31
lines changed

4 files changed

+29
-31
lines changed

.eslintrc.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,13 @@ module.exports = {
22
env: {
33
browser: true,
44
es6: true,
5-
node: true
5+
node: true,
66
},
77
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
88
parser: '@typescript-eslint/parser',
99
parserOptions: {
10-
sourceType: 'module'
10+
sourceType: 'module',
1111
},
1212
plugins: ['@typescript-eslint'],
13-
rules: {
14-
indent: [1, 4],
15-
'linebreak-style': [0, 'error', 'windows'],
16-
quotes: [1, 'single'],
17-
semi: [1, 'never'],
18-
'no-console': 'off',
19-
'max-classes-per-file': [1, 2]
20-
}
13+
rules: {},
2114
}

.prettierrc.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// 参考 https://prettier.io/docs/en/options.html
2+
3+
module.exports = {
4+
// 行最大长度
5+
printWidth: 100,
6+
// 使用单引号 是
7+
singleQuote: true,
8+
// 多行数组是否需要尾部追加逗号 es5 语法需要
9+
trailingComma: 'es5',
10+
// 箭头函数方法是否需要括号 是
11+
arrowParens: 'always',
12+
// 定义换行符 lf linux-style
13+
endOfLine: 'lf',
14+
};

src/storage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @author jdeseva
3-
* @date 2021.04.13
3+
* @date 2022.11.29
44
* @description 本地存储类 v2
55
* @homePage https://github.com/jsmini/util-tools
66
*/

src/utils.ts

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @author jdeseva
3-
* @date 2019.10.24
3+
* @date 2022.11.29
44
* @description 自用工具类函数,包含常用的自定义工具类函数,不定期整理更新。欢迎提出issue
55
* @homePage https://github.com/jsmini/util-tools
66
*/
@@ -74,17 +74,15 @@ export function __Throttle(method: Function, delay: number = 500): Function {
7474
* @param idKey {string} 主键
7575
* @returns {Array<object>} 返回的树形结构数据
7676
*/
77-
export function __ToTree(
78-
data: object[],
79-
parentIdKey: string,
80-
idKey: string = 'id'
81-
): object[] {
77+
export function __ToTree<T>( data: T[], parentIdKey: string, idKey: string = 'id'): T[] {
8278
let _idMap = Object.create(null)
83-
data.forEach((row: object): void => {
79+
80+
data.forEach((row: T): void => {
8481
_idMap[row[idKey]] = row
8582
})
86-
const result: object[] = []
87-
data.forEach((row: object): void => {
83+
const result: T[] = []
84+
85+
data.forEach((row: T): void => {
8886
let parent = _idMap[row[parentIdKey]]
8987
if (parent) {
9088
let v = parent.children || (parent.children = [])
@@ -103,11 +101,7 @@ export function __ToTree(
103101
* @param {String} [val = value] 键值
104102
* @returns {Array<Object>} 返回数组
105103
*/
106-
export function __MapToArray(
107-
map: object,
108-
key: string = 'name',
109-
val: string = 'value'
110-
): object[] {
104+
export function __MapToArray<T>( map: Record<string, T>, key: string = 'name', val: string = 'value'): T[] {
111105
let res = []
112106
for (let k in map) {
113107
var temp = Object.create(null)
@@ -125,13 +119,10 @@ export function __MapToArray(
125119
* @param {String} [val = value] 键值
126120
* @returns {Object} 返回map对象字典
127121
*/
128-
export function __ArrayToMap(
129-
array: object[],
130-
key: string = 'name',
131-
val: string = 'value'
132-
): object {
122+
export function __ArrayToMap<T>( array: Record<string, T>[], key: string = 'name', val: string = 'value'): Record<string, T> {
133123
var res = Object.create(null) // 新建一个纯粹对象
134-
array.forEach((row: object): void => {
124+
125+
array.forEach((row: Record<string, T>): void => {
135126
res[row[key]] = row[val]
136127
})
137128
return res

0 commit comments

Comments
 (0)