MCPcopy Create free account
hub / github.com/chartbrew/chartbrew / compareBooleans

Function compareBooleans

server/charts/dataFilter.js:337–424  ·  view source on GitHub ↗
(data, field, condition)

Source from the content-addressed store, hash-verified

335}
336
337function compareBooleans(data, field, condition) {
338 let newData = data;
339
340 if (!condition.value && condition.value !== false && condition.value !== "false"
341 && (condition.operator !== "isNull" && condition.operator !== "isNotNull")) {
342 return data;
343 }
344
345 // extract value
346 const getValue = (obj) => {
347 const selectors = field.split(".");
348 let value = obj;
349 for (let i = 0; i < selectors.length; i++) {
350 value = value[selectors[i]];
351 }
352
353 if (!value && (value !== 0 || value !== "0") && value !== false) {
354 return null;
355 }
356
357 // Convert string "true"/"false" to actual boolean
358 if (typeof value === "string") {
359 if (value.toLowerCase() === "true") return true;
360 if (value.toLowerCase() === "false") return false;
361 }
362
363 return value;
364 };
365
366 switch (condition.operator) {
367 case "is":
368 newData = _.filter(newData, (o) => {
369 const val = getValue(o);
370 const conditionVal = typeof condition.value === "string"
371 ? condition.value.toLowerCase() === "true"
372 : condition.value;
373 return val === conditionVal;
374 });
375 break;
376 case "isNot":
377 newData = _.filter(newData, (o) => {
378 const val = getValue(o);
379 const conditionVal = typeof condition.value === "string"
380 ? condition.value.toLowerCase() === "true"
381 : condition.value;
382 return val !== conditionVal;
383 });
384 break;
385 case "contains":
386 newData = _.filter(newData, (o) => {
387 const val = getValue(o);
388 if (val?.isString) return getValue(o)?.indexOf(condition.value) > -1;
389 return getValue(o) === parseFloat(condition.value);
390 });
391 break;
392 case "notContains":
393 newData = _.filter(newData, (o) => {
394 const val = getValue(o);

Callers 1

dataFilter.jsFile · 0.85

Calls 2

getValueFunction · 0.85
filterMethod · 0.80

Tested by

no test coverage detected