@nka212bg/backend-utils 0.1.28 → 0.1.29

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.
Files changed (2) hide show
  1. package/db/dbUtils.js +32 -0
  2. package/package.json +1 -1
package/db/dbUtils.js CHANGED
@@ -34,3 +34,35 @@ exports.paramsSanitize = (params) => {
34
34
  return param;
35
35
  });
36
36
  };
37
+
38
+ exports.searchString = (input, column) => {
39
+ try {
40
+ input = String(input ?? "")
41
+ .replace(/[^\p{L}\p{N}\s+,']/gu, " ")
42
+ .replace(/'+/g, "''")
43
+ .replace(/\s+/g, " ")
44
+ .trim();
45
+
46
+ if (!input) return "";
47
+
48
+ if (!input.includes("+") && !input.includes(",")) return `${column} LIKE '%${input}%'`;
49
+
50
+ const andGroups = input
51
+ .split("+")
52
+ .map((s) => s.trim())
53
+ .filter(Boolean)
54
+ .map((andPart) => {
55
+ const likes = andPart
56
+ .split(",")
57
+ .map((s) => s.trim())
58
+ .filter(Boolean)
59
+ .map((term) => `${column} LIKE '%${term}%'`);
60
+
61
+ return likes.length > 1 ? `(${likes.join(" OR ")})` : likes[0];
62
+ });
63
+
64
+ return andGroups.join(" AND ");
65
+ } catch (e) {
66
+ return "";
67
+ }
68
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nka212bg/backend-utils",
3
3
  "author": "nka212bg",
4
- "version": "0.1.28",
4
+ "version": "0.1.29",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "@maxmind/geoip2-node": "^5.0.0",