UNPKG

@replyke/core

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

101 lines 3.65 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.keywordHelpers = void 0; /** * Helper utilities for managing keywords filters in entity lists */ exports.keywordHelpers = { /** * Add keywords to a specific filter type */ addKeywords: function (current, type, values) { var _a; var existing = current || {}; return __assign(__assign({}, existing), (_a = {}, _a[type] = Array.from(new Set(__spreadArray(__spreadArray([], (existing[type] || []), true), values, true))), _a)); }, /** * Remove keywords from a specific filter type */ removeKeywords: function (current, type, values) { var _a; if (!current) return null; var updated = __assign(__assign({}, current), (_a = {}, _a[type] = (current[type] || []).filter(function (item) { return !values.includes(item); }), _a)); // Return null if both arrays are empty if ((!updated.includes || updated.includes.length === 0) && (!updated.doesNotInclude || updated.doesNotInclude.length === 0)) { return null; } return updated; }, /** * Remove keywords from both filter types */ removeKeywordsFromBoth: function (current, values) { if (!current) return null; var updated = { includes: (current.includes || []).filter(function (item) { return !values.includes(item); }), doesNotInclude: (current.doesNotInclude || []).filter(function (item) { return !values.includes(item); }), }; // Return null if both arrays are empty if (updated.includes.length === 0 && updated.doesNotInclude.length === 0) { return null; } return updated; }, /** * Reset keywords for a specific filter type */ resetKeywords: function (current, type) { var _a; if (!current) return null; var updated = __assign(__assign({}, current), (_a = {}, _a[type] = undefined, _a)); // Return null if both arrays are empty/undefined if (!updated.includes && !updated.doesNotInclude) { return null; } return updated; }, /** * Reset all keywords filters */ resetAllKeywords: function () { return null; }, /** * Replace keywords for a specific filter type */ replaceKeywords: function (current, type, values) { var _a; var existing = current || {}; var updated = __assign(__assign({}, existing), (_a = {}, _a[type] = values.length > 0 ? values : undefined, _a)); // Return null if both arrays are empty/undefined if (!updated.includes && !updated.doesNotInclude) { return null; } return updated; }, }; //# sourceMappingURL=keywordHelpers.js.map