query-obj

A non-opinionated way of querying javascript objects.

query-obj

A non-opinionated way of querying javascript objects.

npm install query-obj
var Query = require('query-obj')
  , fns = {}
 
fns.isString = function(){
  return (typeof this.value == 'string')
}
 
Query()
.setMethods(fns)
.where('str')
  .isString()
  .error('type', 'Str should be a string')
 
.end({str: 100}, function(errorsattrs){
  console.log(errors.str)
  //= [ValidatorError] 
  console.log(attrs.str.value)
  //= 100 
})
.end({str: 'a string'}, function(errorsattrs){
  console.log(errors.str)
  //= undefined 
  console.log(attrs.str.value)
  //= 'a string' 
})
 

Initialize a new Query

Inherit chains, methods and setters from another query or similar object.

Specifies the methods available to chain on each .where() call.

Methods that return false will trigger any subsequent .error() calls on that specific .where() chain.

Methods that return true, will skip any .error() calls and continue to next chained method.

Sets up a chain of methods for a particular attributeName. This chain will run when .end() is called.

Setup an error to fire if a previous method in a .where() chain return false.

Sets up a setter attribute with value.

On .end() the setter will be assigned to this query object.

Run any given query chains against obj.

Once finished fn is invoked with any Attribute errors, and attributes.

MIT