User:Dorumin/api.​js

// An API library that doesn't suck.  window.api = {};

api.api = new mw.Api; api.step = 500;

api.get = function(params, raw) { return api.api.get($.extend({ action: 'query', }, params)) .then(function(d) {       if (raw) return d;        return d[params.action || 'query'];    }) };

api.query = function(params) { return api.get(params); };

api._callagain = function(params, offset, sum) { return api.get($.extend(params, { offset: offset }), true).then(function(results) {       var cont = results['query-continue'] || results['continue'];

sum = sum.concat(Object.values(results[params.action || 'query'])[0]);

if (!cont) { return sum; }

return api._callagain(params, offset + api.step, sum); }); };

api.query.recursive = function(params) { return api._callagain(params, 0, []); };

api.sequence = function(list, fn, index, sum) { index = index || 0; sum = sum || []; return api.get(fn(list[index])).then(function(results) {       sum.push(results);        index++;        if (list[index]) {            return api.sequence(list, fn, index, sum);        }        return sum;    }); };