You've already forked search-query-parser
honor alwaysArray option for exclusions
This commit is contained in:
@@ -195,7 +195,13 @@ exports.parse = function (string, options) {
|
||||
// Got only a single value this time
|
||||
else {
|
||||
// Record its value as a string
|
||||
exclusion[key] = value;
|
||||
if (options.alwaysArray) {
|
||||
// ...but we always return an array if option alwaysArray is true
|
||||
exclusion[key] = [value];
|
||||
} else {
|
||||
// Record its value as a string
|
||||
exclusion[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "search-query-parser",
|
||||
"version": "1.4.0",
|
||||
"version": "1.5.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "search-query-parser",
|
||||
"version": "1.4.2",
|
||||
"version": "1.5.0",
|
||||
"description": "Parser for advanced search query syntax",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
16
test/test.js
16
test/test.js
@@ -348,9 +348,9 @@ describe('Search query syntax parser', function () {
|
||||
});
|
||||
|
||||
it('should always return an array if alwaysArray is set to true', function () {
|
||||
var searchQuery = 'from:jul@foo.com to:a@b.c ouch!#';
|
||||
var searchQuery = 'from:jul@foo.com to:a@b.c -cc:you@foo.com ouch!#';
|
||||
|
||||
var options = {keywords: ['from', 'to'], alwaysArray: true};
|
||||
var options = {keywords: ['from', 'to', 'cc'], alwaysArray: true};
|
||||
var parsedSearchQuery = searchquery.parse(searchQuery, options);
|
||||
|
||||
parsedSearchQuery.should.be.an.Object;
|
||||
@@ -359,10 +359,13 @@ describe('Search query syntax parser', function () {
|
||||
parsedSearchQuery.should.have.property('to');
|
||||
parsedSearchQuery.from.should.be.an.Array;
|
||||
parsedSearchQuery.to.should.be.an.Array;
|
||||
parsedSearchQuery.exclude.cc.should.be.an.Array;
|
||||
parsedSearchQuery.from.length.should.equal(1);
|
||||
parsedSearchQuery.to.length.should.equal(1);
|
||||
parsedSearchQuery.exclude.cc.length.should.equal(1);
|
||||
parsedSearchQuery.from.should.containEql('jul@foo.com');
|
||||
parsedSearchQuery.to.should.containEql('a@b.c');
|
||||
parsedSearchQuery.exclude.cc.should.containEql('you@foo.com');
|
||||
parsedSearchQuery.should.have.property('offsets', [{
|
||||
keyword: 'from',
|
||||
value: 'jul@foo.com',
|
||||
@@ -373,10 +376,15 @@ describe('Search query syntax parser', function () {
|
||||
value: 'a@b.c',
|
||||
offsetStart: 17,
|
||||
offsetEnd: 25
|
||||
}, {
|
||||
keyword: 'cc',
|
||||
value: 'you@foo.com',
|
||||
offsetStart: 27,
|
||||
offsetEnd: 41
|
||||
}, {
|
||||
text: 'ouch!#',
|
||||
offsetStart: 26,
|
||||
offsetEnd: 32
|
||||
offsetStart: 42,
|
||||
offsetEnd: 48
|
||||
}]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user