lib/flightstats.js
function( options, callback ) {

    if( typeof options === 'function' ) {
      callback = options
      options = null
    }

    options = options != null ? options : {}

    var self = this
    var baseUrl = 'airlines/rest/v1/json'
    var isCode = options.fs || options.iata || options.icao
    var supportsDate = !options.all || isCode

    if( !options.all && !isCode ) {
      baseUrl += '/active'
    } else if( !isCode ) {
      baseUrl += '/all'
    }

    if( options.fs ) {
      baseUrl += '/fs/' + options.fs
    } else if( options.iata ) {
      baseUrl += '/iata/' + options.iata
    } else if( options.icao ) {
      baseUrl += '/icao/' + options.icao
    }

    if( options.date && supportsDate ) {

      var year = options.date.getFullYear()
      var month = options.date.getMonth() + 1
      var day = options.date.getDate()

      baseUrl += '/' + year + '/' + month + '/' + day

    }

    return this._clientRequest({
      url: baseUrl,
      extendedOptions: [
        'includeNewFields'
      ],
    }, function( error, data ) {

      if( error != null )
        return callback.call( self, error )

      var airlines = [].concat( data.airlines || data.airline || [] )

      // Trim excessive whitespace in airline names
      airlines.forEach( function( airline ) {
        airline.name = airline.name.replace( /^\s|\s$/g, '' )
      })

      // Expand the airline category to a detailed object
      if( options.expandCategory ) {
        airlines.forEach( function( airline ) {

          var info = FlightStats.AirlineCategory[ airline.category ]

          airline.category = {
            code: ( info && info.code ) || airline.category,
            scheduled: info && info.scheduled,
            passenger: info && info.passenger,
            cargo: info && info.cargo,
          }

        })
      }

      callback.call( self, error, airlines )

    })

  }
function( options, callback ) {

    if( typeof options === 'function' ) {
      callback = options
      options = null
    }

    options = options != null ? options : {}

    var self = this
    var baseUrl = 'airlines/rest/v1/json'
    var isCode = options.fs || options.iata || options.icao
    var supportsDate = !options.all || isCode

    if( !options.all && !isCode ) {
      baseUrl += '/active'
    } else if( !isCode ) {
      baseUrl += '/all'
    }

    if( options.fs ) {
      baseUrl += '/fs/' + options.fs
    } else if( options.iata ) {
      baseUrl += '/iata/' + options.iata
    } else if( options.icao ) {
      baseUrl += '/icao/' + options.icao
    }

    if( options.date && supportsDate ) {

      var year = options.date.getFullYear()
      var month = options.date.getMonth() + 1
      var day = options.date.getDate()

      baseUrl += '/' + year + '/' + month + '/' + day

    }

    return this._clientRequest({
      url: baseUrl,
      extendedOptions: [
        'includeNewFields'
      ],
    }, function( error, data ) {

      if( error != null )
        return callback.call( self, error )

      var airlines = [].concat( data.airlines || data.airline || [] )

      // Trim excessive whitespace in airline names
      airlines.forEach( function( airline ) {
        airline.name = airline.name.replace( /^\s|\s$/g, '' )
      })

      // Expand the airline category to a detailed object
      if( options.expandCategory ) {
        airlines.forEach( function( airline ) {

          var info = FlightStats.AirlineCategory[ airline.category ]

          airline.category = {
            code: ( info && info.code ) || airline.category,
            scheduled: info && info.scheduled,
            passenger: info && info.passenger,
            cargo: info && info.cargo,
          }

        })
      }

      callback.call( self, error, airlines )

    })

  }
function ( options , callback ) { if ( typeof options === 'function' ) { callback = options options = null } options = options != null ? options : { } var self = this var baseUrl = 'airlines/rest/v1/json' var isCode = options . fs || options . iata || options . icao var supportsDate = ! options . all || isCode if ( ! options . all && ! isCode ) { baseUrl += '/active' } else if ( ! isCode ) { baseUrl += '/all' } if ( options . fs ) { baseUrl += '/fs/' + options . fs } else if ( options . iata ) { baseUrl += '/iata/' + options . iata } else if ( options . icao ) { baseUrl += '/icao/' + options . icao } if ( options . date && supportsDate ) { var year = options . date . getFullYear ( ) var month = options . date . getMonth ( ) + 1 var day = options . date . getDate ( ) baseUrl += '/' + year + '/' + month + '/' + day } return this . _clientRequest ( { url : baseUrl , extendedOptions : [ 'includeNewFields' ] , } , function ( error , data ) { if ( error != null ) return callback . call ( self , error ) var airlines = [ ] . concat ( data . airlines || data . airline || [ ] ) // Trim excessive whitespace in airline names airlines . forEach ( function ( airline ) { airline . name = airline . name . replace ( / ^\s|\s$ / g , '' ) } ) // Expand the airline category to a detailed object if ( options . expandCategory ) { airlines . forEach ( function ( airline ) { var info = FlightStats . AirlineCategory [ airline . category ] airline . category = { code : ( info && info . code ) || airline . category , scheduled : info && info . scheduled , passenger : info && info . passenger , cargo : info && info . cargo , } } ) } callback . call ( self , error , airlines ) } ) }
Retrieve a list of airlines
@param {Object} options
@param {Boolean} [options.all=false] optional
@param {?Date} [options.date] optional
@param {?String} [options.iata] optional
@param {?String} [options.icao] optional
@param {?String} [options.fs] optional
@param {Function} callback
@return {Request}
Retrieve a list of airlines