1
- import { ComponentPublicInstance , h , VNode } from " vue" ;
1
+ import { ComponentPublicInstance , h , VNode } from ' vue' ;
2
2
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
4
export type KeyHash = { [ key : string ] : any } ;
4
5
5
- const camelizeRE = / - ( \w ) / g
6
+ const camelizeRE = / - ( \w ) / g;
6
7
export const camelize = ( str : string ) : string => {
7
- return str . replace ( camelizeRE , ( _ , c ) => c ? c . toUpperCase ( ) : '' )
8
- }
8
+ return str . replace ( camelizeRE , ( _ , c ) => ( c ? c . toUpperCase ( ) : '' ) ) ;
9
+ } ;
9
10
10
- const hyphenateRE = / \B ( [ A - Z ] ) / g
11
+ const hyphenateRE = / \B ( [ A - Z ] ) / g;
11
12
export const hyphenate = ( str : string ) : string => {
12
- return str . replace ( hyphenateRE , '-$1' ) . toLowerCase ( )
13
- }
13
+ return str . replace ( hyphenateRE , '-$1' ) . toLowerCase ( ) ;
14
+ } ;
14
15
15
16
export function setInitialProps ( propsList : string [ ] ) : KeyHash {
16
- const res : KeyHash = { }
17
+ const res : KeyHash = { } ;
17
18
propsList . forEach ( key => {
18
- res [ key ] = undefined
19
- } )
20
- return res
21
- }
22
-
23
- export function injectHook ( options : KeyHash , key : string , hook : Function ) {
24
- options [ key ] = [ ] . concat ( options [ key ] || [ ] )
25
- options [ key ] . unshift ( hook )
19
+ res [ key ] = undefined ;
20
+ } ) ;
21
+ return res ;
26
22
}
27
23
28
- export function callHooks ( vm : ComponentPublicInstance | undefined , hook : string ) {
24
+ export function callHooks ( vm : ComponentPublicInstance | undefined , hook : string ) : void {
29
25
if ( vm ) {
30
26
let hooks = vm . $options [ hook ] || [ ] ;
31
- if ( ! Array . isArray ( hooks ) ) {
27
+ if ( ! Array . isArray ( hooks ) ) {
32
28
hooks = [ hooks ] ;
33
29
}
34
- hooks . forEach ( ( hook : Function ) => {
30
+ hooks . forEach ( ( hook : ( ) => void ) : void => {
35
31
hook . call ( vm ) ;
36
32
} ) ;
37
33
}
38
34
}
39
35
40
- export function createCustomEvent ( name : string , args : any ) {
36
+ export function createCustomEvent ( name : string , args : unknown ) : CustomEvent {
41
37
return new CustomEvent ( name , {
42
38
bubbles : false ,
43
39
cancelable : false ,
44
40
detail : args
45
- } )
41
+ } ) ;
46
42
}
47
43
48
- const isBoolean = ( val : any ) => / f u n c t i o n B o o l e a n / . test ( String ( val ) ) ;
49
- const isNumber = ( val : any ) => / f u n c t i o n N u m b e r / . test ( String ( val ) ) ;
44
+ const isBoolean = ( val : unknown ) => / f u n c t i o n B o o l e a n / . test ( String ( val ) ) ;
45
+ const isNumber = ( val : unknown ) => / f u n c t i o n N u m b e r / . test ( String ( val ) ) ;
50
46
51
- export function convertAttributeValue ( value : any , name : string , { type } : { type ?: any } = { } ) {
47
+ export function convertAttributeValue (
48
+ value : unknown ,
49
+ name : string ,
50
+ { type } : { type ?: unknown } = { }
51
+ ) : unknown {
52
52
if ( isBoolean ( type ) ) {
53
53
if ( value === 'true' || value === 'false' ) {
54
54
return value === 'true' ;
@@ -58,14 +58,14 @@ export function convertAttributeValue (value: any, name: string, { type }: { typ
58
58
}
59
59
return value != null ;
60
60
} else if ( isNumber ( type ) ) {
61
- const parsed = parseFloat ( value ) ;
61
+ const parsed = parseFloat ( < string > value ) ;
62
62
return isNaN ( parsed ) ? value : parsed ;
63
63
} else {
64
64
return value ;
65
65
}
66
66
}
67
67
68
- export function toVNodes ( children : NodeListOf < ChildNode > ) : ( VNode | null ) [ ] {
68
+ export function toVNodes ( children : NodeListOf < ChildNode > ) : ( VNode | null ) [ ] {
69
69
const res : ( VNode | null ) [ ] = [ ] ;
70
70
71
71
for ( let i = 0 , l = children . length ; i < l ; i ++ ) {
@@ -75,11 +75,13 @@ export function toVNodes (children: NodeListOf<ChildNode>): (VNode | null)[] {
75
75
return res ;
76
76
}
77
77
78
- function toVNode ( node : any ) : VNode | null {
78
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
+ function toVNode ( node : any ) : VNode | null {
79
80
if ( node . nodeType === 3 ) {
80
81
return node . data . trim ( ) ? node . data : null ;
81
82
} else if ( node . nodeType === 1 ) {
82
- const data = {
83
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
+ const data : { attrs : any ; domProps : any ; slot ?: any } = {
83
85
attrs : getAttributes ( node ) ,
84
86
domProps : {
85
87
innerHTML : node . innerHTML
@@ -93,11 +95,11 @@ function toVNode (node: any): VNode | null {
93
95
94
96
return h ( node . tagName , data ) ;
95
97
} else {
96
- return null
98
+ return null ;
97
99
}
98
100
}
99
101
100
- function getAttributes ( node : any ) : KeyHash {
102
+ function getAttributes ( node : { attributes : { nodeName : string ; nodeValue : unknown } [ ] } ) : KeyHash {
101
103
const res : KeyHash = { } ;
102
104
for ( let i = 0 , l = node . attributes . length ; i < l ; i ++ ) {
103
105
const attr = node . attributes [ i ] ;
0 commit comments