c2-mongoose 2.1.50 → 2.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,7 @@ declare abstract class SearchFlow {
15
15
  buildPopulate(): any;
16
16
  buildPath(target: string, nested?: string): any;
17
17
  buildOrdenation(): any;
18
- diacriticSensitiveRegex(string?: string): string;
18
+ buildRegex(searchText: string): RegExp;
19
19
  searchPageable(model: mongoose.Model<any>, pipeline: any): Promise<{
20
20
  items: any;
21
21
  paging: any;
@@ -135,15 +135,14 @@ var SearchFlow = /** @class */ (function () {
135
135
  this.sort = order;
136
136
  return order;
137
137
  };
138
- SearchFlow.prototype.diacriticSensitiveRegex = function (string) {
139
- if (string === void 0) { string = ""; }
140
- return string
141
- .replace(/[a|á|à|ä|â|A|Á|Â|Ã|Ä]/g, '[a,á,à,ä,â,A,Á,Â,Ã,Ä]')
142
- .replace(/[e|é|ë|è|E|É|Ë|È]/g, '[e,é,ë,è,E,É,Ë,È]')
143
- .replace(/[i|í|ï|ì|I|Í|Ï|Ì]/g, '[i,í,ï,ì,I,Í,Ï,Ì]')
144
- .replace(/[o|ó|ö|ò|õ|O|Ó|Ö|Ô|Õ]/g, '[o,ó,ö,ò,õ,O,Ó,Ö,Ô,Õ]')
145
- .replace(/[u|ü|ú|ù|U|Ú|Ü|Ù]/g, '[u,ü,ú,ù,U,Ú,Ü,Ù]')
146
- .replace(/[ç|Ç|c|C]/g, '[c,C,ç,Ç]');
138
+ SearchFlow.prototype.buildRegex = function (searchText) {
139
+ var regexExpression = searchText
140
+ .replace(/^"/, '^').replace(/"$/, '$') //Replace aspas duplas para busca exata
141
+ .replace(/^%22/, '^').replace(/%22$/, '$') //Replace aspas duplas para busca exata
142
+ .replace(/%20/, ' ') //Replace espaço em branco para nao quebrar o proximo replace
143
+ .replace(/%/g, '.*?') //Replace % para o padrão regex (% é muito utilizado como o .*? e é mais simples para o usuario digitar)
144
+ .replace(/[ç|c|C|Ç]/g, '[c,ç]');
145
+ return new RegExp("".concat(regexExpression), 'i');
147
146
  };
148
147
  SearchFlow.prototype.searchPageable = function (model, pipeline) {
149
148
  return __awaiter(this, void 0, void 0, function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.50",
3
+ "version": "2.1.51",
4
4
  "description": "Lib to make any search in database mongoose and use as basic crud",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -64,14 +64,14 @@ abstract class SearchFlow {
64
64
  return order
65
65
  }
66
66
 
67
- public diacriticSensitiveRegex(string: string = ""): string {
68
- return string
69
- .replace(/[a|á|à|ä|â|A|Á|Â|Ã|Ä]/g, '[a,á,à,ä,â,A,Á,Â,Ã,Ä]')
70
- .replace(/[e|é|ë|è|E|É|Ë|È]/g, '[e,é,ë,è,E,É,Ë,È]')
71
- .replace(/[i|í|ï|ì|I|Í|Ï|Ì]/g, '[i,í,ï,ì,I,Í,Ï,Ì]')
72
- .replace(/[o|ó|ö|ò|õ|O|Ó|Ö|Ô|Õ]/g, '[o,ó,ö,ò,õ,O,Ó,Ö,Ô,Õ]')
73
- .replace(/[u|ü|ú|ù|U|Ú|Ü|Ù]/g, '[u,ü,ú,ù,U,Ú,Ü,Ù]')
74
- .replace(/[ç|Ç|c|C]/g, '[c,C,ç,Ç]')
67
+ buildRegex(searchText: string): RegExp {
68
+ let regexExpression = searchText
69
+ .replace(/^"/, '^').replace(/"$/, '$') //Replace aspas duplas para busca exata
70
+ .replace(/^%22/, '^').replace(/%22$/, '$') //Replace aspas duplas para busca exata
71
+ .replace(/%20/, ' ') //Replace espaço em branco para nao quebrar o proximo replace
72
+ .replace(/%/g, '.*?') //Replace % para o padrão regex (% é muito utilizado como o .*? e é mais simples para o usuario digitar)
73
+ .replace(/[ç|c|C|Ç]/g, '[c,ç]')
74
+ return new RegExp(`${regexExpression}`, 'i');
75
75
  }
76
76
 
77
77
  async searchPageable(model: mongoose.Model<any>, pipeline: any) {