Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 76592ba

Browse files
author
Hans Kristian Flaatten
committed
Merge branch 'es6-rewrite'
2 parents 75c7c5e + e059e80 commit 76592ba

File tree

12 files changed

+661
-680
lines changed

12 files changed

+661
-680
lines changed

.eslintrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# vi:syntax=json
2+
{
3+
"extends": "airbnb-base",
4+
"env": {
5+
"mocha": true,
6+
"node": true
7+
},
8+
"parserOptions": {
9+
"ecmaVersion": 6,
10+
"sourceType": "script",
11+
"ecmaFeatures": {
12+
"modules": false
13+
}
14+
},
15+
"rules": {
16+
"strict": [2, "global"],
17+
"no-param-reassign": [2, { "props": false }]
18+
}
19+
}

.jshintrc

Lines changed: 0 additions & 63 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014-2015 Den Norske Turistforening (DNT), Hans Kristian Flaatten
3+
Copyright (c) 2014-2016 Den Norske Turistforening (DNT), Hans Kristian Flaatten
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# MongoDB QueryString
1+
# MongoDB QueryString Parser
22

3-
[![Build status](https://img.shields.io/wercker/ci/566dca6762f42c407207777a.svg "Build status")](https://app.wercker.com/project/bykey/a31eed21b34f26d9b7af766b4614c260)
3+
[![Build status](https://app.wercker.com/status/b33b844c0ab10d56c318e116e587e2fa/s "wercker status")](https://app.wercker.com/project/bykey/b33b844c0ab10d56c318e116e587e2fa)
4+
[![Codacy grade](https://img.shields.io/codacy/grade/782d0dc482ea4033892f99f968090b35.svg "Codacy grade")](https://www.codacy.com/app/DNT/node-mongo-querystring)
5+
[![Codacy coverage](https://img.shields.io/codacy/coverage/782d0dc482ea4033892f99f968090b35.svg "Codacy coverage")](https://www.codacy.com/app/DNT/node-mongo-querystring)
46
[![NPM downloads](https://img.shields.io/npm/dm/mongo-querystring.svg "NPM downloads")](https://www.npmjs.com/package/mongo-querystring)
57
[![NPM version](https://img.shields.io/npm/v/mongo-querystring.svg "NPM version")](https://www.npmjs.com/package/mongo-querystring)
68
[![Node version](https://img.shields.io/node/v/mongo-querystring.svg "Node version")](https://www.npmjs.com/package/mongo-querystring)
7-
[![Dependency status](https://img.shields.io/david/turistforeningen/node-mongo-querystring.svg "Dependency status")](https://david-dm.org/turistforeningen/node-mongo-querystring)
9+
[![Dependency status](https://img.shields.io/david/Turistforeningen/node-mongo-querystring.svg "Dependency status")](https://david-dm.org/Turistforeningen/node-mongo-querystring)
810

911
Accept MongoDB query parameters through URI queries safe and easy. This is
1012
useful when building an API and accepting various user specificed queries.

docker-compose.yml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
mongo:
1+
version: '2'
2+
3+
services:
4+
mongo:
25
image: mongo:latest
36

4-
dev:
5-
image: node:argon
6-
links:
7-
- mongo
8-
working_dir: /usr/src/app
9-
volumes:
10-
- ".:/usr/src/app"
11-
command: "npm run watch"
12-
environment:
13-
- NODE_ENV=development
7+
node:
8+
image: node:argon
9+
working_dir: /usr/src/app
10+
links:
11+
- mongo
12+
volumes:
13+
- .:/usr/src/app
14+
environment:
15+
- NODE_ENV=development
16+
- NPM_CONFIG_LOGLEVEL=silent
17+
- NPM_CONFIG_PROGRESS=false
18+
- NPM_CONFIG_SPIN=false
19+
command: npm test

examples/app.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
'use strict';
22

3-
var express = require('express');
4-
var app = module.exports = express();
3+
const express = require('express');
4+
const app = module.exports = express();
55

6-
var MongoQS = require('../index');
6+
const JSONStream = require('JSONStream');
7+
const MongoQS = require('../index');
8+
const mongo = require('./db');
79

810
// Create a new Mongo QueryString parser
9-
var qs = new MongoQS({
11+
const qs = new MongoQS({
1012
custom: {
1113
bbox: 'geojson',
12-
near: 'geojson'
13-
}
14+
near: 'geojson',
15+
},
1416
});
1517

16-
app.get('/api/places', function(req, res) {
18+
app.get('/api/places', (req, res) => {
1719
res.set('Content-Type', 'application/json');
1820

1921
// Parse the request query parameters
20-
var query = qs.parse(req.query);
21-
var collection = require('./db').db.collection('places');
22-
var cursor = collection.find(query).limit(3);
22+
const query = qs.parse(req.query);
23+
const collection = mongo.db.collection('places');
24+
const cursor = collection.find(query).limit(3);
2325

24-
cursor.stream().pipe(require('JSONStream').stringify()).pipe(res);
26+
cursor.stream().pipe(JSONStream.stringify()).pipe(res);
2527
});
2628

2729
if (!module.parent) {
28-
require('./db').once('ready', function() {
30+
mongo.once('ready', () => {
2931
app.listen(3000);
30-
console.log('Express started on port 3000');
32+
console.log('Express started on port 3000'); // eslint-disable-line no-console
3133
});
3234
}

examples/db.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
'use strict';
22

3-
var EventEmitter = require('events').EventEmitter;
4-
var MongoClient = require('mongodb').MongoClient;
5-
var inherits = require('util').inherits;
3+
const EventEmitter = require('events').EventEmitter;
4+
const MongoClient = require('mongodb').MongoClient;
5+
const inherits = require('util').inherits;
66

7-
var Mongo = function(uri) {
7+
function Mongo(uri) {
88
EventEmitter.call(this);
99

1010
this.db = null;
1111

12-
var $this = this;
13-
14-
new MongoClient.connect(uri, function(err, db) {
12+
MongoClient.connect(uri, (err, db) => {
1513
if (err) { throw err; }
1614

17-
$this.db = db;
18-
$this.emit('ready');
15+
this.db = db;
16+
this.emit('ready');
1917
});
2018

2119
return this;
22-
};
20+
}
2321

2422
inherits(Mongo, EventEmitter);
2523

0 commit comments

Comments
 (0)