@@ -11,6 +11,12 @@ const KlassName = process.argv[2]
11
11
fetch (
12
12
"https://developers.google.com/maps/documentation/javascript/3.exp/reference"
13
13
)
14
+ . then ( it => it . text ( ) )
15
+ . then ( it => cheerio . load ( it ) )
16
+ . then ( $ => {
17
+ const href = $ ( `#${ KlassName } a` ) . attr ( "href" )
18
+ return fetch ( href )
19
+ } )
14
20
. then ( it => it . text ( ) )
15
21
. then ( it => cheerio . load ( it ) )
16
22
. then ( $ => {
@@ -33,32 +39,25 @@ function contentToJS(KlassName, $, $content) {
33
39
const $constructorTable = $content . find (
34
40
`[summary="class ${ KlassName } - Constructor"]`
35
41
)
36
- const [ , constructorArgs ] = $constructorTable
37
- . find ( `tr > td > code` )
42
+ const constructorArgs = $constructorTable
43
+ . find ( `tbody .desc li code:first-child ` )
38
44
. text ( )
39
- . match ( / \S + \( ( .* ) \) / )
40
-
41
45
const $methodsTable = $content . find (
42
46
`[summary="class ${ KlassName } - Methods"]`
43
47
)
44
48
const methods = $methodsTable
45
49
. find ( "tbody > tr" )
46
50
. map ( ( i , tr ) => {
47
51
const $tr = $ ( tr )
48
- const [ , name , args ] = $tr
49
- . find ( "td:first-child" )
50
- . text ( )
51
- . replace ( "\n" , "" )
52
- . match ( / ( \S + ) \( ( .* ) \) / )
53
-
54
- const returnsDesc = toMarkdown (
55
- $tr . find ( "td:nth-child(2) > div.desc" ) . html ( )
56
- )
52
+ const name = $tr . find ( '[itemprop="property"]' ) . text ( )
53
+ const args = $tr . find ( '.desc:contains("Parameters") li' ) . text ( )
54
+ const returns = $tr . find ( '.desc:contains("Return Value") code' ) . text ( )
55
+ const returnsDesc = toMarkdown ( $tr . find ( ".desc:last-child" ) . html ( ) )
57
56
58
57
return {
59
58
name,
60
59
args,
61
- returns : $tr . find ( "td:nth-child(2) > div > code" ) . text ( ) ,
60
+ returns,
62
61
returnsDesc,
63
62
}
64
63
} )
0 commit comments