@nka212bg/backend-utils 0.1.28 → 0.1.30

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.
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/misc.js CHANGED
@@ -563,19 +563,6 @@ exports.strToEmailsArray = (emailString) => {
563
563
  ].sort();
564
564
  };
565
565
 
566
- exports.handlebars = ({ template, ...params } = {}) => {
567
- const placeholders = template.match(/(\{\{)(.*?)(\}\})/g);
568
-
569
- for (const p in params) {
570
- const placeholder = placeholders.find((e) => e.includes(p));
571
- if (!placeholder) continue;
572
-
573
- template = template.replace(RegExp(placeholder, "g"), params[p]);
574
- }
575
-
576
- return template;
577
- };
578
-
579
566
  exports.iterateObject = (obj, callback) => {
580
567
  for (let key in obj) {
581
568
  if (Array.isArray(obj[key])) {
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.30",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "@maxmind/geoip2-node": "^5.0.0",
package/session.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const { existsSync, readFileSync, writeFileSync, mkdirSync } = require("fs");
2
+ const { createToken } = require("./misc");
2
3
 
3
4
  !existsSync(`${__basedir}/state`) && mkdirSync(`${__basedir}/state`, { recursive: true });
4
5
  const sessionStateFile = `${__basedir}/state/session.json`;
@@ -38,6 +39,7 @@ exports.session = {
38
39
 
39
40
  if (!payload.expirePeriod) payload.expirePeriod = 60000 * 60 * 24 * 7; // 7days
40
41
  payload.expireTime = now + payload.expirePeriod;
42
+ payload.uuid = createToken({ type: "date" });
41
43
 
42
44
  SESSION[token] = payload;
43
45
  return { ...payload, expireIn: payload.expirePeriod + 60000 };