Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

querymen-custom

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

querymen-custom - npm Package Compare versions

Comparing version 2.1.4 to 2.1.5

12

dist/index.js

@@ -24,3 +24,3 @@ 'use strict';

/** @module querymen */
/** @module querymen-custom */

@@ -36,3 +36,3 @@ exports.Param = _querymenParam2.default;

* Get or set a handler.
* @memberof querymen
* @memberof querymen-custom
* @param {string} type - Handler type.

@@ -52,3 +52,3 @@ * @param {string} name - Handler name.

* Get or set a parser.
* @memberof querymen
* @memberof querymen-custom
* @param {string} name - Parser name.

@@ -64,3 +64,3 @@ * @param {parserFn} [fn] - Set the parser method.

* Get or set a formatter.
* @memberof querymen
* @memberof querymen-custom
* @param {string} name - Formatter name.

@@ -87,3 +87,3 @@ * @param {formatterFn} [fn] - Set the formatter method.

* Create a middleware.
* @memberof querymen
* @memberof querymen-custom
* @param {QuerymenSchema|Object} [schema] - Schema object.

@@ -113,3 +113,3 @@ * @param {Object} [options] - Options to be passed to schema.

* Error handler middleware.
* @memberof querymen
* @memberof querymen-custom
* @return {Function} The middleware.

@@ -116,0 +116,0 @@ */

{
"name": "querymen-custom",
"version": "2.1.4",
"version": "2.1.5",
"description": "Querystring parser middleware for MongoDB, Express and Nodejs",

@@ -32,3 +32,3 @@ "main": "dist/index.js",

"type": "git",
"url": "git+https://github.com/diegohaz/querymen.git"
"url": "git+https://github.com/chemitaxis/querymen.git"
},

@@ -49,3 +49,3 @@ "keywords": [

"bugs": {
"url": "https://github.com/diegohaz/querymen/issues"
"url": "https://github.com/chemitaxis/querymen/issues"
},

@@ -52,0 +52,0 @@ "homepage": "https://github.com/diegohaz/querymen#readme",

@@ -12,6 +12,12 @@ # Querymen

## Important: This is a fork from 'querymen'
```sh
https://github.com/diegohaz/querymen
```
## Install
```sh
npm install --save querymen
npm install --save querymen-custom
```

@@ -117,173 +123,3 @@

### Reusable schemas
You can create reusable schemas as well. Just instantiate a `querymen.Schema` object.
```js
var querymen = require('querymen');
var schema = new querymen.Schema({
tags: {
type: [String],
}
});
// user requests /posts?tags=world,travel
// req.querymen.query is {tags: {$in: ['world', 'travel']}}
app.get('/posts', querymen.middleware(schema));
app.get('/articles', querymen.middleware(schema));
```
### Advanced schema
```js
var querymen = require('querymen');
var schema = new querymen.Schema({
active: Boolean, // shorthand to {type: Boolean}
sort: '-createdAt', // shorthand to {type: String, default: '-createdAt'}
term: {
type: RegExp,
paths: ['title', 'description'],
bindTo: 'search' // default was 'query'
},
with_picture: {
type: Boolean,
paths: ['picture'],
operator: '$exists'
}
}, {
page: false, // disable default parameter `page`
limit: 'max_items' // change name of default parameter `limit` to `max_items`
});
app.get('/posts', querymen.middleware(schema), function(req, res) {
// user requests /posts?term=awesome&with_picture=true&active=true&max_items=100
// req.querymen.query is {picture: {$exists: true}, active: true}
// req.querymen.cursor is {limit: 100, sort: {createdAt: -1}}
// req.querymen.search is {$or: [{title: /awesome/i}, {description: /awesome/i}]}
});
```
### Dynamic advanced schema
```js
var querymen = require('querymen');
var schema = new querymen.Schema();
schema.formatter('scream', function(scream, value, param) {
if (scream) {
value = value.toUpperCase() + '!!!!!!!';
}
return value;
});
schema.param('text', null, {type: String}); // {type: String}
schema.param('text').option('scream', true); // {type: String, scream: true}
schema.param('text').value('help');
console.log(schema.param('text').value()); // HELP!!!!!!!
schema.validator('isPlural', function(isPlural, value, param) {
return {
valid: !isPlural || value.substr(-1) === 's',
message: param.name + ' must be in plural form.'
};
});
schema.param('text').option('isPlural', true); // {type: String, scream: true, isPlural: true}
console.log(schema.validate()); // false
schema.param('text', 'helps');
console.log(schema.validate()); // true
console.log(schema.param('text').value()); // HELPS!!!!!!!
schema.parser('elemMatch', function(elemMatch, value, path, operator) {
if (elemMatch) {
value = {[path]: {$elemMatch: {[elemMatch]: {[operator]: value}}}};
}
return value;
});
schema.param('text', 'ivegotcontrols');
console.log(schema.param('text').parse()); // {text: 'IVEGOTCONTROLS!!!!!!!'}
schema.param('text').option('elemMatch', 'prop');
console.log(schema.param('text').parse()); // {text: {$elemMatch: {prop: {$eq: 'IVEGOTCONTROLS!!!!!!!'}}}}
```
### Geo queries
Querymen also support geo queries, but it's disabled by default. To enable geo queries you just need to set `near` option to true in schema options.
```js
var querymen = require('querymen');
app.get('/places', querymen.middleware({}, {near: true}), function(req, res) {
});
```
Its `paths` option is set to `['location']` by default, but you can change this as well:
```js
var querymen = require('querymen');
app.get('/places',
querymen.middleware({
near: {paths: ['loc']}
}, {
near: true
}),
function(req, res) {
});
```
User requests `/places?near=-22.332113,-44.312311` (latitude, longitude), req.querymen.query will be:
```js
req.querymen.query = {
loc: {
$near: {
$geometry: {
type: 'Point',
coordinates: [-44.312311, -22.332113]
}
}
}
}
```
User requests `/places?near=-22.332113,-44.312311&min_distance=200&max_distance=2000` (min_distance and max_distance in meters), req.querymen.query will be:
```js
req.querymen.query = {
loc: {
$near: {
$geometry: {
type: 'Point',
coordinates: [-44.312311, -22.332113]
},
$minDistace: 200,
$maxDistance: 2000
}
}
}
```
You can also use legacy geo queries as well. Just set `geojson` option in param:
```js
var querymen = require('querymen');
app.get('/places',
querymen.middleware({
near: {
paths: ['loc'],
geojson: false
}
}, {
near: true
}),
function(req, res) {
});
```
User requests `/places?near=-22.332113,-44.312311&min_distance=200&max_distance=2000`, req.querymen.query will be:
```js
req.querymen.query = {
loc: {
$near: [-44.312311, -22.332113],
// convert meters to radians automatically
$minDistace: 0.000031,
$maxDistance: 0.00031
}
}
```
### Error handling

@@ -290,0 +126,0 @@ ```js

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc