File tree 3 files changed +31
-26
lines changed 3 files changed +31
-26
lines changed Original file line number Diff line number Diff line change 2
2
var db = { }
3
3
4
4
// initialize with all the IANA types
5
- require ( '../src/iana.json' ) . forEach ( function ( mime ) {
6
- // i don't think the name is useful,
7
- // and i don't think we need to bother with the "Reference"
8
- // just look at the site yourself!
9
-
10
- var template = mime . template
11
-
12
- if ( ! template ) {
13
- // some types don't have a template, so we guess it
14
- console . log ( 'guessing: %s/%s' , mime . type , mime . name )
15
- template = mime . type + '/' + mime . name
16
- }
17
-
18
- if ( ! ~ template . indexOf ( '/' ) ) {
19
- // i don't know what templates exactly are,
20
- // but some aren't valid mime types.
21
- console . log ( 'prefixing: %s/%s' , mime . type , template )
22
- template = mime . type + '/' + template
23
- }
24
-
25
- db [ template . toLowerCase ( ) ] = {
26
- source : 'iana'
27
- }
5
+ var mime = require ( '../src/iana.json' )
6
+ Object . keys ( mime ) . forEach ( function ( type ) {
7
+ var d = mime [ type ]
8
+ var t = type . toLowerCase ( )
9
+ var o = db [ t ] = db [ t ] || { source : 'iana' }
28
10
} )
29
11
30
12
// add the mime extensions from Apache
Original file line number Diff line number Diff line change @@ -20,7 +20,22 @@ co(function* () {
20
20
get ( 'text' ) ,
21
21
]
22
22
23
- fs . writeFileSync ( 'src/iana.json' , JSON . stringify ( results . reduce ( concat , [ ] ) ) )
23
+ // flatten results
24
+ results = results . reduce ( concat , [ ] )
25
+
26
+ var json = { }
27
+ results . forEach ( function ( result ) {
28
+ var mime = result . mime
29
+
30
+ if ( mime in json && result . template !== json [ mime ] . template ) {
31
+ throw new Error ( 'duplicate entry for ' + mime )
32
+ }
33
+
34
+ delete result . mime
35
+ json [ mime ] = result
36
+ } )
37
+
38
+ fs . writeFileSync ( 'src/iana.json' , JSON . stringify ( json ) )
24
39
} ) ( )
25
40
26
41
function * get ( type ) {
@@ -34,7 +49,15 @@ function* get(type) {
34
49
35
50
return mimes . map ( function ( row ) {
36
51
var data = row . reduce ( reduceRows , { type : type } )
37
- if ( data . template !== type + '/example' ) return data
52
+
53
+ if ( data . template === type + '/example' ) {
54
+ return
55
+ }
56
+
57
+ // guess mime type
58
+ data . mime = ( data . template || ( type + '/' + data . name ) ) . toLowerCase ( )
59
+
60
+ return data
38
61
} )
39
62
}
40
63
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments