1- 'use strict' ;
1+ 'use strict'
22
3- var fs = require ( 'fs' ) ;
4- var https = require ( 'https' ) ;
5- var bail = require ( 'bail' ) ;
6- var concat = require ( 'concat-stream' ) ;
7- var alphaSort = require ( 'alpha-sort' ) ;
8- var unified = require ( 'unified' ) ;
9- var parse = require ( 'rehype-parse' ) ;
10- var q = require ( 'hast-util-select' ) ;
11- var toString = require ( 'hast-util-to-string' ) ;
12- var ev = require ( 'hast-util-is-event-handler' ) ;
3+ var fs = require ( 'fs' )
4+ var https = require ( 'https' )
5+ var bail = require ( 'bail' )
6+ var concat = require ( 'concat-stream' )
7+ var alphaSort = require ( 'alpha-sort' )
8+ var unified = require ( 'unified' )
9+ var parse = require ( 'rehype-parse' )
10+ var q = require ( 'hast-util-select' )
11+ var toString = require ( 'hast-util-to-string' )
12+ var ev = require ( 'hast-util-is-event-handler' )
1313
14- var actual = 0 ;
15- var expected = 3 ;
14+ var proc = unified ( ) . use ( parse )
1615
17- var all = { } ;
16+ var actual = 0
17+ var expected = 3
1818
19- /* Crawl SVG 1.1. */
20- https . get ( 'https://www.w3.org/TR/SVG/attindex.html' , function ( res ) {
21- res . pipe ( concat ( onconcat ) ) . on ( 'error' , bail ) ;
19+ var all = { }
20+
21+ https . get ( 'https://www.w3.org/TR/SVG/attindex.html' , onsvg1 )
22+ https . get ( 'https://www.w3.org/TR/SVGTiny12/attributeTable.html' , ontiny )
23+ https . get ( 'https://www.w3.org/TR/SVG2/attindex.html' , onsvg2 )
24+
25+ function onsvg1 ( res ) {
26+ res . pipe ( concat ( onconcat ) ) . on ( 'error' , bail )
2227
2328 function onconcat ( buf ) {
24- var tree = unified ( ) . use ( parse ) . parse ( buf ) ;
25- var map = { } ;
29+ var tree = proc . parse ( buf )
30+ var map = { }
2631
27- q . selectAll ( '.property-table tr' , tree ) . forEach ( each ) ;
32+ q . selectAll ( '.property-table tr' , tree ) . forEach ( each )
2833
29- done ( map ) ;
34+ done ( map )
3035
3136 function each ( node ) {
32- var elements = q . selectAll ( '.element-name' , node ) ;
37+ var elements = q . selectAll ( '.element-name' , node )
3338
34- q . selectAll ( '.attr-name' , node ) . forEach ( every ) ;
39+ q . selectAll ( '.attr-name' , node ) . forEach ( every )
3540
3641 function every ( name ) {
3742 elements
3843 . map ( toString )
3944 . map ( clean )
40- . forEach ( add ( map , clean ( toString ( name ) ) ) ) ;
45+ . forEach ( add ( map , clean ( toString ( name ) ) ) )
4146 }
4247 }
4348
4449 function clean ( value ) {
45- return value . replace ( / [ ‘ ’ ] / g, '' ) ;
50+ return value . replace ( / [ ‘ ’ ] / g, '' )
4651 }
4752 }
48- } ) ;
53+ }
4954
50- /* Crawl SVG Tiny 1.2. */
51- https . get ( 'https://www.w3.org/TR/SVGTiny12/attributeTable.html' , function ( res ) {
52- res . pipe ( concat ( onconcat ) ) . on ( 'error' , bail ) ;
55+ function ontiny ( res ) {
56+ res . pipe ( concat ( onconcat ) ) . on ( 'error' , bail )
5357
5458 function onconcat ( buf ) {
55- var tree = unified ( ) . use ( parse ) . parse ( buf ) ;
56- var map = { } ;
59+ var tree = proc . parse ( buf )
60+ var map = { }
5761
58- q . selectAll ( '#attributes .attribute' , tree ) . forEach ( each ) ;
62+ q . selectAll ( '#attributes .attribute' , tree ) . forEach ( each )
5963
60- done ( map ) ;
64+ done ( map )
6165
6266 function each ( node ) {
6367 q
6468 . selectAll ( '.element' , node )
6569 . map ( toString )
66- . forEach ( add ( map , toString ( q . select ( '.attribute-name' , node ) ) ) ) ;
70+ . forEach ( add ( map , toString ( q . select ( '.attribute-name' , node ) ) ) )
6771 }
6872 }
69- } ) ;
73+ }
7074
71- /* Crawl SVG 2. */
72- https . get ( 'https://www.w3.org/TR/SVG2/attindex.html' , function ( res ) {
73- res . pipe ( concat ( onconcat ) ) . on ( 'error' , bail ) ;
75+ function onsvg2 ( res ) {
76+ res . pipe ( concat ( onconcat ) ) . on ( 'error' , bail )
7477
7578 function onconcat ( buf ) {
76- var tree = unified ( ) . use ( parse ) . parse ( buf ) ;
77- var map = { } ;
79+ var tree = proc . parse ( buf )
80+ var map = { }
7881
79- q . selectAll ( 'tbody tr' , tree ) . forEach ( each ) ;
82+ q . selectAll ( 'tbody tr' , tree ) . forEach ( each )
8083
81- done ( map ) ;
84+ done ( map )
8285
8386 function each ( node ) {
8487 q
8588 . selectAll ( '.element-name span' , node )
8689 . map ( toString )
87- . forEach ( add ( map , toString ( q . select ( '.attr-name span' , node ) ) ) ) ;
90+ . forEach ( add ( map , toString ( q . select ( '.attr-name span' , node ) ) ) )
8891 }
8992 }
90- } ) ;
93+ }
9194
92- // / * Add a map. */
95+ /* Add a map. */
9396function done ( map ) {
94- merge ( all , clean ( map ) ) ;
95- cleanAll ( all ) ;
97+ merge ( all , clean ( map ) )
98+ cleanAll ( all )
9699
97- actual ++ ;
100+ actual ++
98101
99102 if ( actual === expected ) {
100- fs . writeFile ( 'index.json' , JSON . stringify ( sort ( all ) , 0 , 2 ) + '\n' , bail ) ;
103+ fs . writeFile ( 'index.json' , JSON . stringify ( sort ( all ) , 0 , 2 ) + '\n' , bail )
101104 }
102105}
103106
@@ -110,112 +113,108 @@ function add(map, name) {
110113 name . slice ( 0 , 4 ) === 'xml:' ||
111114 name . slice ( 0 , 6 ) === 'xlink:'
112115 ) {
113- return noop ;
116+ return noop
114117 }
115118
116- return fn ;
119+ return fn
117120
118121 function fn ( tagName ) {
119- var attributes = map [ tagName ] || ( map [ tagName ] = [ ] ) ;
122+ var attributes = map [ tagName ] || ( map [ tagName ] = [ ] )
120123
121124 if ( attributes . indexOf ( name ) === - 1 ) {
122- attributes . push ( name ) ;
125+ attributes . push ( name )
123126 }
124127 }
125128
126129 function noop ( ) { }
127130}
128131
129132function clean ( map ) {
130- var result = { } ;
131- var list = [ ] ;
132- var globals = [ ] ;
133+ var result = { }
134+ var list = [ ]
135+ var globals = [ ]
133136
134137 /* Find all used attributes. */
135- Object . keys ( map ) . forEach ( function ( tagName ) {
136- map [ tagName ] . forEach ( function ( attribute ) {
138+ Object . keys ( map ) . forEach ( function ( tagName ) {
139+ map [ tagName ] . forEach ( function ( attribute ) {
137140 if ( list . indexOf ( attribute ) === - 1 ) {
138- list . push ( attribute ) ;
141+ list . push ( attribute )
139142 }
140- } ) ;
141- } ) ;
143+ } )
144+ } )
142145
143146 /* Find global attributes. */
144- list . forEach ( function ( attribute ) {
145- var global = true ;
146- var key ;
147+ list . forEach ( function ( attribute ) {
148+ var global = true
149+ var key
147150
148151 for ( key in map ) {
149152 if ( map [ key ] . indexOf ( attribute ) === - 1 ) {
150- global = false ;
151- break ;
153+ global = false
154+ break
152155 }
153156 }
154157
155158 if ( global ) {
156- globals . push ( attribute ) ;
159+ globals . push ( attribute )
157160 }
158- } ) ;
161+ } )
159162
160163 /* Remove globals. */
161164 result = {
162165 '*' : globals
163- } ;
166+ }
164167
165168 Object . keys ( map )
166169 . sort ( )
167- . forEach ( function ( tagName ) {
170+ . forEach ( function ( tagName ) {
168171 var attributes = map [ tagName ]
169- . filter ( function ( attribute ) {
170- return globals . indexOf ( attribute ) === - 1 ;
172+ . filter ( function ( attribute ) {
173+ return globals . indexOf ( attribute ) === - 1
171174 } )
172- . sort ( ) ;
175+ . sort ( )
173176
174177 if ( attributes . length !== 0 ) {
175- result [ tagName ] = attributes ;
178+ result [ tagName ] = attributes
176179 }
177- } ) ;
180+ } )
178181
179- return result ;
182+ return result
180183}
181184
182185function merge ( left , right ) {
183- Object . keys ( right ) . forEach ( each ) ;
186+ Object . keys ( right ) . forEach ( each )
184187
185188 function each ( tagName ) {
186189 left [ tagName ] = ( left [ tagName ] || [ ] )
187190 . concat ( right [ tagName ] )
188- . filter ( function ( attribute , index , list ) {
189- return list . indexOf ( attribute ) === index ;
191+ . filter ( function ( attribute , index , list ) {
192+ return list . indexOf ( attribute ) === index
190193 } )
191- . sort ( ) ;
194+ . sort ( )
192195 }
193196}
194197
195198function cleanAll ( map ) {
196- var globals = map [ '*' ] ;
197-
198- Object
199- . keys ( map )
200- . forEach ( function ( tagName ) {
201- if ( tagName !== '*' ) {
202- map [ tagName ] = map [ tagName ]
203- . filter ( function ( attribute ) {
204- return globals . indexOf ( attribute ) === - 1 ;
205- } ) ;
206- }
207- } ) ;
199+ var globals = map [ '*' ]
200+
201+ Object . keys ( map ) . forEach ( function ( tagName ) {
202+ if ( tagName !== '*' ) {
203+ map [ tagName ] = map [ tagName ] . filter ( function ( attribute ) {
204+ return globals . indexOf ( attribute ) === - 1
205+ } )
206+ }
207+ } )
208208}
209209
210210function sort ( map ) {
211- var result = { } ;
211+ var result = { }
212212
213- Object
214- . keys ( map )
213+ Object . keys ( map )
215214 . sort ( alphaSort . asc )
216- . forEach ( function ( key ) {
217- result [ key ] = map [ key ] ;
218- } ) ;
215+ . forEach ( function ( key ) {
216+ result [ key ] = map [ key ]
217+ } )
219218
220- return result ;
219+ return result
221220}
0 commit comments