mongoose-query-maker
Advanced tools
Comparing version 3.0.3 to 3.0.4
@@ -63,5 +63,8 @@ "use strict"; | ||
// src/utils/negativeSelect.ts | ||
var negativeSelect = (input) => { | ||
return input.map((x) => `-${x}`).join(" "); | ||
// src/utils/selectFormatter.ts | ||
var selectFormatter = (input) => { | ||
return { | ||
negative: input.length ? "-" + input.join(" -") : "", | ||
pipe: input.join("|") | ||
}; | ||
}; | ||
@@ -71,17 +74,17 @@ | ||
var select = (input, { select: select2 }) => { | ||
if (!input) | ||
return negativeSelect(select2); | ||
if (Array.isArray(input)) | ||
throw new Error("Multiple `select` found."); | ||
const { negative, pipe } = selectFormatter(select2); | ||
let isNegative = false; | ||
const result = input.split(",").map((element) => element.trim()).filter((element) => { | ||
const regexInvalid = new RegExp(/^$|\s|\+$|^-{2,}/).test(element); | ||
const selectInvalid = select2.filter((x) => new RegExp(`${x}|^${x}\\.|^-${x}`).test(element)); | ||
if (element.startsWith("-") && element !== "-_id" && !regexInvalid && !selectInvalid.length && !isNegative) { | ||
const result = input.split(",").reduce((prev, value) => { | ||
value = value.trim(); | ||
if (new RegExp(`(^$|\\s|^\\+|^--)|((^|\\s)(-?(?:${pipe}))($|\\s))`).test(value)) { | ||
return prev; | ||
} | ||
if (value.startsWith("-") && value !== "-_id" && !isNegative) { | ||
isNegative = true; | ||
} | ||
return !selectInvalid.length && !regexInvalid; | ||
}); | ||
const resultValidation = result.length === 0 ? negativeSelect(select2) : result.length === 1 && result[0] === "-_id" ? `-_id ${negativeSelect(select2)}` : isNegative ? `${result.join(" ")} ${negativeSelect(select2)}` : result.join(" "); | ||
return resultValidation.trim(); | ||
return `${prev} ${value}`; | ||
}, ""); | ||
return `${result} ${isNegative ? negative : ""}`.trim(); | ||
}; | ||
@@ -88,0 +91,0 @@ |
{ | ||
"name": "mongoose-query-maker", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "A powerful query maker for MongoDB with Mongoose", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
434
63573