fix: use lodash package

This commit is contained in:
yassinedorbozgithub 2024-09-24 06:36:41 +01:00
parent fcfc68187b
commit cdb39e7c90
5 changed files with 12 additions and 21 deletions

View File

@ -11,7 +11,7 @@
import fs from 'fs';
import path from 'path';
import { escapeRegularExpression } from '@/utils/helpers/string';
import _ from 'lodash';
// Get the argument passed (e.g., "all-users-fr")
const arg: string | undefined = process.argv[2];
@ -27,8 +27,7 @@ const templatePath: string = path.join(__dirname, '../config/template.ts');
// Check if a migration with the same name (excluding timestamp) already exists
const migrationExists: boolean = fs.readdirSync(migrationsDir).some((file) => {
const escapedRegExp = escapeRegularExpression(arg);
const regex = new RegExp(`^[0-9]+-${escapedRegExp}\.ts$`);
const regex = new RegExp(`^[0-9]+-${_.escapeRegExp(arg)}\.ts$`);
return regex.test(file);
});

7
api/package-lock.json generated
View File

@ -67,6 +67,7 @@
"@types/express": "^4.17.17",
"@types/express-session": "^1.17.10",
"@types/jest": "^29.5.2",
"@types/lodash": "^4.17.9",
"@types/minio": "^7.1.1",
"@types/module-alias": "^2.0.4",
"@types/multer": "^1.4.11",
@ -6027,6 +6028,12 @@
"@types/node": "*"
}
},
"node_modules/@types/lodash": {
"version": "4.17.9",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.9.tgz",
"integrity": "sha512-w9iWudx1XWOHW5lQRS9iKpK/XuRhnN+0T7HvdCCd802FYkT1AMTnxndJHGrNJwRoRHkslGr4S29tjm1cT7x/7w==",
"dev": true
},
"node_modules/@types/mime": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz",

View File

@ -91,6 +91,7 @@
"@types/express": "^4.17.17",
"@types/express-session": "^1.17.10",
"@types/jest": "^29.5.2",
"@types/lodash": "^4.17.9",
"@types/module-alias": "^2.0.4",
"@types/multer": "^1.4.11",
"@types/node": "^20.3.1",

View File

@ -1,16 +0,0 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
*/
const reRegExpSpecialChars = /[\\^$.*+?()[\]{}|]/g,
reHasRegularExpressionChar = RegExp(reRegExpSpecialChars.source);
export const escapeRegularExpression = (string: string) =>
string && reHasRegularExpressionChar.test(string)
? string.replace(reRegExpSpecialChars, '\\$&')
: string;

View File

@ -13,9 +13,9 @@ import {
ArgumentMetadata,
Logger,
} from '@nestjs/common';
import _ from 'lodash';
import { TFilterQuery, Types } from 'mongoose';
import { escapeRegularExpression } from '../helpers/string';
import {
TFilterNestedKeysOfType,
TSearchFilterValue,
@ -37,7 +37,7 @@ export class SearchFilterPipe<T>
}
private getRegexValue(val: string) {
const escapedRegExp = escapeRegularExpression(val);
const escapedRegExp = _.escapeRegExp(val);
return new RegExp(escapedRegExp, 'i');
}