File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -7,5 +7,6 @@ export * from './tools'
7
7
export * from './lodash-lite'
8
8
export * from './download'
9
9
export * from './to'
10
+ export * from './to/toPro'
10
11
export * from './log'
11
12
// export * from './browser'
Original file line number Diff line number Diff line change
1
+ import { getObjVal } from '../object'
2
+ import { isArray } from '../is'
3
+ import { to } from './index'
4
+
5
+ interface ValItem {
6
+ keys : string [ ]
7
+ valFormat ?: any
8
+ }
9
+
10
+ export async function toPro ( promise : Promise < T > , valList ?: ValItem [ ] ) {
11
+ const [ err , res ] = await to ( promise )
12
+ if ( err )
13
+ return [ err , undefined ]
14
+
15
+ if ( isArray ( valList ) ) {
16
+ const resObj = res as any
17
+ const dataList = [ ] as any
18
+ valList . forEach ( ( { keys, valFormat } ) => {
19
+ const valList = keys . map ( ( key ) => {
20
+ return getObjVal ( resObj , key )
21
+ } )
22
+ const tempVal = valFormat ? valFormat ( valList ) : valList
23
+ if ( isArray ( tempVal ) && tempVal . length === 1 && ! valFormat )
24
+ dataList . push ( tempVal [ 0 ] )
25
+ else
26
+ dataList . push ( tempVal )
27
+ } )
28
+ return [ undefined , dataList ]
29
+ }
30
+ else {
31
+ return [ undefined , res ]
32
+ }
33
+ }
34
+
35
+ export default {
36
+ toPro,
37
+ }
You can’t perform that action at this time.
0 commit comments