@@ -87,19 +87,20 @@ HTTPSnippet.prototype._matchTarget = function (familyName, target) {
8787 if ( typeof family === 'function' ) {
8888 return family ;
8989 }
90- // find the first possibel target
91- var firstTarget = Object . keys ( family ) . pop ( ) ;
90+
91+ // find the first default target
92+ var defaultTarget = family . _familyInfo ( ) . default ;
9293
9394 // shorthand
9495 if ( ! target || typeof target === 'object' ) {
95- target = firstTarget ;
96+ target = defaultTarget ;
9697 }
9798
9899 // asking for a particular target
99100 if ( typeof target === 'string' ) {
100101 // attempt to call the first one we find
101102 if ( typeof family [ target ] !== 'function' ) {
102- target = firstTarget ;
103+ target = defaultTarget ;
103104 }
104105
105106 // last chance
@@ -119,12 +120,61 @@ module.exports._targets = function () {
119120 return Object . keys ( targets ) ;
120121} ;
121122
123+ module . exports . _familyInfo = function ( family ) {
124+ if ( targets [ family ] && targets [ family ] . _familyInfo ) {
125+ return targets [ family ] . _familyInfo ( ) ;
126+ }
127+
128+ return false ;
129+ } ;
130+
122131module . exports . info = function ( family , target ) {
123- var result = HTTPSnippet . prototype . _matchTarget . call ( null , family , target ) ;
132+ if ( ! targets [ family ] ) {
133+ return false ;
134+ }
124135
125- if ( result ) {
126- return result . info ( ) ;
136+ if ( typeof targets [ family ] === 'function' ) {
137+ return targets [ family ] . info ( ) ;
127138 }
128139
129- return false ;
140+ // get all info for all family members
141+ if ( ! target && typeof targets [ family ] === 'object' ) {
142+ var results = {
143+ family : family
144+ } ;
145+
146+ results . members = Object . keys ( targets [ family ] )
147+ . filter ( function ( key ) {
148+ return key !== '_familyInfo' ;
149+ } )
150+
151+ . map ( function ( target ) {
152+ var info = targets [ family ] [ target ] . info ( ) ;
153+
154+ delete info . family ;
155+
156+ return info ;
157+ } ) ;
158+
159+ return results ;
160+ }
161+
162+ if ( typeof targets [ family ] === 'object' && typeof targets [ family ] [ target ] === 'function' ) {
163+ return targets [ family ] [ target ] . info ( ) ;
164+ }
165+ } ;
166+
167+ module . exports . extname = function ( family , target ) {
168+ if ( ! targets [ family ] ) {
169+ return '' ;
170+ }
171+
172+ if ( typeof targets [ family ] === 'function' ) {
173+ return targets [ family ] . info ( ) . extname ;
174+ }
175+
176+ // get all info for all family members
177+ if ( ! target && typeof targets [ family ] === 'object' ) {
178+ return targets [ family ] . _familyInfo ( ) . extname ;
179+ }
130180} ;
0 commit comments