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

Commit ce0af14

Browse files
author
Hans Kristian Flaatten
committed
Deprecate 'ignore' option in favor of blacklist
1 parent 6db8be0 commit ce0af14

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ useful when building an API and accepting various user specificed queries.
99
## Features
1010

1111
* Aliased query parameters
12-
* Ignored query parameters
12+
* Blacklisted query parameters
1313
* Basic operators
1414
* `$ne`
1515
* `$gt`
@@ -37,7 +37,7 @@ var MongoQS = require('mongo-querystring');
3737

3838
* `Array` ops - list of supported operators
3939
* `object` alias - query param aliases
40-
* `object` ignore - ignored query params
40+
* `object` blacklist - blacklisted query params
4141
* `object` custom - custom query params
4242

4343
#### Bult in custom queries

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@
4141
"devDependencies": {
4242
"coffee-script": "^1.8.0",
4343
"mocha": "^1.21.4"
44+
},
45+
"dependencies": {
46+
"depd": "1.0.0"
4447
}
4548
}

src/index.litcoffee

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
module.exports = MongoQS = (opts) ->
2+
if opts?.ignore
3+
deprecate.property opts, 'ignore'
4+
opts.blacklist = opts.ignore
5+
26
@ops = opts?.ops or ['!', '^', '$', '~', '>', '<']
37
@alias = opts?.alias or {}
4-
@ignore = opts?.ignore or {}
8+
@blacklist = opts?.blacklist or {}
59
@custom = opts?.custom or {}
610
711
for param, field of @custom
@@ -79,7 +83,7 @@ Main query param parser method which follows the following order of operations.
7983
res = {}
8084
8185
for key, val of query
82-
continue if @ignore[key]
86+
continue if @blacklist[key]
8387
continue if typeof val isnt 'string'
8488
continue if not /^[a-zæøå0-9-_.]+$/i.test key
8589
@@ -122,3 +126,5 @@ instanciating `MongoQS` and the defaults are `!`, `^`, `$`, `~`, `>`, and `<`.
122126
123127
res
124128
129+
deprecate = require('depd')('mongo-querystring')
130+

test/suite.coffee

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ describe 'parse()', ->
146146
qs = new MongoQS alias: foo: 'bar', baz: 'bax'
147147
assert.deepEqual qs.parse({foo: 'bix', baz: 'box'}), bar: 'bix', bax: 'box'
148148

149-
describe 'ignoring', ->
150-
it 'should ignore key', ->
151-
qs = new MongoQS ignore: foo: true
149+
describe 'blacklisting', ->
150+
it 'should blacklist key', ->
151+
qs = new MongoQS blacklist: foo: true
152152
assert.deepEqual qs.parse({foo: 'bar', bar: 'foo'}), bar: 'foo'
153153

154-
it 'should ingore multiple keys', ->
155-
qs = new MongoQS ignore: foo: true, bar: true
154+
it 'should blacklist multiple keys', ->
155+
qs = new MongoQS blacklist: foo: true, bar: true
156156
assert.deepEqual qs.parse({foo: 'bar', bar: 'foo', baz: 'bax'}), baz: 'bax'
157157

158158
describe 'custom', ->

0 commit comments

Comments
 (0)