UNPKG

agson

Version:

Querying and manipulating JSON graphs

69 lines (51 loc) 1.57 kB
(function() { var AgsonQuery, combinators, lenses, liftL, traversals, __slice = [].slice; lenses = require('./agson/lenses'); traversals = require('./agson/traversals'); combinators = require('./agson/combinators'); liftL = function(lensf) { return function() { var args; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; return new AgsonQuery(this.lens.then(lensf.apply(null, args))); }; }; AgsonQuery = (function() { function AgsonQuery(lens) { this.lens = lens; } AgsonQuery.prototype.toString = function() { return "agson(" + (this.lens.toString()) + ")"; }; AgsonQuery.prototype.list = liftL(function() { return traversals.list; }); AgsonQuery.prototype.object = liftL(function() { return traversals.object; }); AgsonQuery.prototype.property = liftL(lenses.property); AgsonQuery.prototype.index = liftL(lenses.property); AgsonQuery.prototype.where = liftL(function(predicate) { return combinators.where(function(ma) { return ma.map(predicate).getOrElse(false); }); }); AgsonQuery.prototype.recurse = function() { var lens; lens = this.lens.then(combinators.recurse(function() { return lens; })); return new AgsonQuery(lens); }; AgsonQuery.prototype.run = function(data) { return this.lens.run(data); }; return AgsonQuery; })(); module.exports = new AgsonQuery({ then: function(lens) { return lens; } }); }).call(this);