@yext/search-headless
Version:
A library for powering UI components for Yext Search integrations
43 lines • 1.93 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.areStaticFiltersEqual = exports.areFieldValueFiltersEqual = void 0;
const isEqual_1 = __importDefault(require("lodash/isEqual"));
/**
* Returns true if the two given field value filters are the same.
*
* @param thisFilter - The first field value filter to compare
* @param otherFilter - The second field value filter to compare
* @returns Whether the two field value filters are the same or not
*/
function areFieldValueFiltersEqual(thisFilter, otherFilter) {
return thisFilter.fieldId === otherFilter.fieldId
&& thisFilter.matcher === otherFilter.matcher
&& (0, isEqual_1.default)(thisFilter.value, otherFilter.value);
}
exports.areFieldValueFiltersEqual = areFieldValueFiltersEqual;
/**
* Returns true if the two given static filters are the same.
*
* @param thisFilter - The first static filter to compare
* @param otherFilter - The second static filter to compare
* @returns Whether the two static filters are the same or not
*/
function areStaticFiltersEqual(thisFilter, otherFilter) {
if (thisFilter.kind === 'fieldValue') {
return otherFilter.kind === 'fieldValue'
? areFieldValueFiltersEqual(thisFilter, otherFilter)
: false;
}
if (otherFilter.kind === 'fieldValue') {
return false;
}
return thisFilter.combinator === otherFilter.combinator
&& thisFilter.filters.length === otherFilter.filters.length
&& thisFilter.filters.every(t => otherFilter.filters.some(o => areStaticFiltersEqual(t, o)))
&& otherFilter.filters.every(o => thisFilter.filters.some(t => areStaticFiltersEqual(o, t)));
}
exports.areStaticFiltersEqual = areStaticFiltersEqual;
//# sourceMappingURL=filter-utils.js.map