### Run SVAR Filter Tests Source: https://github.com/svar-widgets/filter/blob/main/readme.md Commands to run the tests for the SVAR Filter project. It includes starting the test examples and executing end-to-end tests using Cypress. ```bash yarn start:tests ``` ```bash yarn test:cypress ``` -------------------------------- ### Run SVAR Filter Test Examples Source: https://github.com/svar-widgets/filter/blob/main/svelte/readme.md This command initiates the test examples for the SVAR Filter project. It's a preliminary step before running the end-to-end tests. ```bash yarn start:tests ``` -------------------------------- ### Start SVAR Filter Project in Development Mode Source: https://github.com/svar-widgets/filter/blob/main/svelte/readme.md This command starts the SVAR Filter project in development mode. It's used when you need to modify the source code of the filter components. Note that this project uses yarn workspaces. ```bash yarn start ``` -------------------------------- ### Install SVAR Svelte Filter via npm Source: https://github.com/svar-widgets/filter/blob/main/readme.md Installs the SVAR Svelte Filter package using npm. This is the first step to integrate the filtering components into your Svelte project. ```bash npm install @svar-ui/svelte-filter ``` -------------------------------- ### Run SVAR Filter End-to-End Tests with Cypress Source: https://github.com/svar-widgets/filter/blob/main/svelte/readme.md This command executes the end-to-end tests for the SVAR Filter project using Cypress. Ensure that the test examples are running in a separate console before executing this command. ```bash yarn test:cypress ``` -------------------------------- ### Basic SVAR FilterBuilder Usage in Svelte Source: https://github.com/svar-widgets/filter/blob/main/svelte/readme.md Demonstrates how to import and use the FilterBuilder component in a Svelte application. It shows the basic setup with fields and options for filtering data. The component outputs structured JSON for filtering rules. ```svelte ``` -------------------------------- ### Retrieve Available Filters by Data Type Source: https://context7.com/svar-widgets/filter/llms.txt Fetches lists of available filter operators for specified data types (text, number, date) using the `getFilters` function. It also shows how to retrieve a specific filter and its handler function using `getFilter`, demonstrating its usage with example inputs and expected boolean outputs. ```javascript import { getFilters, getFilter } from '@svar-ui/svelte-filter'; // Get all filters for text fields const textFilters = getFilters("text"); // Get all filters for number fields const numberFilters = getFilters("number"); // Get all filters for date fields const dateFilters = getFilters("date"); // Get specific filter with handler const containsFilter = getFilter("contains", "text"); console.log(containsFilter.handler("Hello World", "world")); // true console.log(containsFilter.handler("Hello World", "xyz")); // false ``` -------------------------------- ### Build Filters with FilterBuilder and Apply to Data Source: https://context7.com/svar-widgets/filter/llms.txt Demonstrates using the FilterBuilder component to construct complex filter queries with nested rules and AND/OR logic. It also shows how to use the `createArrayFilter` helper function to apply these filters to a JavaScript array and update the displayed data. ```svelte applyFilter(value)} /> ``` -------------------------------- ### Basic Usage of FilterBuilder in Svelte Source: https://github.com/svar-widgets/filter/blob/main/readme.md Demonstrates the basic integration of the FilterBuilder component in a Svelte application. It shows how to import the component and provide initial field and option configurations. ```svelte ``` -------------------------------- ### Load Filter Options Dynamically with Svelte Source: https://context7.com/svar-widgets/filter/llms.txt Demonstrates how to dynamically load filter options asynchronously within a Svelte component using the `FilterBuilder`. The `options` prop accepts an async function that simulates fetching data for fields like 'country', 'city', and 'category' based on the field ID, enabling on-demand loading for large datasets. ```svelte ``` -------------------------------- ### Edit Single Filter Rule with FilterEditor Source: https://context7.com/svar-widgets/filter/llms.txt Illustrates the usage of the FilterEditor component for managing a single filtering rule. It demonstrates how to bind to the rule's properties (includes, filter, value) and handle events like 'apply', 'cancel', and 'change' to update the filter state. ```svelte ``` -------------------------------- ### Generate Field Options Map with Lazy Evaluation in JavaScript Source: https://context7.com/svar-widgets/filter/llms.txt The getOptionsMap helper function generates a map of field options from a dataset, utilizing lazy evaluation for efficient memory usage. It processes an array of data and a list of field configurations to create an object where keys are field IDs and values are arrays of unique options. ```javascript import { getOptionsMap } from '@svar-ui/svelte-filter'; const data = [ { first_name: "Alex", age: 26, country: "USA" }, { first_name: "Jane", age: 44, country: "USA" }, { first_name: "John", age: 24, country: "Germany" } ]; const fields = [ { id: "first_name", type: "text" }, { id: "age", type: "number" }, { id: "country", type: "text" } ]; const optionsMap = getOptionsMap(data, fields); // Access options for each field (computed on demand) console.log(optionsMap.first_name); // ["Alex", "Jane", "John"] console.log(optionsMap.age); // [24, 26, 44] console.log(optionsMap.country); // ["Germany", "USA"] ``` -------------------------------- ### Create Array Filter Function with JavaScript Source: https://context7.com/svar-widgets/filter/llms.txt The createArrayFilter helper function converts filter configurations into a function that filters JavaScript arrays based on specified rules, supporting complex AND/OR logic. It takes a filter configuration object and returns a filter function. Input is an array of objects, and output is a filtered array. ```javascript import { createArrayFilter } from '@svar-ui/svelte-filter'; const data = [ { first_name: "Alex", age: 26, country: "USA" }, { first_name: "Jane", age: 44, country: "USA" }, { first_name: "John", age: 24, country: "Germany" }, { first_name: "Daisy", age: 33, country: "Germany" } ]; // Simple filter const filterConfig1 = { rules: [ { field: "country", filter: "equal", value: "USA" } ] }; const filter1 = createArrayFilter(filterConfig1); const result1 = filter1(data); // Result: [{ first_name: "Alex", age: 26, country: "USA" }, // { first_name: "Jane", age: 44, country: "USA" }] // Complex filter with AND/OR logic const filterConfig2 = { glue: "or", rules: [ { field: "first_name", filter: "equal", value: "Alex" }, { glue: "and", rules: [ { field: "age", filter: "greater", value: 40 }, { field: "country", filter: "equal", value: "USA" } ] } ] }; const filter2 = createArrayFilter(filterConfig2); const result2 = filter2(data); // Result: [{ first_name: "Alex", age: 26, country: "USA" }, // { first_name: "Jane", age: 44, country: "USA" }] ``` -------------------------------- ### Create Individual Object Filter Function in JavaScript Source: https://context7.com/svar-widgets/filter/llms.txt The createFilter helper function generates a filter function designed for testing individual objects against a set of rules, rather than filtering entire arrays. It accepts a filter configuration object and returns a function that returns a boolean. ```javascript import { createFilter } from '@svar-ui/svelte-filter'; const filterConfig = { glue: "and", rules: [ { field: "age", filter: "greaterOrEqual", value: 30 }, { field: "country", filter: "equal", value: "USA" } ] }; const filterFn = createFilter(filterConfig); const person1 = { first_name: "Alex", age: 26, country: "USA" }; const person2 = { first_name: "Jane", age: 44, country: "USA" }; console.log(filterFn(person1)); // false console.log(filterFn(person2)); // true ``` -------------------------------- ### Define Filter Value Structure Source: https://context7.com/svar-widgets/filter/llms.txt Illustrates various JSON structures for defining filter configurations. This includes simple single-rule filters, filters with OR logic across multiple rules, complex nested groups with mixed AND/OR logic, and filters using the 'includes' property for list-based matching. ```javascript // Simple single-rule filter const simpleFilter = { rules: [ { field: "age", filter: "greater", value: 30 } ] }; // Multiple rules with OR logic const orFilter = { glue: "or", rules: [ { field: "first_name", filter: "equal", value: "Alex" }, { field: "first_name", filter: "equal", value: "Jane" } ] }; // Nested groups with mixed AND/OR logic const complexFilter = { glue: "or", rules: [ { field: "first_name", filter: "equal", value: "Alex" }, { glue: "and", rules: [ { field: "age", filter: "greater", value: 40 }, { field: "age", filter: "less", value: 60 } ] }, { field: "start", filter: "between", type: "date", value: { start: new Date("2024-01-01"), end: new Date("2024-12-31") } } ] }; // Filter with includes (list of values) const includesFilter = { rules: [ { field: "country", includes: ["USA", "Canada", "Mexico"] } ] }; ``` -------------------------------- ### Implement FilterBar Component in Svelte Source: https://context7.com/svar-widgets/filter/llms.txt The FilterBar component provides a simplified horizontal filter bar with input fields and select controls for basic multi-field filtering. It utilizes Svelte for its declarative UI and reactivity. Dependencies include '@svar-ui/svelte-filter'. ```svelte applyFilter(value)} /> ``` -------------------------------- ### Control FilterBuilder API with Interceptors and Callbacks Source: https://context7.com/svar-widgets/filter/llms.txt Shows how to programmatically control the FilterBuilder component's behavior using its API. This includes intercepting events like 'add-rule' and 'add-group' to modify default actions and listening to the 'change' event to log filter value updates. ```svelte ``` -------------------------------- ### Extract Unique Field Options from Dataset in JavaScript Source: https://context7.com/svar-widgets/filter/llms.txt The getOptions helper function extracts unique values from a dataset for a specific field. It supports optional sorting and predicate transformations for data manipulation, such as extracting years from dates. Dependencies include '@svar-ui/svelte-filter'. ```javascript import { getOptions } from '@svar-ui/svelte-filter'; const data = [ { name: "Alex", age: 26, start: new Date(2024, 0, 15) }, { name: "Jane", age: 44, start: new Date(2024, 5, 20) }, { name: "John", age: 26, start: new Date(2025, 0, 10) }, { name: "Daisy", age: 33, start: new Date(2024, 0, 22) } ]; // Simple extraction const ages = getOptions(data, "age"); // Result: [26, 33, 44] // Extract with type configuration const agesWithConfig = getOptions(data, "age", { type: "number", sort: true }); // Result: [26, 33, 44] // Extract years from dates using predicate const years = getOptions(data, "start", { predicate: "year" }); // Result: [2024, 2025] // Extract months from dates const months = getOptions(data, "start", { predicate: "month" }); // Result: [0, 5] (January and June) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.