1
0

honor alwaysArray option for exclusions

This commit is contained in:
Russell Schick
2019-04-24 12:22:02 -07:00
parent 60e8120929
commit baa4353a1f
4 changed files with 21 additions and 7 deletions

View File

@@ -194,10 +194,16 @@ exports.parse = function (string, options) {
} }
// Got only a single value this time // Got only a single value this time
else { else {
// Record its value as a string
if (options.alwaysArray) {
// ...but we always return an array if option alwaysArray is true
exclusion[key] = [value];
} else {
// Record its value as a string // Record its value as a string
exclusion[key] = value; exclusion[key] = value;
} }
} }
}
} else { } else {
// If we already have seen that keyword... // If we already have seen that keyword...
if (query[key]) { if (query[key]) {

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "search-query-parser", "name": "search-query-parser",
"version": "1.4.0", "version": "1.5.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "search-query-parser", "name": "search-query-parser",
"version": "1.4.2", "version": "1.5.0",
"description": "Parser for advanced search query syntax", "description": "Parser for advanced search query syntax",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@@ -348,9 +348,9 @@ describe('Search query syntax parser', function () {
}); });
it('should always return an array if alwaysArray is set to true', 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); var parsedSearchQuery = searchquery.parse(searchQuery, options);
parsedSearchQuery.should.be.an.Object; parsedSearchQuery.should.be.an.Object;
@@ -359,10 +359,13 @@ describe('Search query syntax parser', function () {
parsedSearchQuery.should.have.property('to'); parsedSearchQuery.should.have.property('to');
parsedSearchQuery.from.should.be.an.Array; parsedSearchQuery.from.should.be.an.Array;
parsedSearchQuery.to.should.be.an.Array; parsedSearchQuery.to.should.be.an.Array;
parsedSearchQuery.exclude.cc.should.be.an.Array;
parsedSearchQuery.from.length.should.equal(1); parsedSearchQuery.from.length.should.equal(1);
parsedSearchQuery.to.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.from.should.containEql('jul@foo.com');
parsedSearchQuery.to.should.containEql('a@b.c'); parsedSearchQuery.to.should.containEql('a@b.c');
parsedSearchQuery.exclude.cc.should.containEql('you@foo.com');
parsedSearchQuery.should.have.property('offsets', [{ parsedSearchQuery.should.have.property('offsets', [{
keyword: 'from', keyword: 'from',
value: 'jul@foo.com', value: 'jul@foo.com',
@@ -373,10 +376,15 @@ describe('Search query syntax parser', function () {
value: 'a@b.c', value: 'a@b.c',
offsetStart: 17, offsetStart: 17,
offsetEnd: 25 offsetEnd: 25
}, {
keyword: 'cc',
value: 'you@foo.com',
offsetStart: 27,
offsetEnd: 41
}, { }, {
text: 'ouch!#', text: 'ouch!#',
offsetStart: 26, offsetStart: 42,
offsetEnd: 32 offsetEnd: 48
}]); }]);
}); });