UNPKG

@ianwalter/peregrin

Version:

Toolkit for converting API Blueprint files to JSON and consuming that JSON

42 lines (40 loc) 1.49 kB
module.exports = (function () { function Blueprint(json) { this.json = json; } Blueprint.prototype.find = function find (filter, prop) { var json = prop ? this.json[prop] : this.json; if (Number.isInteger(filter)) { json = json[filter]; } else if (typeof filter === 'string') { json = json.find(function (o) { return Object.values(o).includes(filter); }); } else if (typeof filter === 'function') { var values = Array.isArray(json) ? json : Object.values(json); json = values.find(filter); } return new Blueprint(json); }; Blueprint.prototype.group = function group (filter) { return this.find(filter); }; Blueprint.prototype.resource = function resource (filter) { return this.find(filter, 'resources'); }; Blueprint.prototype.action = function action (filter) { return this.find(filter, 'actions'); }; Blueprint.prototype.example = function example (filter) { return this.find(filter, 'examples'); }; Blueprint.prototype.request = function request (filter) { return this.find(filter, 'requests'); }; Blueprint.prototype.response = function response (filter) { return this.find(filter, 'responses'); }; Blueprint.prototype.body = function body () { return JSON.parse(this.json.body); }; return Blueprint; }()); //# sourceMappingURL=peregrin.js.map