Source: bemap-services-v2/search/bemap-near-poi-response.js

/**
 * BeNomad BeMap JavaScript API - NearPoiResponse
 *
 * Container for the list of `NearPoint` items returned by
 * `bemap.NearPoiSearch.nearPoi()`.
 *
 * Wire shape from the BeMap server — confirmed by a real
 * `POST service/nearpoi/1.0` response on bemap-beta.benomad.com:
 *
 *   {
 *     "pois": [
 *       { coordinate: {lon, lat}, distance, duration, type, name, telephone },
 *       ...
 *     ]
 *   }
 *
 * `fromJson` reads `pois` first, then tolerates a bare root array and the
 * `points` / `items` / `results` wrappers as fallbacks, so consumer code
 * survives if the server tweaks the field name.
 *
 * @since 1.5.0
 * @public
 * @constructor
 * @param {Object} [options]
 * @param {Array.<bemap.NearPoint>} [options.points]
 */
bemap.NearPoiResponse = function(options) {
    var opts = options || {};
    this.points = Array.isArray(opts.points) ? opts.points : [];
};

bemap.NearPoiResponse.prototype.getPoints = function() {
    return this.points;
};

bemap.NearPoiResponse.prototype.size = function() {
    return this.points.length;
};

/**
 * Convenience: return only POIs whose `type` matches one of the values in
 * the supplied list. Pass a single string or an Array of strings.
 *
 * @public
 * @param {String|Array.<String>} typeOrTypes
 * @return {Array.<bemap.NearPoint>}
 */
bemap.NearPoiResponse.prototype.getPointsByType = function(typeOrTypes) {
    var set = Array.isArray(typeOrTypes) ? typeOrTypes : [typeOrTypes];
    return this.points.filter(function(p) {
        return set.indexOf(p.getType()) >= 0;
    });
};

bemap.NearPoiResponse.fromJson = function(json) {
    var resp = new bemap.NearPoiResponse();
    if (!json) return resp;

    // Server-authoritative wrapper is `pois`. The other shapes are
    // tolerance fallbacks for older fixtures and future server tweaks.
    var raw = null;
    if (Array.isArray(json.pois)) raw = json.pois;
    else if (Array.isArray(json)) raw = json;
    else if (Array.isArray(json.points)) raw = json.points;
    else if (Array.isArray(json.items)) raw = json.items;
    else if (Array.isArray(json.results)) raw = json.results;

    if (!raw) return resp;

    for (var i = 0; i < raw.length; i++) {
        resp.points.push(bemap.NearPoint.fromJson(raw[i]));
    }
    return resp;
};