Apply prefer-const lint rule
This commit is contained in:
1 parent
b43088c03c
commit
09e6a360af
26 files changed
+217
-215
No files matched your search
+16
-16
@@ -37,15 +37,15 @@ function stringToRegexp(input, flags) {
|
||||
function normalize(input) {
|
||||
if (common.typeOf(input) === common.STRING_TYPE) {
|
||||
const vals = [input];
|
||||
let m = /^\/(.*?)\/(g?i?m?y?)$/.exec(input);
|
||||
const m = /^\/(.*?)\/(g?i?m?y?)$/.exec(input);
|
||||
if (m) vals.push({ $regex: new RegExp(m[1], m[2]) });
|
||||
|
||||
if (+input === parseFloat(input)) vals.push(+input);
|
||||
|
||||
let d = new Date(input);
|
||||
const d = new Date(input);
|
||||
if (input.length >= 8 && d.getFullYear() > 1983) vals.push(d);
|
||||
|
||||
let r = stringToRegexp(input);
|
||||
const r = stringToRegexp(input);
|
||||
if (r !== false) vals.push({ $regex: r });
|
||||
|
||||
return vals;
|
||||
@@ -56,7 +56,7 @@ function normalize(input) {
|
||||
function expandValue(value) {
|
||||
if (common.typeOf(value) === common.ARRAY_TYPE) {
|
||||
let a = [];
|
||||
for (let j of value) a = a.conact(expandValue(j));
|
||||
for (const j of value) a = a.conact(expandValue(j));
|
||||
return [a];
|
||||
} else if (common.typeOf(value) !== common.OBJECT_TYPE) {
|
||||
const n = normalize(value);
|
||||
@@ -68,7 +68,7 @@ function expandValue(value) {
|
||||
const indices = [];
|
||||
const keys = [];
|
||||
const values = [];
|
||||
for (let [k, v] of Object.entries(value)) {
|
||||
for (const [k, v] of Object.entries(value)) {
|
||||
keys.push(k);
|
||||
values.push(expandValue(v));
|
||||
indices.push(0);
|
||||
@@ -95,7 +95,7 @@ function permute(param, val) {
|
||||
|
||||
if (param[param.lastIndexOf(".") + 1] !== "_") param += "._value";
|
||||
|
||||
for (let v of values) {
|
||||
for (const v of values) {
|
||||
const obj = {};
|
||||
obj[param] = v;
|
||||
conditions.push(obj);
|
||||
@@ -106,7 +106,7 @@ function permute(param, val) {
|
||||
|
||||
function expand(query) {
|
||||
const newQuery = {};
|
||||
for (let [k, v] of Object.entries(query)) {
|
||||
for (const [k, v] of Object.entries(query)) {
|
||||
if (k[0] === "$") {
|
||||
// Operator
|
||||
newQuery[k] = v.map(e => expand(e));
|
||||
@@ -117,7 +117,7 @@ function expand(query) {
|
||||
if (v && (v["$ne"] != null || v["$not"] != null)) {
|
||||
if (Object.keys(v).length > 1)
|
||||
throw new Error("Cannot mix $ne or $not with other operators");
|
||||
for (let c of conditions) newQuery["$an"].push(c);
|
||||
for (const c of conditions) newQuery["$an"].push(c);
|
||||
} else {
|
||||
newQuery["$and"].push({ $or: conditions });
|
||||
}
|
||||
@@ -159,7 +159,7 @@ function testExpressions(params, expressions, lop) {
|
||||
|
||||
function test(params, query) {
|
||||
let res;
|
||||
for (let [k, v] of Object.entries(query)) {
|
||||
for (const [k, v] of Object.entries(query)) {
|
||||
if (k.charAt(0) === "$") {
|
||||
// Logical operator
|
||||
res = testExpressions(params, v, k);
|
||||
@@ -174,7 +174,7 @@ function test(params, query) {
|
||||
else res = v === value;
|
||||
}
|
||||
} else {
|
||||
for (let [k2, v2] of Object.entries(v)) {
|
||||
for (const [k2, v2] of Object.entries(v)) {
|
||||
switch (k2) {
|
||||
case "$ne":
|
||||
if (common.typeOf(value) === common.ARRAY_TYPE)
|
||||
@@ -234,7 +234,7 @@ function matchType(src, dst) {
|
||||
}
|
||||
|
||||
function testFilter(obj, filter) {
|
||||
for (let [k, v] of Object.entries(filter)) {
|
||||
for (const [k, v] of Object.entries(filter)) {
|
||||
const [param, op] = k.split(/([^a-zA-Z0-9\-_.].*)/, 2);
|
||||
const val = matchType(obj[param], v);
|
||||
switch (op) {
|
||||
@@ -269,7 +269,7 @@ function convertMongoQueryToFilters(query, filters) {
|
||||
for (let [k, v] of Object.entries(query)) {
|
||||
if (k[0] === "$") {
|
||||
if (k === "$and")
|
||||
for (let vv of v) convertMongoQueryToFilters(vv, filters);
|
||||
for (const vv of v) convertMongoQueryToFilters(vv, filters);
|
||||
else throw new Error(`Operator ${k} not supported`);
|
||||
} else if (k === "_tags") {
|
||||
if (common.typeOf(v) === common.OBJECT_TYPE) {
|
||||
@@ -313,7 +313,7 @@ function convertMongoQueryToFilters(query, filters) {
|
||||
}
|
||||
|
||||
if (common.typeOf(v) === common.OBJECT_TYPE) {
|
||||
for (let [kk, vv] of Object.entries(v)) {
|
||||
for (const [kk, vv] of Object.entries(v)) {
|
||||
switch (kk) {
|
||||
case "$eq":
|
||||
filters[k] = vv;
|
||||
@@ -347,13 +347,13 @@ function convertMongoQueryToFilters(query, filters) {
|
||||
}
|
||||
|
||||
function sanitizeQueryTypes(query, types) {
|
||||
for (let [k, v] of Object.entries(query)) {
|
||||
for (const [k, v] of Object.entries(query)) {
|
||||
if (k[0] === "$") {
|
||||
// Logical operator
|
||||
for (let vv of v) sanitizeQueryTypes(vv, types);
|
||||
for (const vv of v) sanitizeQueryTypes(vv, types);
|
||||
} else if (k in types) {
|
||||
if (common.typeOf(v) === common.OBJECT_TYPE) {
|
||||
for (let [kk, vv] of Object.entries(v)) {
|
||||
for (const [kk, vv] of Object.entries(v)) {
|
||||
switch (kk) {
|
||||
case "$in":
|
||||
case "$nin":
|
||||
|
||||
Reference in new issue
Block a user