Skip to content

Commit

Permalink
Merge tag '2.1.6' into develop
Browse files Browse the repository at this point in the history
Adds accents to the search filter.
  • Loading branch information
douglasrafael committed Aug 5, 2020
2 parents d92c0a5 + 47a340e commit 7e61b3d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: node_js
node_js:
- "8"
- "9"
- "10"
- "11"
- "12"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ For informations and details about the supported query strings, access the [wiki
[npm-url]: https://npmjs.org/package/query-strings-parser
[downloads-image]: https://img.shields.io/npm/dt/query-strings-parser.svg?logo=npm
[travis-image]: https://img.shields.io/travis/nutes-uepb/query-strings-parser.svg?logo=travis
[travis-url]: https://travis-ci.org/nutes-uepb/query-strings-parser
[travis-url]: https://travis-ci.com/nutes-uepb/query-strings-parser
[coverage-image]: https://coveralls.io/repos/github/nutes-uepb/query-strings-parser/badge.svg
[coverage-url]: https://coveralls.io/github/nutes-uepb/query-strings-parser?branch=master
[known-vulnerabilities-image]: https://snyk.io/test/github/nutes-uepb/query-strings-parser/badge.svg?targetFile=package.json
Expand Down
10 changes: 10 additions & 0 deletions lib/mapper/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,23 @@ function splitByCommas(key, value) {

function buildRegEx(value) {
value = value.replace(/(^\*{2,})|\*{2,}$/gi, '*')
value = addAccentsRegex(value)
const result = {'$options': 'i'}
if (!value.startsWith('*') && value.endsWith('*')) result.$regex = '^'.concat(value.replace(/([*])/gi, ''))
else if (value.startsWith('*') && !value.endsWith('*')) result.$regex = value.replace(/([*])/gi, '').concat('$')
else result.$regex = value.replace(/([*])/gi, '')

return result
}

function addAccentsRegex(string) {
return string.replace(/a/g, '[a,á,à,ä,â,ã]')
.replace(/e/g, '[e,é,ë,ê]')
.replace(/i/g, '[i,í,ï]')
.replace(/o/g, '[o,ó,ö,ò,ô]')
.replace(/u/g, '[u,ü,ú,ù]')
}

function parseDate(query, options) {
const result = []
if (query.start_at === 'today') query.start_at = normalizeDate(dateToString(new Date()), true)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "query-strings-parser",
"version": "2.1.5",
"version": "2.1.6",
"description": "Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL and other databases...",
"license": "MIT",
"main": "index.js",
Expand Down Expand Up @@ -44,7 +44,7 @@
"devDependencies": {
"chai": "^4.2.0",
"express": "^4.17.1",
"mocha": "^7.2.0",
"mocha": "^8.1.1",
"nyc": "^15.1.0",
"supertest": "^4.0.2"
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/index.default.config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ describe('queryFilter()', function () {
const expect_filters = {
'$and': [
{
name: {'$options': 'i', '$regex': '^lucas'}
name: { '$options': 'i', '$regex': '^l[u,ü,ú,ù]c[a,á,à,ä,â,ã]s' }
},
{
name: {'$options': 'i', '$regex': 'douglas$'}
name: { '$options': 'i', '$regex': 'd[o,ó,ö,ò,ô][u,ü,ú,ù]gl[a,á,à,ä,â,ã]s$' }
},
{
name: {'$options': 'i', '$regex': 'jorge'}
name: { '$options': 'i', '$regex': 'j[o,ó,ö,ò,ô]rg[e,é,ë,ê]' }
}],
'school.name': 'UEPB',
'timestamp': '2018-12-05T00:00:00',
Expand Down

0 comments on commit 7e61b3d

Please sign in to comment.