Source: bemap-services-v2/search/bemap-geo-autocomplete-v2.js

/**
 * BeNomad BeMap JavaScript API - GeoAutocomplete v1.5 extension
 *
 * Adds a Promise-based `autocomplete(request)` method to the existing
 * `bemap.GeoAutocomplete` prototype. Unlike `bemap.Autocomplete`, this path
 * forces `addressDetails: true` so each result carries a full
 * `bemap.PostalAddress` and (when the Worker can resolve it) a
 * `bemap.Coordinate`.
 *
 * The legacy jQuery-based `autocomplete(options, listener)` callback path
 * stays unchanged for retrocompat; dispatch is decided by the type of the
 * first argument.
 *
 * @since 1.5.0
 */
(function() {

    if (typeof bemap === 'undefined' || !bemap.GeoAutocomplete) return;

    bemap.GeoAutocomplete.prototype._v2 = function() {
        if (!this._v2Instance) {
            this._v2Instance = new bemap.ServiceV2(this.context, {});
        }
        return this._v2Instance;
    };

    var legacyAutocomplete = bemap.GeoAutocomplete.prototype.autocomplete;

    /**
     * @public
     * @param {bemap.AutocompleteGeocodingRequest|Object} request
     *   When a typed request is passed, a Promise is returned.
     *   Any other shape falls through to the legacy callback implementation.
     * @param {Object|Function} [options]
     * @return {Promise<bemap.AutocompleteGeocodingResponse>|undefined}
     */
    bemap.GeoAutocomplete.prototype.autocomplete = function(request, options) {
        if (!(request instanceof bemap.AutocompleteGeocodingRequest)) {
            return legacyAutocomplete.call(this, request, options);
        }
        var opts = options || {};
        var body = request.toJson();
        body.addressDetails = true;
        body.geoserver = opts.geoserver || this.geoserver
            || (this.context && this.context.getGeoserver && this.context.getGeoserver());

        return this._v2()._post('service/geocoding/autocomplete/1.0', body, opts)
            .then(function(json) {
                return bemap.AutocompleteGeocodingResponse.fromJson(json);
            });
    };

})();